Author: sergeyb
Date: Fri Nov 8 12:56:50 2013
New Revision: 1540006
URL: http://svn.apache.org/r1540006
Log:
[CXF-5380] Better support for xsi:type
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
(with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring2.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Fri Nov 8 12:56:50 2013
@@ -241,10 +241,11 @@ public class JAXRSOutInterceptor extends
MediaType responseMediaType =
getResponseMediaType(responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE));
- Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
Class<?> serviceCls = invoked != null ?
ori.getClassResourceInfo().getServiceClass() : null;
+ Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
Type genericType = InjectionUtils.getGenericResponseType(invoked,
serviceCls,
response.getActualEntity(), targetType, exchange);
+ targetType = InjectionUtils.updateParamClassToTypeIfNeeded(targetType,
genericType);
annotations = response.getEntityAnnotations();
List<WriterInterceptor> writers = providerFactory
@@ -253,9 +254,7 @@ public class JAXRSOutInterceptor extends
OutputStream outOriginal = message.getContent(OutputStream.class);
if (writers == null || writers.isEmpty()) {
- message.put(Message.CONTENT_TYPE, "text/plain");
- message.put(Message.RESPONSE_CODE, 500);
- writeResponseErrorMessage(outOriginal, "NO_MSG_WRITER",
targetType, responseMediaType);
+ writeResponseErrorMessage(message, outOriginal, "NO_MSG_WRITER",
targetType, responseMediaType);
return;
}
responseMediaType = checkFinalContentType(responseMediaType, writers);
@@ -400,7 +399,10 @@ public class JAXRSOutInterceptor extends
}
- private void writeResponseErrorMessage(OutputStream out, String name,
Class<?> cls, MediaType ct) {
+ private void writeResponseErrorMessage(Message message, OutputStream out,
+ String name, Class<?> cls,
MediaType ct) {
+ message.put(Message.CONTENT_TYPE, "text/plain");
+ message.put(Message.RESPONSE_CODE, 500);
try {
String errorMessage = JAXRSUtils.logMessageHandlerProblem(name,
cls, ct);
if (out != null) {
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Fri Nov 8 12:56:50 2013
@@ -65,6 +65,8 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.validation.Schema;
+import org.w3c.dom.Element;
+
import org.xml.sax.helpers.DefaultHandler;
import org.apache.cxf.common.i18n.BundleUtils;
@@ -122,6 +124,7 @@ public abstract class AbstractJAXBProvid
private String collectionWrapperName;
private Map<String, String> collectionWrapperMap;
private List<String> jaxbElementClassNames;
+ private boolean xmlRootAsJaxbElement;
private Map<String, Object> cProperties;
private Map<String, Object> uProperties;
@@ -139,6 +142,11 @@ public abstract class AbstractJAXBProvid
private DocumentDepthProperties depthProperties;
private String namespaceMapperPropertyName;
+ public void setXmlRootAsJaxbElement(boolean xmlRootAsJaxbElement) {
+ this.xmlRootAsJaxbElement = xmlRootAsJaxbElement;
+ }
+
+
protected void setNamespaceMapper(Marshaller ms,
Map<String, String> map) throws
Exception {
Object nsMapper = JAXBUtils.setNamespaceMapper(map, ms);
@@ -259,7 +267,7 @@ public abstract class AbstractJAXBProvid
Class<?> jaxbElementCls = jaxbElementClassNames == null ? null :
getJaxbElementClass(cls);
boolean asJaxbElement = jaxbElementCls != null;
- if (!asJaxbElement && isXmlRoot(cls)) {
+ if (!asJaxbElement && isXmlRoot(cls) && !xmlRootAsJaxbElement) {
return obj;
}
if (jaxbElementCls == null) {
@@ -839,12 +847,23 @@ public abstract class AbstractJAXBProvid
}
@SuppressWarnings("unchecked")
- public <T> Object getCollectionOrArray(Class<T> type, Class<?>
origType,
- XmlJavaTypeAdapter adapter) {
+ public <T> Object getCollectionOrArray(Unmarshaller unm, Class<T>
type, Class<?> origType,
+ XmlJavaTypeAdapter adapter)
throws JAXBException {
List<?> theList = getList();
boolean adapterChecked = false;
if (theList.size() > 0) {
Object first = theList.get(0);
+
+ if (first instanceof Element) {
+ List<Object> newList = new
ArrayList<Object>(theList.size());
+ for (Object o : theList) {
+ newList.add(unm.unmarshal((Element)o));
+ }
+ theList = newList;
+ }
+
+ first = theList.get(0);
+
if (first instanceof JAXBElement &&
!JAXBElement.class.isAssignableFrom(type)) {
adapterChecked = true;
List<Object> newList = new
ArrayList<Object>(theList.size());
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Nov 8 12:56:50 2013
@@ -187,7 +187,8 @@ public class JAXBElementProvider<T> exte
response = ((JAXBElement<?>)response).getValue();
}
if (isCollection) {
- response =
((CollectionWrapper)response).getCollectionOrArray(theType, type,
+ response = ((CollectionWrapper)response).getCollectionOrArray(
+ unmarshaller, theType, type,
org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theGenericType, anns));
} else {
response = checkAdapter(response, type, anns, false);
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Nov 8 12:56:50 2013
@@ -1283,8 +1283,12 @@ public final class InjectionUtils {
return type;
}
public static Class<?> updateParamClassToTypeIfNeeded(Class<?> paramCls,
Type type) {
- if (type instanceof Class &&
paramCls.isAssignableFrom((Class<?>)type)) {
- paramCls = (Class<?>)type;
+ if (paramCls != type && type instanceof Class) {
+ Class<?> clsType = (Class<?>)type;
+ if (paramCls.isAssignableFrom(clsType)
+ || clsType != Object.class && !clsType.isInterface() &&
clsType.isAssignableFrom(paramCls)) {
+ paramCls = clsType;
+ }
}
return paramCls;
}
Modified:
cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++
cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Fri Nov 8 12:56:50 2013
@@ -236,7 +236,8 @@ public class JSONProvider<T> extends Abs
response = ((JAXBElement<?>)response).getValue();
}
if (isCollection) {
- response =
((CollectionWrapper)response).getCollectionOrArray(theType, type,
+ response = ((CollectionWrapper)response).getCollectionOrArray(
+ unmarshaller, theType, type,
org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theGenericType, anns));
} else {
response = checkAdapter(response, type, anns, false);
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
Fri Nov 8 12:56:50 2013
@@ -28,6 +28,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
@@ -35,6 +36,7 @@ import com.fasterxml.jackson.annotation.
@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY, property = "class")
@XmlRootElement(name = "Book")
+@XmlSeeAlso(SuperBook.class)
public class Book {
private String name;
private long id;
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Nov 8 12:56:50 2013
@@ -572,7 +572,8 @@ public class BookStore {
@Path("/collections2")
@Produces({"application/xml", "application/json" })
@Consumes({"application/xml", "application/json" })
- public List<BookNoXmlRootElement>
getBookCollection2(List<BookNoXmlRootElement> bs) throws Exception {
+ public List<JAXBElement<BookNoXmlRootElement>> getBookCollection2(
+ List<JAXBElement<BookNoXmlRootElement>> bs) throws Exception {
if (bs == null || bs.size() != 2) {
throw new RuntimeException();
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java?rev=1540006&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
Fri Nov 8 12:56:50 2013
@@ -0,0 +1,124 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import javax.xml.bind.annotation.XmlType;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+
+@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY, property = "class")
+@XmlType(name = "Book")
+@XmlSeeAlso(SuperBook2.class)
+public class BookType {
+ private String name;
+ private long id;
+ private Map<Long, Chapter> chapters = new HashMap<Long, Chapter>();
+
+ public BookType() {
+ init();
+ //System.out.println("----chapters: " + chapters.size());
+ }
+
+ public BookType(String name, long id) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public void setName(String n) {
+ name = n;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setId(long i) {
+ id = i;
+ }
+ public long getId() {
+ return id;
+ }
+
+ @PUT
+ public void cloneState(BookType book) {
+ id = book.getId();
+ name = book.getName();
+ }
+
+ @GET
+ public BookType retrieveState() {
+ return this;
+ }
+
+ @GET
+ @Path("chapters/{chapterid}/")
+ @Produces("application/xml;charset=ISO-8859-1")
+ public Chapter getChapter(@PathParam("chapterid")int chapterid) {
+ return chapters.get(new Long(chapterid));
+ }
+
+ @GET
+ @Path("chapters/acceptencoding/{chapterid}/")
+ @Produces("application/xml")
+ public Chapter getChapterAcceptEncoding(@PathParam("chapterid")int
chapterid) {
+ return chapters.get(new Long(chapterid));
+ }
+
+ @GET
+ @Path("chapters/badencoding/{chapterid}/")
+ @Produces("application/xml;charset=UTF-48")
+ public Chapter getChapterBadEncoding(@PathParam("chapterid")int chapterid)
{
+ return chapters.get(new Long(chapterid));
+ }
+
+ @Path("chapters/sub/{chapterid}/")
+ public Chapter getSubChapter(@PathParam("chapterid")int chapterid) {
+ return chapters.get(new Long(chapterid));
+ }
+
+ @Path("chaptersobject/sub/{chapterid}/")
+ public Object getSubChapterObject(@PathParam("chapterid")int chapterid) {
+ return getSubChapter(chapterid);
+ }
+
+
+ final void init() {
+ Chapter c1 = new Chapter();
+ c1.setId(1);
+ c1.setTitle("chapter 1");
+ chapters.put(c1.getId(), c1);
+ Chapter c2 = new Chapter();
+ c2.setId(2);
+ c2.setTitle("chapter 2");
+ chapters.put(c2.getId(), c2);
+ }
+
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring2.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring2.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring2.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring2.java
Fri Nov 8 12:56:50 2013
@@ -31,13 +31,13 @@ import javax.ws.rs.WebApplicationExcepti
import org.apache.cxf.annotations.Logging;
@Path("/")
-@Produces("application/json")
-@Consumes("application/json")
+@Consumes({"application/json", "application/xml" })
+@Produces({"application/json", "application/xml" })
@Logging
public class GenericBookStoreSpring2 extends AbstractBookStoreSpring {
@POST
@Path("/books/superbook")
- public <T extends Book> T echoSuperBookJson(T book) {
+ public <T extends Book> T echoSuperBook(T book) {
if (((SuperBook)book).isSuperBook()) {
return book;
}
@@ -46,13 +46,31 @@ public class GenericBookStoreSpring2 ext
@POST
@Path("/books/superbooks")
- public <T extends Book> List<T> echoSuperBookCollectionJson(List<T> book) {
+ public <T extends Book> List<T> echoSuperBookCollection(List<T> book) {
if (((SuperBook)book.get(0)).isSuperBook()) {
return book;
}
throw new WebApplicationException(400);
}
+ @POST
+ @Path("/books/superbooktype")
+ public <T extends BookType> T echoSuperBookType(T book) {
+ if (((SuperBook2)book).isSuperBook()) {
+ return book;
+ }
+ throw new WebApplicationException(400);
+ }
+
+ @POST
+ @Path("/books/superbooktypes")
+ public <T extends BookType> List<T> echoSuperBookTypeCollection(List<T>
book) {
+ if (((SuperBook2)book.get(0)).isSuperBook()) {
+ return book;
+ }
+ throw new WebApplicationException(400);
+ }
+
}
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Nov 8 12:56:50 2013
@@ -880,6 +880,7 @@ public class JAXRSClientServerBookTest e
}
@Test
+ @Ignore
public void testGetBookCollection2() throws Exception {
JAXBElementProvider<?> provider = new JAXBElementProvider<Object>();
provider.setMarshallAsJaxbElement(true);
@@ -889,18 +890,21 @@ public class JAXRSClientServerBookTest e
Collections.singletonList(provider));
BookNoXmlRootElement b1 = new BookNoXmlRootElement("CXF in Action",
123L);
BookNoXmlRootElement b2 = new BookNoXmlRootElement("CXF Rocks", 124L);
- List<BookNoXmlRootElement> books = new
ArrayList<BookNoXmlRootElement>();
- books.add(b1);
- books.add(b2);
+ List<JAXBElement<BookNoXmlRootElement>> books =
+ new ArrayList<JAXBElement<BookNoXmlRootElement>>();
+ books.add(new JAXBElement<BookNoXmlRootElement>(new
QName("bookNoXmlRootElement"),
+ BookNoXmlRootElement.class, b1));
+ books.add(new JAXBElement<BookNoXmlRootElement>(new
QName("bookNoXmlRootElement"),
+ BookNoXmlRootElement.class, b2));
WebClient.getConfig(store).getHttpConduit().getClient().setReceiveTimeout(10000000L);
- List<BookNoXmlRootElement> books2 = store.getBookCollection2(books);
+ List<JAXBElement<BookNoXmlRootElement>> books2 =
store.getBookCollection2(books);
assertNotNull(books2);
assertNotSame(books, books2);
assertEquals(2, books2.size());
- BookNoXmlRootElement b11 = books.get(0);
+ BookNoXmlRootElement b11 = books.get(0).getValue();
assertEquals(123L, b11.getId());
assertEquals("CXF in Action", b11.getName());
- BookNoXmlRootElement b22 = books.get(1);
+ BookNoXmlRootElement b22 = books.get(1).getValue();
assertEquals(124L, b22.getId());
assertEquals("CXF Rocks", b22.getName());
}
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Fri Nov 8 12:56:50 2013
@@ -35,6 +35,7 @@ import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
@@ -141,27 +142,127 @@ public class JAXRSClientServerResourceJa
}
@Test
- public void testEchoGenericSuperBookProxy2() throws Exception {
+ public void testEchoGenericSuperBookProxy2Json() throws Exception {
String endpointAddress =
"http://localhost:" + PORT + "/webapp/genericstore2";
GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
GenericBookStoreSpring2.class, Collections.singletonList(new
JacksonJsonProvider()));
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
- SuperBook book = proxy.echoSuperBookJson(new SuperBook("Super", 124L,
true));
+
WebClient.client(proxy).type("application/json").accept("application/json");
+ SuperBook book = proxy.echoSuperBook(new SuperBook("Super", 124L,
true));
+ assertEquals(124L, book.getId());
+ assertTrue(book.isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookProxy2JsonType() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2type";
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class, Collections.singletonList(new
JacksonJsonProvider()));
+
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
+
WebClient.client(proxy).type("application/json").accept("application/json");
+ SuperBook2 book = proxy.echoSuperBookType(new SuperBook2("Super",
124L, true));
+ assertEquals(124L, book.getId());
+ assertTrue(book.isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookProxy2Xml() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2";
+ JAXBElementProvider<Object> jaxbProvider = new
JAXBElementProvider<Object>();
+ jaxbProvider.setXmlRootAsJaxbElement(true);
+ jaxbProvider.setMarshallAsJaxbElement(true);
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class,
Collections.singletonList(jaxbProvider));
+
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
+
WebClient.client(proxy).type("application/xml").accept("application/xml");
+ SuperBook book = proxy.echoSuperBook(new SuperBook("Super", 124L,
true));
+ assertEquals(124L, book.getId());
+ assertTrue(book.isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookProxy2XmlType() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2type";
+ JAXBElementProvider<Object> jaxbProvider = new
JAXBElementProvider<Object>();
+ jaxbProvider.setMarshallAsJaxbElement(true);
+ jaxbProvider.setUnmarshallAsJaxbElement(true);
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class,
Collections.singletonList(jaxbProvider));
+
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
+
WebClient.client(proxy).type("application/xml").accept("application/xml");
+ SuperBook2 book = proxy.echoSuperBookType(new SuperBook2("Super",
124L, true));
assertEquals(124L, book.getId());
assertTrue(book.isSuperBook());
}
@Test
- public void testEchoGenericSuperBookCollectionProxy2() throws Exception {
+ public void testEchoGenericSuperBookCollectionProxy2Json() throws
Exception {
String endpointAddress =
"http://localhost:" + PORT + "/webapp/genericstore2";
GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
GenericBookStoreSpring2.class, Collections.singletonList(new
JacksonJsonProvider()));
+
WebClient.client(proxy).type("application/json").accept("application/json");
List<SuperBook> books =
- proxy.echoSuperBookCollectionJson(Collections.singletonList(new
SuperBook("Super", 124L, true)));
+ proxy.echoSuperBookCollection(Collections.singletonList(new
SuperBook("Super", 124L, true)));
+ assertEquals(124L, books.get(0).getId());
+ assertTrue(books.get(0).isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookCollectionProxy2JsonType() throws
Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2type";
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class, Collections.singletonList(new
JacksonJsonProvider()));
+
WebClient.client(proxy).type("application/json").accept("application/json");
+ List<SuperBook2> books =
+ proxy.echoSuperBookTypeCollection(Collections.singletonList(new
SuperBook2("Super", 124L, true)));
+ assertEquals(124L, books.get(0).getId());
+ assertTrue(books.get(0).isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookCollectionProxy2Xml() throws Exception
{
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2";
+ JAXBElementProvider<Object> jaxbProvider = new
JAXBElementProvider<Object>();
+ jaxbProvider.setMarshallAsJaxbElement(true);
+ jaxbProvider.setUnmarshallAsJaxbElement(true);
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class,
Collections.singletonList(jaxbProvider));
+
WebClient.client(proxy).type("application/xml").accept("application/xml");
+
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
+ List<SuperBook> books =
+ proxy.echoSuperBookCollection(Collections.singletonList(new
SuperBook("Super", 124L, true)));
+ assertEquals(124L, books.get(0).getId());
+ assertTrue(books.get(0).isSuperBook());
+ }
+
+ @Test
+ public void testEchoGenericSuperBookCollectionProxy2XmlType() throws
Exception {
+
+ String endpointAddress =
+ "http://localhost:" + PORT + "/webapp/genericstore2type";
+ JAXBElementProvider<Object> jaxbProvider = new
JAXBElementProvider<Object>();
+ jaxbProvider.setMarshallAsJaxbElement(true);
+ jaxbProvider.setUnmarshallAsJaxbElement(true);
+ GenericBookStoreSpring2 proxy =
JAXRSClientFactory.create(endpointAddress,
+ GenericBookStoreSpring2.class,
Collections.singletonList(jaxbProvider));
+
WebClient.client(proxy).type("application/xml").accept("application/xml");
+
WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
+ List<SuperBook2> books =
+ proxy.echoSuperBookTypeCollection(Collections.singletonList(new
SuperBook2("Super", 124L, true)));
assertEquals(124L, books.get(0).getId());
assertTrue(books.get(0).isSuperBook());
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java?rev=1540006&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
Fri Nov 8 12:56:50 2013
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+@XmlRootElement(name = "SuperBook")
+public class SuperBook2 extends BookType {
+ private boolean superBook;
+
+ public SuperBook2() {
+
+ }
+
+ public SuperBook2(String name, long id, boolean superStatus) {
+ super(name, id);
+ this.superBook = superStatus;
+ }
+
+ public boolean isSuperBook() {
+ return superBook;
+ }
+
+ public void setSuperBook(boolean superBook) {
+ this.superBook = superBook;
+ }
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook2.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml?rev=1540006&r1=1540005&r2=1540006&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
(original)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
Fri Nov 8 12:56:50 2013
@@ -67,7 +67,23 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
</jaxrs:providers>
</jaxrs:server>
+ <jaxrs:server id="genericBookStore2type"
+ address="/genericstore2type">
+ <jaxrs:serviceBeans>
+ <ref bean="gBookStore2"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="jackson"/>
+ <ref bean="jaxb"/>
+ </jaxrs:providers>
+ </jaxrs:server>
+
<bean id="jackson"
class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
+ <bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
+ <property name="unmarshallAsJaxbElement" value="true"/>
+ <property name="marshallAsJaxbElement" value="true"/>
+ </bean>
+
<bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
<bean id="bookstore2"
class="org.apache.cxf.systest.jaxrs.BookStoreSpring"/>
<bean id="gBookStore"
class="org.apache.cxf.systest.jaxrs.GenericBookStoreSpring"/>