You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/03/20 11:46:39 UTC
svn commit: r756410 [2/2] - in /cxf/branches/2.1.x-fixes: ./
common/common/src/main/java/org/apache/cxf/common/util/
rt/core/src/main/java/org/apache/cxf/bus/spring/
rt/core/src/main/java/org/apache/cxf/interceptor/
rt/databinding/jaxb/src/main/java/or...
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java Fri Mar 20 10:46:33 2009
@@ -29,13 +29,13 @@
@Test
public void testBaseCurrentPath() {
- assertEquals(URI.create("http://foo"), new WebClient("http://foo").getBaseURI());
- assertEquals(URI.create("http://foo"), new WebClient("http://foo").getCurrentURI());
+ assertEquals(URI.create("http://foo"), WebClient.create("http://foo").getBaseURI());
+ assertEquals(URI.create("http://foo"), WebClient.create("http://foo").getCurrentURI());
}
@Test
public void testNewBaseCurrentPath() {
- WebClient wc = new WebClient("http://foo");
+ WebClient wc = WebClient.create("http://foo");
assertEquals(URI.create("http://foo"), wc.getBaseURI());
assertEquals(URI.create("http://foo"), wc.getCurrentURI());
wc.to("http://bar", false);
@@ -45,7 +45,7 @@
@Test
public void testForward() {
- WebClient wc = new WebClient("http://foo");
+ WebClient wc = WebClient.create("http://foo");
wc.to("http://foo/bar", true);
assertEquals(URI.create("http://foo"), wc.getBaseURI());
assertEquals(URI.create("http://foo/bar"), wc.getCurrentURI());
@@ -53,13 +53,13 @@
@Test(expected = IllegalArgumentException.class)
public void testWrongForward() {
- WebClient wc = new WebClient("http://foo");
+ WebClient wc = WebClient.create("http://foo");
wc.to("http://bar", true);
}
@Test
public void testBaseCurrentPathAfterChange() {
- WebClient wc = new WebClient(URI.create("http://foo"));
+ WebClient wc = WebClient.create(URI.create("http://foo"));
wc.path("bar").path("baz").matrix("m1", "m1value").query("q1", "q1value");
assertEquals(URI.create("http://foo"), wc.getBaseURI());
assertEquals(URI.create("http://foo/bar/baz;m1=m1value?q1=q1value"), wc.getCurrentURI());
@@ -68,16 +68,16 @@
@Test
public void testBaseCurrentPathAfterCopy() {
- WebClient wc = new WebClient(URI.create("http://foo"));
+ WebClient wc = WebClient.create(URI.create("http://foo"));
wc.path("bar").path("baz").matrix("m1", "m1value").query("q1", "q1value");
- WebClient wc1 = new WebClient(wc);
+ WebClient wc1 = WebClient.fromClient(wc);
assertEquals(URI.create("http://foo/bar/baz;m1=m1value?q1=q1value"), wc1.getBaseURI());
assertEquals(URI.create("http://foo/bar/baz;m1=m1value?q1=q1value"), wc1.getCurrentURI());
}
@Test
public void testHeaders() {
- WebClient wc = new WebClient(URI.create("http://foo"));
+ WebClient wc = WebClient.create(URI.create("http://foo"));
wc.header("h1", "h1value").header("h2", "h2value");
assertEquals(1, wc.getHeaders().get("h1").size());
assertEquals("h1value", wc.getHeaders().getFirst("h1"));
@@ -94,7 +94,7 @@
@Test
public void testBackFast() {
- WebClient wc = new WebClient(URI.create("http://foo"));
+ WebClient wc = WebClient.create(URI.create("http://foo"));
wc.path("bar").path("baz").matrix("m1", "m1value");
assertEquals(URI.create("http://foo"), wc.getBaseURI());
assertEquals(URI.create("http://foo/bar/baz;m1=m1value"), wc.getCurrentURI());
@@ -104,7 +104,7 @@
@Test
public void testBack() {
- WebClient wc = new WebClient(URI.create("http://foo"));
+ WebClient wc = WebClient.create(URI.create("http://foo"));
wc.path("bar").path("baz");
assertEquals(URI.create("http://foo"), wc.getBaseURI());
assertEquals(URI.create("http://foo/bar/baz"), wc.getCurrentURI());
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java Fri Mar 20 10:46:33 2009
@@ -182,7 +182,7 @@
verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
MessageBodyWriter writer = ProviderFactory.getInstance()
- .createMessageBodyWriter(File.class, null, null, JAXRSUtils.ALL_TYPES, null);
+ .createMessageBodyWriter(File.class, null, null, JAXRSUtils.ALL_TYPES, new MessageImpl());
assertTrue(BinaryDataProvider.class == writer.getClass());
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Fri Mar 20 10:46:33 2009
@@ -19,8 +19,14 @@
package org.apache.cxf.systest.jaxrs;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.provider.BinaryDataProvider;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
public class BookServer extends AbstractBusTestServerBase {
@@ -29,6 +35,13 @@
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BookStore.class);
//default lifecycle is per-request, change it to singleton
+ BinaryDataProvider p = new BinaryDataProvider();
+ p.setProduceMediaTypes(Collections.singletonList("application/bar"));
+ p.setEnableBuffering(true);
+ sf.setProvider(p);
+ List<Interceptor> ints = new ArrayList<Interceptor>();
+ ints.add(new CustomOutInterceptor());
+ sf.setOutInterceptors(ints);
sf.setResourceProvider(BookStore.class,
new SingletonResourceProvider(new BookStore()));
sf.setAddress("http://localhost:9080/");
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Fri Mar 20 10:46:33 2009
@@ -21,6 +21,7 @@
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Calendar;
@@ -264,11 +265,26 @@
return doGetBook(currentBookId);
}
+
@GET
- @Path("/books/stream")
- @ProduceMime("application/xml")
+ @Path("/books/buffer")
+ @ProduceMime("application/bar")
+ public InputStream getBufferedBook() {
+ return getClass().getResourceAsStream("resources/expected_get_book123.txt");
+ }
+
+ @GET
+ @Path("/books/fail-early")
+ @ProduceMime("application/bar")
+ public StreamingOutput failEarlyInWrite() {
+ return new StreamingOutputImpl(true);
+ }
+
+ @GET
+ @Path("/books/fail-late")
+ @ProduceMime("application/bar")
public StreamingOutput writeToStreamAndFail() {
- return new StreamingOutputImpl();
+ return new StreamingOutputImpl(false);
}
private Book doGetBook(String id) throws BookNotFoundFault {
@@ -522,11 +538,21 @@
private static class StreamingOutputImpl implements StreamingOutput {
+ private boolean failEarly;
+
+ public StreamingOutputImpl(boolean failEarly) {
+ this.failEarly = failEarly;
+ }
+
public void write(OutputStream output) throws IOException, WebApplicationException {
- //output.write("This is not supposed to go on the wire".getBytes());
- throw new WebApplicationException(
- Response.status(410).type("text/plain")
- .entity("This is supposed to go on the wire").build());
+ if (failEarly) {
+ throw new WebApplicationException(
+ Response.status(410).type("text/plain")
+ .entity("This is supposed to go on the wire").build());
+ } else {
+ output.write("This is not supposed to go on the wire".getBytes());
+ throw new WebApplicationException(410);
+ }
}
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java Fri Mar 20 10:46:33 2009
@@ -49,4 +49,8 @@
@Path("/books/{id}")
@WebMethod(exclude = true)
BookSubresource getBookSubresource(@PathParam("id") String id);
+
+ @Path("/thestore/{id}")
+ @WebMethod(exclude = true)
+ BookStoreJaxrsJaxws getBookStore(@PathParam("id") String id);
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java Fri Mar 20 10:46:33 2009
@@ -104,5 +104,13 @@
public BookSubresource getBookSubresource(String id) {
return new BookSubresourceImpl(Long.valueOf(id));
}
+
+ @WebMethod(exclude = true)
+ public BookStoreJaxrsJaxws getBookStore(String id) {
+ if (!"number1".equals(id)) {
+ throw new WebApplicationException(404);
+ }
+ return this;
+ }
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java Fri Mar 20 10:46:33 2009
@@ -40,7 +40,7 @@
Book getTheBook() throws BookNotFoundFault;
@POST
- @Path("/subresource2/{n1}")
+ @Path("/subresource2/{n1:.*}")
@ConsumeMime("text/plain")
@ProduceMime("application/xml")
Book getTheBook2(@PathParam("n1") String name1,
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Fri Mar 20 10:46:33 2009
@@ -87,9 +87,15 @@
@Test
public void testWriteAndFailEarly() throws Exception {
- getAndCompare("http://localhost:9080/bookstore/books/stream",
+ getAndCompare("http://localhost:9080/bookstore/books/fail-early",
"This is supposed to go on the wire",
- "application/xml, text/plain", 410);
+ "application/bar, text/plain", 410);
+ }
+
+ @Test
+ public void testWriteAndFailLate() throws Exception {
+ getAndCompare("http://localhost:9080/bookstore/books/fail-late",
+ "", "application/bar", 410);
}
@@ -258,6 +264,13 @@
}
@Test
+ public void testGetBookBuffer() throws Exception {
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/buffer",
+ "resources/expected_get_book123.txt",
+ "application/bar", 200);
+ }
+
+ @Test
public void testGetBookBySegment() throws Exception {
getAndCompareAsStrings("http://localhost:9080/bookstore/segment/matrix2;first=12;second=3",
"resources/expected_get_book123.txt",
@@ -729,6 +742,9 @@
String content = getStringFromInputStream(get.getResponseBodyAsStream());
assertEquals("Expected value is wrong",
expectedValue, content);
+ if (expectedStatus == 200) {
+ assertEquals("123", get.getResponseHeader("BookId").getValue());
+ }
} finally {
get.releaseConnection();
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java Fri Mar 20 10:46:33 2009
@@ -37,7 +37,7 @@
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServerResourceCreatedSpringProviders.class));
+ launchServer(BookServerResourceCreatedSpringProviders.class, true));
}
@Test
Copied: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java (from r750522, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java)
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java?p2=cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java&p1=cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java&r1=750522&r2=756410&rev=756410&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java Fri Mar 20 10:46:33 2009
@@ -20,6 +20,8 @@
package org.apache.cxf.systest.jaxrs;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -51,7 +53,9 @@
p.setEnableStreaming(true);
sf.setProvider(p);
sf.setAddress("http://localhost:9080/");
-
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("org.apache.cxf.serviceloader-context", "true");
+ sf.setProperties(properties);
sf.create();
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Fri Mar 20 10:46:33 2009
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -45,7 +46,6 @@
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.ext.form.Form;
import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
@@ -92,7 +92,7 @@
@Test
public void testGetBook123WebClient() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest";
- WebClient client = new WebClient(baseAddress);
+ WebClient client = WebClient.create(baseAddress);
client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
Book b = client.get(Book.class);
assertEquals(123L, b.getId());
@@ -102,7 +102,7 @@
@Test
public void testGetBook123WebClientBean() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest";
- WebClient client = WebClient.createClient(baseAddress);
+ WebClient client = WebClient.create(baseAddress);
client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
Book b = client.get(Book.class);
assertEquals(123, b.getId());
@@ -112,7 +112,7 @@
@Test
public void testNoBookWebClient() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest";
- WebClient client = new WebClient(baseAddress);
+ WebClient client = WebClient.create(baseAddress);
client.path("/bookstore/books/0/subresource").accept(MediaType.APPLICATION_XML_TYPE);
Book b = client.get(Book.class);
assertNull(b);
@@ -122,7 +122,7 @@
@Test
public void testGetBook123WebClientResponse() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest";
- WebClient client = new WebClient(baseAddress);
+ WebClient client = WebClient.create(baseAddress);
client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
Book b = readBook((InputStream)client.get().getEntity());
assertEquals(123L, b.getId());
@@ -134,9 +134,9 @@
String baseAddress = "http://localhost:9092/test/services/rest";
BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
- BookStoreJaxrsJaxws.class);
+ BookStoreJaxrsJaxws.class,
+ Collections.singletonList(new TestResponseExceptionMapper()));
- ProviderFactory.getInstance().registerUserProvider(new TestResponseExceptionMapper());
try {
proxy.getBook(356L);
fail();
@@ -165,29 +165,16 @@
BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
BookStoreJaxrsJaxws.class);
doTestSubresource(proxy);
- }
-
- @Test
- public void testGetBookSubresourceWebClientProxyDirect() throws Exception {
-
- WebClient client = new WebClient("http://localhost:9092/test/services/rest");
- client.type(MediaType.TEXT_PLAIN_TYPE)
- .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE);
- BookStoreJaxrsJaxws proxy =
- JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true, true);
-
- doTestSubresource(proxy);
-
- BookStoreJaxrsJaxws proxy2 = JAXRSClientFactory.fromClient(
- WebClient.client(proxy), BookStoreJaxrsJaxws.class);
+ BookStoreJaxrsJaxws proxy2 = proxy.getBookStore("number1");
doTestSubresource(proxy2);
-
+ BookStoreJaxrsJaxws proxy3 = proxy2.getBookStore("number1");
+ doTestSubresource(proxy3);
}
@Test
public void testGetBookSubresourceWebClientProxyBean() throws Exception {
- WebClient client = new WebClient("http://localhost:9092/test/services/rest");
+ WebClient client = WebClient.create("http://localhost:9092/test/services/rest");
client.type(MediaType.TEXT_PLAIN_TYPE)
.accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE);
BookStoreJaxrsJaxws proxy =
@@ -205,7 +192,7 @@
@Test
public void testGetBookSubresourceWebClientProxy2() throws Exception {
- WebClient client = new WebClient("http://localhost:9092/test/services/rest/bookstore")
+ WebClient client = WebClient.create("http://localhost:9092/test/services/rest/bookstore")
.path("/books/378");
client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE);
BookSubresource proxy = JAXRSClientFactory.fromClient(client, BookSubresource.class);
@@ -227,13 +214,16 @@
b = bs.getTheBook2("CXF ", "in ", "Action ", null, "7", "8");
assertEquals(378L, b.getId());
assertEquals("CXF in Action - 478", b.getName());
+
+
+
}
@Test
public void testGetBookWebClientForm() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest/bookstore/books/679/subresource3";
- WebClient wc = new WebClient(baseAddress);
+ WebClient wc = WebClient.create(baseAddress);
MultivaluedMap<String, Object> map = new MetadataMap<String, Object>();
map.putSingle("id", "679");
map.putSingle("name", "CXF in Action - 679");
@@ -247,7 +237,7 @@
public void testGetBookWebClientForm2() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest/bookstore/books/679/subresource3";
- WebClient wc = new WebClient(baseAddress);
+ WebClient wc = WebClient.create(baseAddress);
Form f = new Form();
f.set("id", "679").set("name", "CXF in Action - 679");
Book b = readBook((InputStream)wc.accept("application/xml")
@@ -274,7 +264,7 @@
@Test
public void testAddGetBook123WebClient() throws Exception {
String baseAddress = "http://localhost:9092/test/services/rest";
- WebClient client = new WebClient(baseAddress);
+ WebClient client = WebClient.create(baseAddress);
client.path("/bookstore/books").accept(MediaType.APPLICATION_XML_TYPE)
.type(MediaType.APPLICATION_XML_TYPE);
Book b = new Book();
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java Fri Mar 20 10:46:33 2009
@@ -21,11 +21,7 @@
import javax.ws.rs.core.MediaType;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
-import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.systest.jaxrs.Book;
import org.apache.cxf.systest.jaxrs.BookStore;
@@ -46,34 +42,59 @@
}
@Test
- public void testGetBook123Client() throws Exception {
+ public void testGetBook123Proxy() throws Exception {
- SpringBusFactory bf = new SpringBusFactory();
- Bus bus = bf.createBus(CLIENT_CONFIG_FILE);
- BusFactory.setDefaultBus(bus);
-
- BookStore bs = JAXRSClientFactory.create("https://localhost:9095", BookStore.class);
+ BookStore bs = JAXRSClientFactory.create("https://localhost:9095", BookStore.class,
+ CLIENT_CONFIG_FILE);
// just to verify the interface call goes through CGLIB proxy too
assertEquals("https://localhost:9095", WebClient.client(bs).getBaseURI().toString());
Book b = bs.getSecureBook("123");
assertEquals(b.getId(), 123);
+ b = bs.getSecureBook("123");
+ assertEquals(b.getId(), 123);
+ }
+
+ @Test
+ public void testGetBook123ProxyToWebClient() throws Exception {
+
+ BookStore bs = JAXRSClientFactory.create("https://localhost:9095", BookStore.class,
+ CLIENT_CONFIG_FILE);
+ Book b = bs.getSecureBook("123");
+ assertEquals(b.getId(), 123);
+ WebClient wc = WebClient.fromClient(WebClient.client(bs));
+ wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
+ Book b2 = wc.get(Book.class);
+ assertEquals(123, b2.getId());
}
+
+ @Test
+ public void testGetBook123WebClientToProxy() throws Exception {
+
+ WebClient wc = WebClient.create("https://localhost:9095", CLIENT_CONFIG_FILE);
+ wc.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
+ Book b = wc.get(Book.class);
+ assertEquals(123, b.getId());
+
+ wc.back(true);
+
+ BookStore bs = JAXRSClientFactory.fromClient(wc, BookStore.class);
+ Book b2 = bs.getSecureBook("123");
+ assertEquals(b2.getId(), 123);
+
+ }
+
+
@Test
public void testGetBook123WebClient() throws Exception {
- SpringBusFactory bf = new SpringBusFactory();
- Bus bus = bf.createBus(CLIENT_CONFIG_FILE);
- BusFactory.setDefaultBus(bus);
-
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
- bean.setAddress("https://localhost:9095");
- WebClient client = bean.createWebClient();
+ WebClient client = WebClient.create("https://localhost:9095", CLIENT_CONFIG_FILE);
assertEquals("https://localhost:9095", client.getBaseURI().toString());
client.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
Book b = client.get(Book.class);
assertEquals(123, b.getId());
+
}
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java Fri Mar 20 10:46:33 2009
@@ -19,6 +19,13 @@
package org.apache.cxf.systest.jaxrs.security;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.systest.jaxrs.Book;
+import org.apache.cxf.systest.jaxrs.BookNotFoundFault;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -68,4 +75,48 @@
getBook(endpointAddress, "foo", "bar", 200);
getBook(endpointAddress, "bob", "bobspassword", 403);
}
+
+ @Test
+ public void testWebClientAdmin() throws Exception {
+ String address = "http://localhost:9080/bookstorestorage/thosebooks";
+ doGetBookWebClient(address, "foo", "bar", 200);
+ }
+
+ @Test
+ public void testProxyClientAdmin() throws Exception {
+ String address = "http://localhost:9080/bookstorestorage";
+ doGetBookProxyClient(address, "foo", "bar", 200);
+ }
+
+ @Test
+ public void testWebClientUserUnauthorized() throws Exception {
+ String address = "http://localhost:9080/bookstorestorage/thosebooks";
+ doGetBookWebClient(address, "bob", "bobspassword", 403);
+ }
+
+ @Test
+ public void testWebClientUserAuthorized() throws Exception {
+ String address = "http://localhost:9080/bookstorestorage/thosebooks/123/123";
+ doGetBookWebClient(address, "bob", "bobspassword", 200);
+ }
+
+ private void doGetBookWebClient(String address, String username, String password, int expectedStatus) {
+ WebClient wc = WebClient.create(address, username, password, null);
+ Response r = wc.get();
+ assertEquals(expectedStatus, r.getStatus());
+ WebClient wc2 = WebClient.fromClient(wc);
+ r = wc2.get();
+ assertEquals(expectedStatus, r.getStatus());
+ }
+
+ private void doGetBookProxyClient(String address, String username, String password, int expectedStatus)
+ throws BookNotFoundFault {
+ SecureBookInterface books = JAXRSClientFactory.create(address, SecureBookInterface.class,
+ username, password, null);
+ Book b = books.getThatBook();
+ assertEquals(123, b.getId());
+ Response r = WebClient.client(books).getResponse();
+ assertEquals(expectedStatus, r.getStatus());
+
+ }
}
Modified: cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml?rev=756410&r1=756409&r2=756410&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml Fri Mar 20 10:46:33 2009
@@ -80,6 +80,9 @@
<jaxrs:extensionMappings>
<entry key="json" value="application/json"/>
</jaxrs:extensionMappings>
+ <jaxrs:properties>
+ <entry key="org.apache.cxf.output.buffering" value="true"/>
+ </jaxrs:properties>
</jaxrs:server>
<bean id="atomstore" class="org.apache.cxf.systest.jaxrs.AtomBookStore"/>