CXF
From Resin 3.0
(Difference between revisions)
(First few steps - checkpoint) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Cleanup}} | ||
== CXF and Resin == | == CXF and Resin == | ||
Line 6: | Line 7: | ||
<ol> | <ol> | ||
− | <li> Download Resin from | + | <li> Download Resin from http://www.caucho.com/download</li> |
<li>Unzip Resin into <code>/usr/local/share/resin</code></li> | <li>Unzip Resin into <code>/usr/local/share/resin</code></li> | ||
<li>Create the CXF webapp directory structure: | <li>Create the CXF webapp directory structure: | ||
− | <br/><code>/usr/local/share/resin/webapps/cxf/WEB-INF/lib/</code> | + | <br/><code>mkdir -p /usr/local/share/resin/webapps/cxf/WEB-INF/lib/</code> |
− | <br/><code>/usr/local/share/resin/webapps/cxf/WEB-INF/classes/ | + | <br/><code>mkdir -p /usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/</code> |
</li> | </li> | ||
− | <li>Download CXF from | + | <li>Download CXF from http://incubator.apache.org/cxf/</li> |
<li>Unzip CXF</li> | <li>Unzip CXF</li> | ||
<li>Copy all the jars included the CXF lib/ directory to | <li>Copy all the jars included the CXF lib/ directory to | ||
<br/><code>/usr/local/share/resin/webapps/cxf/WEB-INF/lib/</code> | <br/><code>/usr/local/share/resin/webapps/cxf/WEB-INF/lib/</code> | ||
</li> | </li> | ||
− | <li>Create the file <code>/usr/local/share/resin/webapps/cxf/WEB-INF/resin-web.xml</code> | + | <li>Create the configuration file <code>/usr/local/share/resin/webapps/cxf/WEB-INF/resin-web.xml</code> |
<pre><web-app xmlns="http://caucho.com/ns/resin"> | <pre><web-app xmlns="http://caucho.com/ns/resin"> | ||
− | + | <servlet-mapping url-pattern='/StrLenDemo/*' servlet-class='demo.StrLenDemo'/> | |
− | + | <servlet-mapping url-pattern='/StrLen/*' servlet-class='demo.StrLenImpl'> | |
− | <protocol | + | <protocol uri="cxf:"/> |
</servlet-mapping> | </servlet-mapping> | ||
− | <remote-client | + | <remote-client interface="demo.StrLen" name="StrLenClient"> |
− | < | + | <uri>cxf:url=http://localhost:8080/cxf/StrLen/StrLenImpl</uri> |
</remote-client> | </remote-client> | ||
</web-app> | </web-app> | ||
+ | </pre> | ||
+ | </li> | ||
+ | <li>Create the interface file <code>/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLen.java</code> | ||
+ | <pre> | ||
+ | package demo; | ||
+ | |||
+ | import javax.jws.WebMethod; | ||
+ | import javax.jws.WebService; | ||
+ | |||
+ | @WebService | ||
+ | public interface StrLen { | ||
+ | @WebMethod | ||
+ | public int strlen(String x); | ||
+ | } | ||
+ | </pre> | ||
+ | </li> | ||
+ | <li>Create the implementation file | ||
+ | <code>/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLenImpl.java</code> | ||
+ | <pre> | ||
+ | package demo; | ||
+ | |||
+ | import javax.jws.WebService; | ||
+ | |||
+ | @WebService(endpointInterface="demo.StrLen") | ||
+ | public class StrLenImpl | ||
+ | { | ||
+ | public int strlen(String x) | ||
+ | { | ||
+ | return x.length(); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | </li> | ||
+ | <li>Create a Servlet to access the service | ||
+ | <code>/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLenDemo.java</code> | ||
+ | <pre> | ||
+ | package demo; | ||
+ | |||
+ | import java.io.IOException; | ||
+ | import java.io.Writer; | ||
+ | |||
+ | import javax.servlet.http.HttpServlet; | ||
+ | import javax.servlet.http.HttpServletRequest; | ||
+ | import javax.servlet.http.HttpServletResponse; | ||
+ | import javax.webbeans.In; | ||
+ | |||
+ | public class StrLenDemo extends HttpServlet | ||
+ | { | ||
+ | @In StrLen strlenClient; | ||
+ | |||
+ | public void doGet(HttpServletRequest req, HttpServletResponse resp) | ||
+ | throws IOException | ||
+ | { | ||
+ | Writer out = resp.getWriter(); | ||
+ | out.write("strlen(\"hello, world\") = " + | ||
+ | strlenClient.strlen("hello, world")); | ||
+ | } | ||
+ | } | ||
</pre> | </pre> | ||
</li> | </li> | ||
<li>Start Resin with <code>java -jar /usr/local/share/resin/lib/resin.jar</code></li> | <li>Start Resin with <code>java -jar /usr/local/share/resin/lib/resin.jar</code></li> | ||
+ | <li>Look at http://localhost:8080/cxf/StrLenDemo | ||
+ | <br/>It should show | ||
+ | <pre> | ||
+ | strlen("hello, world") = 12 | ||
+ | </pre> | ||
</ol> | </ol> |
Latest revision as of 15:47, 2 December 2011
![]() |
This article requires cleanup and may refer to a legacy version of Resin.
Please visit http://www.caucho.com/documentation/ for the most up-to-date documentation. |
CXF and Resin
Resin features easy creation and deployment of CXF web services and clients, avoiding the need for complicated configuration.
(The following has been tested with Resin 3.1.5 and CXF 2.0.3)
- Download Resin from http://www.caucho.com/download
- Unzip Resin into
/usr/local/share/resin
- Create the CXF webapp directory structure:
mkdir -p /usr/local/share/resin/webapps/cxf/WEB-INF/lib/
mkdir -p /usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/
- Download CXF from http://incubator.apache.org/cxf/
- Unzip CXF
- Copy all the jars included the CXF lib/ directory to
/usr/local/share/resin/webapps/cxf/WEB-INF/lib/
- Create the configuration file
/usr/local/share/resin/webapps/cxf/WEB-INF/resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin"> <servlet-mapping url-pattern='/StrLenDemo/*' servlet-class='demo.StrLenDemo'/> <servlet-mapping url-pattern='/StrLen/*' servlet-class='demo.StrLenImpl'> <protocol uri="cxf:"/> </servlet-mapping> <remote-client interface="demo.StrLen" name="StrLenClient"> <uri>cxf:url=http://localhost:8080/cxf/StrLen/StrLenImpl</uri> </remote-client> </web-app>
- Create the interface file
/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLen.java
package demo; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface StrLen { @WebMethod public int strlen(String x); }
- Create the implementation file
/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLenImpl.java
package demo; import javax.jws.WebService; @WebService(endpointInterface="demo.StrLen") public class StrLenImpl { public int strlen(String x) { return x.length(); } }
- Create a Servlet to access the service
/usr/local/share/resin/webapps/cxf/WEB-INF/classes/demo/StrLenDemo.java
package demo; import java.io.IOException; import java.io.Writer; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.webbeans.In; public class StrLenDemo extends HttpServlet { @In StrLen strlenClient; public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { Writer out = resp.getWriter(); out.write("strlen(\"hello, world\") = " + strlenClient.strlen("hello, world")); } }
- Start Resin with
java -jar /usr/local/share/resin/lib/resin.jar
- Look at http://localhost:8080/cxf/StrLenDemo
It should showstrlen("hello, world") = 12