cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r823616 - in /websites/production/cxf/content: cache/docs.pageCache docs/jaxrs-testing.html
Date Thu, 28 Jun 2012 13:47:52 GMT
Author: buildbot
Date: Thu Jun 28 13:47:51 2012
New Revision: 823616

Log:
Production update by buildbot for cxf

Added:
    websites/production/cxf/content/docs/jaxrs-testing.html
Modified:
    websites/production/cxf/content/cache/docs.pageCache

Modified: websites/production/cxf/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.

Added: websites/production/cxf/content/docs/jaxrs-testing.html
==============================================================================
--- websites/production/cxf/content/docs/jaxrs-testing.html (added)
+++ websites/production/cxf/content/docs/jaxrs-testing.html Thu Jun 28 13:47:51 2012
@@ -0,0 +1,360 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+  <head>
+    <link type="text/css" rel="stylesheet" href="http://cxf.apache.org/resources/site.css">
+    <script src="http://cxf.apache.org/resources/space.js" type="text/javascript"></script>
+    
+<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture,
web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support,
integration standards, application integration, middleware, software, solutions, services,
CXF, open source">
+<meta name="description" content="Apache CXF, Services Framework - JAXRS Testing">
+    <title>
+Apache CXF -- JAXRS Testing
+    </title>
+  </head>
+<body onload="init()">
+
+
+<table width="100%" cellpadding="0" cellspacing="0">
+  <tr>
+    <td id="cell-0-0" colspan="2">&nbsp;</td>
+    <td id="cell-0-1">&nbsp;</td>
+    <td id="cell-0-2" colspan="2">&nbsp;</td>
+  </tr>
+  <tr>
+    <td id="cell-1-0">&nbsp;</td>
+    <td id="cell-1-1">&nbsp;</td>
+    <td id="cell-1-2">
+      <div style="padding: 5px;">
+        <div id="banner">
+          <!-- Banner -->
+<div id="banner-content">
+<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left"
colspan="1" nowrap>
+<a shape="rect" href="http://cxf.apache.org/" title="Apache CXF"><span style="font-weight:
bold; font-size: 170%; color: white">Apache CXF</span></a>
+</td><td align="right" colspan="1" nowrap>
+<a shape="rect" href="http://www.apache.org/" title="The Apache Sofware Foundation"><img
border="0" alt="ASF Logo" src="http://cxf.apache.org/images/asf-logo.png"></a>
+</td></tr></table>
+</div>
+          <!-- Banner -->
+        </div>
+      </div>
+      <div id="top-menu">
+        <table border="0" cellpadding="1" cellspacing="0" width="100%">
+          <tr>
+            <td>
+              <div align="left">
+                <!-- Breadcrumbs -->
+<a href="index.html">Index</a>&nbsp;&gt;&nbsp;<a href="restful-services.html">RESTful
Services</a>&nbsp;&gt;&nbsp;<a href="jax-rs.html">JAX-RS</a>&nbsp;&gt;&nbsp;<a
href="jaxrs-testing.html">JAXRS Testing</a>
+                <!-- Breadcrumbs -->
+              </div>
+            </td>
+            <td>
+              <div align="right">
+                <!-- Quicklinks -->
+<div id="quicklinks"><p><a shape="rect" href="http://cxf.apache.org/download.html">Download</a>
| <a shape="rect" href="http://cxf.apache.org/docs/index.html">Documentation</a></p></div>
+                <!-- Quicklinks -->
+              </div>
+            </td>
+          </tr>
+        </table>
+      </div>
+    </td>
+    <td id="cell-1-3">&nbsp;</td>
+    <td id="cell-1-4">&nbsp;</td>
+  </tr>
+  <tr>
+    <td id="cell-2-0" colspan="2">&nbsp;</td>
+    <td id="cell-2-1">
+      <table>
+        <tr valign="top">
+          <td height="100%">
+            <div id="wrapper-menu-page-right">
+              <div id="wrapper-menu-page-top">
+                <div id="wrapper-menu-page-bottom">
+                  <div id="menu-page">
+                    <!-- NavigationBar -->
+<div id="navigation"><ul class="alternate" type="square"><li><a shape="rect"
href="overview.html" title="Overview">Overview</a></li><li><a shape="rect"
href="how-tos.html" title="How-Tos">How-Tos</a></li><li><a shape="rect"
href="frontends.html" title="Frontends">Frontends</a></li><li><a shape="rect"
href="databindings.html" title="DataBindings">DataBindings</a></li><li><a
shape="rect" href="transports.html" title="Transports">Transports</a></li><li><a
shape="rect" href="configuration.html" title="Configuration">Configuration</a></li><li><a
shape="rect" href="debugging-and-logging.html" title="Debugging and Logging">Debugging
and Logging</a></li><li><a shape="rect" href="tools.html" title="Tools">Tools</a></li><li><a
shape="rect" href="restful-services.html" title="RESTful Services">RESTful Services</a></li><li><a
shape="rect" href="wsdl-bindings.html" title="WSDL Bindings">WSDL Bindings</a></li><li><a
shape="rect" href="service-routing.html" title="Service Routing">Service 
 Routing</a></li><li><a shape="rect" href="dynamic-languages.html" title="Dynamic
Languages">Dynamic Languages</a></li><li><a shape="rect" href="ws-support.html"
title="WS-* Support">WS-* Support</a></li><li><a shape="rect" href="advanced-integration.html"
title="Advanced Integration">Advanced Integration</a></li><li><a shape="rect"
href="deployment.html" title="Deployment">Deployment</a></li><li><a
shape="rect" href="schemas-and-namespaces.html" title="Schemas and Namespaces">Use of Schemas
and Namespaces</a></li></ul>
+
+
+<hr>
+<ul class="alternate" type="square"><li>Search
+
+<form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
+  <div>
+    <input type="hidden" name="cx" value="002890367768291051730:o99qiwa09y4">
+    <input type="hidden" name="ie" value="UTF-8">
+    <input type="text" name="q" size="21">
+    <input type="submit" name="sa" value="Search">
+  </div>
+</form>
+<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>
+</li></ul>
+
+
+<hr>
+<ul class="alternate" type="square"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API
(Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF
Website</a></li></ul>
+
+</div>
+                    <!-- NavigationBar -->
+                  </div>
+              </div>
+            </div>
+          </div>
+         </td>
+         <td height="100%">
+           <!-- Content -->
+           <div class="wiki-content">
+<div id="ConfluenceContent"><p><span style="font-size:2em;font-weight:bold">
JAX-RS Testing</span></p>
+
+
+<div>
+<ul><li><a shape="rect" href="#JAXRSTesting-EmbeddedJetty">Embedded Jetty</a></li><li><a
shape="rect" href="#JAXRSTesting-LocalTransport">Local Transport</a></li></ul></div>
+
+<p>JAX-RS endpoints can be easily tested using the embedded Jetty or CXF Local Transport.</p>
+
+<h1><a shape="rect" name="JAXRSTesting-EmbeddedJetty"></a>Embedded Jetty</h1>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+<span class="code-keyword">import</span> javax.ws.rs.core.Response;
+
+<span class="code-keyword">import</span> org.apache.cxf.endpoint.Server;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.client.WebClient;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+
+<span class="code-keyword">import</span> org.junit.Test;
+<span class="code-keyword">import</span> org.junit.Assert;
+<span class="code-keyword">import</span> org.junit.BeforeClass;
+<span class="code-keyword">import</span> org.junit.AfterClass;
+
+<span class="code-keyword">import</span> custom.MyJaxrsResource;
+<span class="code-keyword">import</span> custom.Book;
+
+<span class="code-keyword">public</span> class JAXRSTest <span class="code-keyword">extends</span>
Assert {
+
+<span class="code-keyword">private</span> <span class="code-keyword">final</span>
<span class="code-keyword">static</span> <span class="code-object">String</span>
ENDPOINT_ADDRESS = <span class="code-quote">"http:<span class="code-comment">//localhost:8080/<span
class="code-keyword">rest</span>"</span>;
+</span><span class="code-keyword">private</span> <span class="code-keyword">final</span>
<span class="code-keyword">static</span> <span class="code-object">String</span>
WADL_ADDRESS = ENDPOINT_ADDRESS + <span class="code-quote">"?_wadl"</span>;
+<span class="code-keyword">private</span> <span class="code-keyword">static</span>
Server server;
+
+@BeforeClass
+<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void initialize() <span class="code-keyword">throws</span> Exception {
+     startServer();
+     waitForWADL();
+}
+
+<span class="code-keyword">private</span> <span class="code-keyword">static</span>
void startServer() <span class="code-keyword">throws</span> Exception {
+     JAXRSServerFactoryBean sf = <span class="code-keyword">new</span> JAXRSServerFactoryBean();
+     sf.setResourceClasses(MyJaxrsResource.class);
+        
+     List&lt;<span class="code-object">Object</span>&gt; providers =
<span class="code-keyword">new</span> ArrayList&lt;<span class="code-object">Object</span>&gt;();
+     <span class="code-comment">// add custom providers <span class="code-keyword">if</span>
any
+</span>     sf.setProviders(providers);
+        
+     sf.setResourceProvider(MyJaxrsResource.class.class,
+                            <span class="code-keyword">new</span> SingletonResourceProvider(<span
class="code-keyword">new</span> MyJaxrsResource(), <span class="code-keyword">true</span>));
+     sf.setAddress(ENDPOINT_ADDRESS);
+
+     server = sf.create();
+}
+
+<span class="code-comment">// Optional step - may be needed to ensure that by the time
individual
+</span><span class="code-comment">// tests start running the endpoint has been
fully initialized
+</span><span class="code-keyword">private</span> <span class="code-keyword">static</span>
void waitForWADL() <span class="code-keyword">throws</span> Exception {
+    WebClient client = WebClient.create(WADL_ADDRESS);
+    <span class="code-comment">// wait <span class="code-keyword">for</span>
20 secs or so
+</span>    <span class="code-keyword">for</span> (<span class="code-object">int</span>
i = 0; i &lt; 20; i++) {
+        <span class="code-object">Thread</span>.currentThread().sleep(1000);
+        Response response = client.get();
+        <span class="code-keyword">if</span> (response.getStatus() == 200) {
+            <span class="code-keyword">break</span>;
+        }
+    }
+    <span class="code-comment">// no WADL is available yet - <span class="code-keyword">throw</span>
an exception or give tests a chance to run anyway
+</span>}
+
+
+@AfterClass
+<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void destroy() <span class="code-keyword">throws</span> Exception {
+   server.stop();
+   server.destroy();
+}
+
+@Test
+<span class="code-keyword">public</span> void testGetBookWithWebClient() {
+ WebClient client = WebClient.create(ENDPOINT_ADDRESS);
+ client.accept(<span class="code-quote">"text/xml"</span>);
+ client.path(<span class="code-quote">"somepath"</span>); 
+ Book book = client.get(Book.class);
+ assertEquals(123L, book.getId());
+}
+
+@Test
+<span class="code-keyword">public</span> void testGetBookWithProxy() {
+  MyJaxrsResource client = JAXRSClientFactory.create(ENDPOINT_ADDRESS, MyJaxrsResource.class);
+  Book book = client.getBook();
+  assertEquals(123L, book.getId());
+}
+}
+</pre>
+</div></div>
+
+<p>It is quite easy to setup a server and start testing it. The advantage of using
the embedded Jetty is that a complete end-to-end round-trip can be exercised, thus stressing
all the CXF runtime which comes at the cost of some added complexity to do with setting up
the server.</p>
+
+<h1><a shape="rect" name="JAXRSTesting-LocalTransport"></a>Local Transport</h1>
+
+<p>Starting from CXF 2.6.2 it is possible to use CXF Local Transport for testing the
JAX-RS endpoints and clients.<br clear="none">
+This avoids the need to start an embedded servlet container and the tests will run faster.</p>
+
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+
+<span class="code-keyword">import</span> org.apache.cxf.endpoint.Server;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.client.WebClient;
+<span class="code-keyword">import</span> org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+
+<span class="code-keyword">import</span> org.apache.cxf.transport.local.LocalConduit;
+<span class="code-keyword">import</span> org.apache.cxf.transport.local.LocalTransportFactory;
+
+<span class="code-keyword">import</span> org.junit.Test;
+<span class="code-keyword">import</span> org.junit.Assert;
+<span class="code-keyword">import</span> org.junit.BeforeClass;
+<span class="code-keyword">import</span> org.junit.AfterClass;
+
+<span class="code-keyword">import</span> custom.MyJaxrsResource;
+<span class="code-keyword">import</span> custom.Book;
+
+<span class="code-keyword">public</span> class JAXRSTest <span class="code-keyword">extends</span>
Assert {
+
+<span class="code-keyword">private</span> <span class="code-keyword">final</span>
<span class="code-keyword">static</span> <span class="code-object">String</span>
ENDPOINT_ADDRESS = <span class="code-quote">"local:<span class="code-comment">//books"</span>;
+</span><span class="code-keyword">private</span> <span class="code-keyword">static</span>
Server server;
+
+@BeforeClass
+<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void initialize() <span class="code-keyword">throws</span> Exception {
+     startServer();
+}
+
+<span class="code-keyword">private</span> <span class="code-keyword">static</span>
void startServer() <span class="code-keyword">throws</span> Exception {
+     JAXRSServerFactoryBean sf = <span class="code-keyword">new</span> JAXRSServerFactoryBean();
+     sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
+     sf.setResourceClasses(MyJaxrsResource.class);
+        
+     List&lt;<span class="code-object">Object</span>&gt; providers =
<span class="code-keyword">new</span> ArrayList&lt;<span class="code-object">Object</span>&gt;();
+     <span class="code-comment">// add custom providers <span class="code-keyword">if</span>
any
+</span>     sf.setProviders(providers);
+        
+     sf.setResourceProvider(MyJaxrsResource.class.class,
+                            <span class="code-keyword">new</span> SingletonResourceProvider(<span
class="code-keyword">new</span> MyJaxrsResource(), <span class="code-keyword">true</span>));
+     sf.setAddress(ENDPOINT_ADDRESS);
+
+     server = sf.create();
+}
+
+@AfterClass
+<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void destroy() <span class="code-keyword">throws</span> Exception {
+   server.stop();
+   server.destroy();
+}
+
+@Test
+<span class="code-keyword">public</span> void testGetBookWithWebClientDirectDispatch()
{
+ WebClient client = WebClient.create(ENDPOINT_ADDRESS);
+ WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, <span
class="code-object">Boolean</span>.TRUE);
+ 
+ client.accept(<span class="code-quote">"text/xml"</span>);
+ client.path(<span class="code-quote">"somepath"</span>); 
+ Book book = client.get(Book.class);
+ assertEquals(123L, book.getId());
+}
+
+@Test
+<span class="code-keyword">public</span> void testGetBookViaPipe() {
+ WebClient client = WebClient.create(ENDPOINT_ADDRESS);
+ client.accept(<span class="code-quote">"text/xml"</span>);
+ client.path(<span class="code-quote">"somepath"</span>); 
+ Book book = client.get(Book.class);
+ assertEquals(123L, book.getId());
+}
+
+
+
+@Test
+<span class="code-keyword">public</span> void testAddBookWithProxyDirectDispatch()
{
+  MyJaxrsResource client = JAXRSClientFactory.create(ENDPOINT_ADDRESS, MyJaxrsResource.class);
+  WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, <span
class="code-object">Boolean</span>.TRUE);
+  Book book = client.echoBook(<span class="code-keyword">new</span> Book(123));
+  assertEquals(123L, book.getId());
+}
+}
+</pre>
+</div></div>
+
+<p>Note that setting a LocalConduit.DIRECT_DISPATCH property to 'true' ensures that
the invocation goes immediately into the service chain after the client out chain has completed.
This works well for all HTTP verbs including GET, POST, etc.</p>
+
+<p>If this property is not set then CXF LocalConduit sets up a pipe which is initiated
via an initial write on the client side. Thus this option is only useful for testing POST
or PUT invocations</p></div>
+           </div>
+           <!-- Content -->
+         </td>
+        </tr>
+      </table>
+   </td>
+   <td id="cell-2-2" colspan="2">&nbsp;</td>
+  </tr>
+  <tr>
+   <td id="cell-3-0">&nbsp;</td>
+   <td id="cell-3-1">&nbsp;</td>
+   <td id="cell-3-2">
+     <div id="footer">
+       <!-- Footer -->
+       <div id="site-footer">
+         <a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a>
- 
+         (<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=27850867">edit
page</a>) 
+	 (<a href="https://cwiki.apache.org/confluence/display/CXF20DOC/JAXRS+Testing?showComments=true&amp;showCommentArea=true#addcomment">add
comment</a>)<br>
+	Apache CXF, CXF, Apache, the Apache feather logo are trademarks of The Apache Software Foundation.<br>
+        All other marks mentioned may be trademarks or registered trademarks of their respective
owners.
+       </div>
+       <!-- Footer -->
+     </div>
+   </td>
+   <td id="cell-3-3">&nbsp;</td>
+   <td id="cell-3-4">&nbsp;</td>
+  </tr>
+  <tr>
+    <td id="cell-4-0" colspan="2">&nbsp;</td>
+    <td id="cell-4-1">&nbsp;</td>
+    <td id="cell-4-2" colspan="2">&nbsp;</td>
+  </tr>
+</table>
+
+<script type="text/javascript">
+var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+</script>
+<script type="text/javascript">
+try {
+var pageTracker = _gat._getTracker("UA-4458903-1");
+pageTracker._trackPageview();
+} catch(err) {}</script>
+
+</body>
+</html>
+



Mime
View raw message