Author: dkulp
Date: Wed Oct 22 09:44:35 2008
New Revision: 707128
URL: http://svn.apache.org/viewvc?rev=707128&view=rev
Log:
Merged revisions 707089 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r707089 | sergeyb | 2008-10-22 10:30:41 -0400 (Wed, 22 Oct 2008) | 1 line
JAXRS: fix for CXF-1882
........
Added:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java
- copied unchanged from r707089,
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 22 09:44:35 2008
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706675,706900,706909,707034
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706675,706900,706909,707034,707089
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=707128&r1=707127&r2=707128&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Wed Oct 22 09:44:35 2008
@@ -38,6 +38,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.SecurityContext;
@@ -104,6 +105,20 @@
return PARAM_ANNOTATION_CLASSES.contains(annotationClass);
}
+ public static boolean isMethodParamAnnotationClass(Class<?>
annotationClass) {
+ return PARAM_ANNOTATION_CLASSES.contains(annotationClass)
+ || Context.class == annotationClass;
+ }
+
+ public static boolean isMethodParamAnnotations(Annotation[]
paramAnnotations) {
+ for (Annotation a : paramAnnotations) {
+ if
(AnnotationUtils.isMethodParamAnnotationClass(a.annotationType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static boolean isMethodAnnotation(Annotation a) {
return METHOD_ANNOTATION_CLASSES.contains(a.annotationType())
|| a.annotationType() == HttpMethod.class;
@@ -141,19 +156,16 @@
if (m == null) {
return m;
}
+
for (Annotation a : m.getAnnotations()) {
if (AnnotationUtils.isMethodAnnotation(a)) {
return m;
}
}
- for (Annotation[] paramAnnotations : m.getParameterAnnotations()) {
- for (Annotation a : paramAnnotations) {
- if
(AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
- return m;
- }
- }
- }
+ if (isMethodParamAnnotations(m.getAnnotations())) {
+ return m;
+ }
Class<?> superC = m.getDeclaringClass().getSuperclass();
if (superC != null) {
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=707128&r1=707127&r2=707128&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Wed Oct 22 09:44:35 2008
@@ -345,8 +345,8 @@
String path = (String)message.get(JAXRSInInterceptor.RELATIVE_PATH);
- if (parameterAnns == null || parameterAnns.length == 0) {
- // we can't really limit it to just PUT and POST
+ if (parameterAnns == null
+ || !AnnotationUtils.isMethodParamAnnotations(parameterAnns)) {
String contentType = (String)message.get(Message.CONTENT_TYPE);
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=707128&r1=707127&r2=707128&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
Wed Oct 22 09:44:35 2008
@@ -42,7 +42,7 @@
import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
-public class Customer {
+public class Customer implements CustomerInfo {
@XmlRootElement(name = "CustomerBean")
public static class CustomerBean {
@@ -107,6 +107,9 @@
uriInfo = ui;
}
+ public void setUriInfoContext(UriInfo ui) {
+ }
+
@Context
public void setServletContext(ServletContext sc) {
servletContext3 = sc;
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=707128&r1=707127&r2=707128&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Wed Oct 22 09:44:35 2008
@@ -612,6 +612,27 @@
}
@Test
+ public void testHttpContextParametersFromInterface() throws Exception {
+
+ ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+ Method methodToInvoke =
+ Customer.class.getMethod("setUriInfoContext",
+ new Class[]{UriInfo.class});
+ OperationResourceInfo ori =
+ new OperationResourceInfo(methodToInvoke, cri);
+ ori.setHttpMethod("GET");
+
ori.setAnnotatedMethod(AnnotationUtils.getAnnotatedMethod(methodToInvoke));
+
+
+ Message m = new MessageImpl();
+
+ List<Object> params =
+ JAXRSUtils.processParameters(ori, new MetadataMap<String,
String>(), m);
+ assertEquals("1 parameters expected", 1, params.size());
+ assertSame(UriInfoImpl.class, params.get(0).getClass());
+ }
+
+ @Test
public void testServletContextParameters() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
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=707128&r1=707127&r2=707128&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
Wed Oct 22 09:44:35 2008
@@ -23,8 +23,10 @@
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.ProduceMime;
@WebService
@Path("/bookstore")
@@ -35,4 +37,9 @@
@Path("/{id}")
Book getBook(@PathParam("id") @WebParam(name = "id") Long id);
+ @WebMethod
+ @POST
+ @Path("/books")
+ @ProduceMime("application/xml")
+ Book addBook(@WebParam(name = "book") Book book);
}
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=707128&r1=707127&r2=707128&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
Wed Oct 22 09:44:35 2008
@@ -36,7 +36,13 @@
public Book getBook(Long id) {
return books.get(id);
}
-
+
+ public Book addBook(Book book) {
+ book.setId(124);
+ books.put(book.getId(), book);
+ return books.get(book.getId());
+ }
+
private void init() {
Book book = new Book();
book.setId(new Long(123));
Modified:
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java?rev=707128&r1=707127&r2=707128&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
(original)
+++
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
Wed Oct 22 09:44:35 2008
@@ -19,12 +19,17 @@
package org.apache.cxf.systest.jaxrs;
+import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.namespace.QName;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -55,6 +60,33 @@
}
@Test
+ public void testAddGetBookRest() throws Exception {
+
+ String endpointAddress =
+ "http://localhost:9092/rest/bookstore/books";
+
+ File input = new
File(getClass().getResource("resources/add_book.txt").toURI());
+ PostMethod post = new PostMethod(endpointAddress);
+ post.setRequestHeader("Content-Type", "application/xml");
+ RequestEntity entity = new FileRequestEntity(input, "text/xml;
charset=ISO-8859-1");
+ post.setRequestEntity(entity);
+ HttpClient httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(post);
+ assertEquals(200, result);
+
+ InputStream expected =
getClass().getResourceAsStream("resources/expected_add_book.txt");
+
+ assertEquals(getStringFromInputStream(expected),
post.getResponseBodyAsString());
+ } finally {
+ // Release current connection to the connection pool once you are
done
+ post.releaseConnection();
+ }
+
+ }
+
+ @Test
public void testGetBookSoap() throws Exception {
String wsdlAddress =
"http://localhost:9092/soap/bookservice?wsdl";