Author: dkulp Date: Mon Apr 14 09:45:50 2008 New Revision: 647895 URL: http://svn.apache.org/viewvc?rev=647895&view=rev Log: [CXF-1494] More jaxrs/Spring AOP fixes from Sergey
Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java (with props) incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java (with props) incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java (with props) Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PathSegmentImpl.java incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java incubator/cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon Apr 14 09:45:50 2008 @@ -21,6 +21,7 @@ import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; @@ -55,9 +56,27 @@ OperationResourceInfo ori = exchange.get(OperationResourceInfo.class); ClassResourceInfo cri = ori.getClassResourceInfo(); - Method m = cri.getMethodDispatcher().getMethod(ori); + Method methodToInvoke = cri.getMethodDispatcher().getMethod(ori); Object resourceObject = getServiceObject(exchange, resources); + // TODO : update the method dispatcher + if (Proxy.class.isInstance(resourceObject)) { + + for (Class<?> c : resourceObject.getClass().getInterfaces()) { + try { + Method m = c.getMethod( + methodToInvoke.getName(), methodToInvoke.getParameterTypes()); + if (m != null) { + methodToInvoke = m; + break; + } + } catch (NoSuchMethodException ex) { + //ignore + } + } + + } + if (cri.isRoot()) { JAXRSUtils.injectHttpContextValues(resourceObject, ori, @@ -76,7 +95,7 @@ Object result = null; try { - result = invoke(exchange, resourceObject, m, params); + result = invoke(exchange, resourceObject, methodToInvoke, params); } catch (Fault ex) { if (ex.getCause() instanceof WebApplicationException) { WebApplicationException wex = (WebApplicationException)ex.getCause(); Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java Mon Apr 14 09:45:50 2008 @@ -181,8 +181,8 @@ String httpMethod = JAXRSUtils.getHttpMethodValue(m); - - if (httpMethod != null && m.getAnnotation(Path.class) != null) { + Path path = (Path)JAXRSUtils.getMethodAnnotation(m, Path.class); + if (httpMethod != null && path != null) { /* * Sub-resource method, URI template created by concatenating * the URI template of the resource class with the URI template @@ -190,15 +190,15 @@ */ OperationResourceInfo ori = new OperationResourceInfo(m, cri); URITemplate t = - URITemplate.createTemplate(cri, m.getAnnotation(Path.class)); + URITemplate.createTemplate(cri, path); ori.setURITemplate(t); ori.setHttpMethod(httpMethod); md.bind(ori, m); - } else if (m.getAnnotation(Path.class) != null) { + } else if (path != null) { // sub-resource locator OperationResourceInfo ori = new OperationResourceInfo(m, cri); URITemplate t = - URITemplate.createTemplate(cri, m.getAnnotation(Path.class)); + URITemplate.createTemplate(cri, path); ori.setURITemplate(t); md.bind(ori, m); Class subResourceClass = m.getReturnType(); Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java Mon Apr 14 09:45:50 2008 @@ -23,8 +23,10 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.net.URLDecoder; import java.util.ArrayList; @@ -89,9 +91,79 @@ return httpM.value(); } } + // TODO : make it shorter + for (Class<?> i : m.getDeclaringClass().getInterfaces()) { + try { + Method interfaceMethod = i.getMethod(m.getName(), m.getParameterTypes()); + if (interfaceMethod != null) { + return getHttpMethodValue(interfaceMethod); + } + } catch (NoSuchMethodException ex) { + //ignore + } + } + Class<?> superC = m.getDeclaringClass().getSuperclass(); + if (superC != null) { + try { + Method cMethod = superC.getMethod(m.getName(), m.getParameterTypes()); + if (cMethod != null) { + return getHttpMethodValue(cMethod); + } + } catch (NoSuchMethodException ex) { + //ignore + } + } + + return null; + } + + public static Annotation getMethodAnnotation(Method m, + Class<? extends Annotation> aClass) { + Annotation a = m.getAnnotation(aClass); + if (a != null) { + return a; + } + + for (Class<?> i : m.getDeclaringClass().getInterfaces()) { + a = getClassMethodAnnotation(m, i, aClass); + if (a != null) { + return a; + } + } + Class<?> superC = m.getDeclaringClass().getSuperclass(); + if (superC != null) { + return getClassMethodAnnotation(m, superC, aClass); + } + + return null; + } + + private static Annotation getClassMethodAnnotation(Method m, + Class<?> c, + Class<? extends Annotation> aClass) { + try { + Method interfaceMethod = c.getMethod(m.getName(), m.getParameterTypes()); + if (interfaceMethod != null) { + return getMethodAnnotation(interfaceMethod, aClass); + } + } catch (NoSuchMethodException ex) { + //ignore + } return null; } + public static Annotation getClassAnnotation(Class<?> c, + Class<? extends Annotation> aClass) { + if (c == null) { + return null; + } + Annotation p = c.getAnnotation(aClass); + if (p != null) { + return p; + } + return getClassAnnotation(c.getSuperclass(), aClass); + } + public static List<PathSegment> getPathSegments(String thePath, boolean decode) { String[] segments = thePath.split("/"); List<PathSegment> theList = new ArrayList<PathSegment>(); @@ -327,15 +399,18 @@ if (parameterAnnotations[0].annotationType() == QueryParam.class) { result = readQueryString((QueryParam)parameterAnnotations[0], parameterClass, message, null); } else if (parameterAnnotations[0].annotationType() == MatrixParam.class) { - result = processMatrixParam(message, ((MatrixParam)parameterAnnotations[0]).value(), null); + result = processMatrixParam(message, ((MatrixParam)parameterAnnotations[0]).value(), + parameterClass, null); } else if (parameterAnnotations[0].annotationType() == HeaderParam.class) { - result = processHeaderParam(message, ((HeaderParam)parameterAnnotations[0]).value(), null); + result = processHeaderParam(message, ((HeaderParam)parameterAnnotations[0]).value(), + parameterClass, null); } return result; } - private static Object processMatrixParam(Message m, String key, String defaultValue) { + private static Object processMatrixParam(Message m, String key, + Class<?> pClass, String defaultValue) { List<PathSegment> segments = JAXRSUtils.getPathSegments( (String)m.get(Message.PATH_INFO), true); String value = null; @@ -348,7 +423,7 @@ } } - return value == null ? defaultValue : value; + return value == null ? defaultValue : handleParameter(value, pClass); } public static MultivaluedMap<String, String> getMatrixParams(String path, boolean decode) { @@ -358,7 +433,8 @@ } @SuppressWarnings("unchecked") - private static Object processHeaderParam(Message m, String header, String defaultValue) { + private static Object processHeaderParam(Message m, String header, + Class<?> pClass, String defaultValue) { Map<String, List<String>> headers = (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS); List<String> values = headers.get(header); StringBuilder sb = new StringBuilder(); @@ -370,7 +446,7 @@ } } } - return sb.length() > 0 ? sb.toString() : defaultValue; + return sb.length() > 0 ? handleParameter(sb.toString(), pClass) : defaultValue; } @SuppressWarnings("unchecked") @@ -421,28 +497,53 @@ return null; } - Object result = null; + String result = null; List<String> results = values.get(parameterName); if (values != null && values.size() > 0) { result = results.get(results.size() - 1); } - if (result != null && parameter.isPrimitive()) { - result = PrimitiveUtils.read((String)result, parameter); + if (result != null) { + return handleParameter(result, parameter); } return result; } + private static Object handleParameter(String value, Class<?> pClass) { + if (pClass.isPrimitive()) { + return PrimitiveUtils.read(value, pClass); + } + // check constructors accepting a single String value + try { + Constructor<?> c = pClass.getConstructor(new Class<?>[]{String.class}); + if (c != null) { + return c.newInstance(new Object[]{value}); + } + } catch (Exception ex) { + // try valueOf + } + // check for valueOf(String) static methods + try { + Method m = pClass.getMethod("valueOf", new Class<?>[]{String.class}); + if (m != null && Modifier.isStatic(m.getModifiers())) { + return m.invoke(null, new Object[]{value}); + } + } catch (Exception ex) { + // no luck + } + return null; + } + //TODO : multiple query string parsing, do it once private static Object readQueryString(QueryParam queryParam, Class<?> parameter, Message m, String defaultValue) { String queryName = queryParam.value(); - Object result = getStructuredParams((String)m.get(Message.QUERY_STRING), + String result = getStructuredParams((String)m.get(Message.QUERY_STRING), "&", true).getFirst(queryName); if (parameter.isPrimitive()) { - result = PrimitiveUtils.read((String)result, parameter); + return handleParameter(result, parameter); } return result; } Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java Mon Apr 14 09:45:50 2008 @@ -30,6 +30,7 @@ import javax.ws.rs.ProduceMime; import javax.ws.rs.core.Context; +import org.apache.cxf.jaxrs.JAXRSUtils; import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; public class ClassResourceInfo { @@ -142,19 +143,16 @@ } } - //TODO : check supeclass as well public ProduceMime getProduceMime() { - return getServiceClass().getAnnotation(ProduceMime.class); + return (ProduceMime)JAXRSUtils.getClassAnnotation(getServiceClass(), ProduceMime.class); } - //TODO : check supeclass as well public ConsumeMime getConsumeMime() { - return getServiceClass().getAnnotation(ConsumeMime.class); + return (ConsumeMime)JAXRSUtils.getClassAnnotation(getServiceClass(), ConsumeMime.class); } - //TODO : check supeclass as well public Path getPath() { - return getServiceClass().getAnnotation(Path.class); + return (Path)JAXRSUtils.getClassAnnotation(getServiceClass(), Path.class); } public List<Field> getHttpContexts() { @@ -175,5 +173,7 @@ ret = Collections.emptyList(); } return ret; - } + } + + } Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java Mon Apr 14 09:45:50 2008 @@ -80,7 +80,8 @@ public List<MediaType> getProduceTypes() { // this needs to be calculated on init - ProduceMime pm = method.getAnnotation(ProduceMime.class); + ProduceMime pm = + (ProduceMime)JAXRSUtils.getMethodAnnotation(method, ProduceMime.class); if (pm != null) { return JAXRSUtils.getMediaTypes(pm.value()); } @@ -91,7 +92,8 @@ public List<MediaType> getConsumeTypes() { // this needs to be calculated on init - ConsumeMime pm = method.getAnnotation(ConsumeMime.class); + ConsumeMime pm = + (ConsumeMime)JAXRSUtils.getMethodAnnotation(method, ConsumeMime.class); if (pm != null) { return JAXRSUtils.getMediaTypes(pm.value()); } Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PathSegmentImpl.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PathSegmentImpl.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PathSegmentImpl.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PathSegmentImpl.java Mon Apr 14 09:45:50 2008 @@ -31,6 +31,10 @@ private String path; private boolean decode; + public PathSegmentImpl(String path) { + this(path, true); + } + public PathSegmentImpl(String path, boolean decode) { this.path = path; this.decode = decode; Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java Mon Apr 14 09:45:50 2008 @@ -83,9 +83,21 @@ assertTrue(template.match("/bookstore/books/123", values)); assertTrue(rootCri.hasSubResources()); MethodDispatcher md = rootCri.getMethodDispatcher(); - assertEquals(4, md.getOperationResourceInfos().size()); + assertEquals(6, md.getOperationResourceInfos().size()); for (OperationResourceInfo ori : md.getOperationResourceInfos()) { - if ("getBook".equals(ori.getMethod().getName())) { + if ("getDescription".equals(ori.getMethod().getName())) { + assertEquals("GET", ori.getHttpMethod()); + assertEquals("/path", ori.getURITemplate().getValue()); + assertEquals("text/bar", ori.getProduceTypes().get(0).toString()); + assertEquals("text/foo", ori.getConsumeTypes().get(0).toString()); + assertFalse(ori.isSubResourceLocator()); + } else if ("getAuthor".equals(ori.getMethod().getName())) { + assertEquals("GET", ori.getHttpMethod()); + assertEquals("/path2", ori.getURITemplate().getValue()); + assertEquals("text/bar2", ori.getProduceTypes().get(0).toString()); + assertEquals("text/foo2", ori.getConsumeTypes().get(0).toString()); + assertFalse(ori.isSubResourceLocator()); + } else if ("getBook".equals(ori.getMethod().getName())) { assertNull(ori.getHttpMethod()); assertNotNull(ori.getURITemplate()); assertTrue(ori.isSubResourceLocator()); Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java Mon Apr 14 09:45:50 2008 @@ -18,6 +18,7 @@ */ package org.apache.cxf.jaxrs; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; @@ -31,12 +32,15 @@ import javax.ws.rs.ConsumeMime; import javax.ws.rs.HeaderParam; import javax.ws.rs.MatrixParam; +import javax.ws.rs.Path; +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.MediaType; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.PathSegment; import javax.ws.rs.core.Request; import javax.ws.rs.core.SecurityContext; import javax.ws.rs.core.UriInfo; @@ -46,21 +50,19 @@ import org.apache.cxf.jaxrs.model.OperationResourceInfo; import org.apache.cxf.jaxrs.model.URITemplate; import org.apache.cxf.jaxrs.provider.HttpHeadersImpl; +import org.apache.cxf.jaxrs.provider.PathSegmentImpl; import org.apache.cxf.jaxrs.provider.RequestImpl; import org.apache.cxf.jaxrs.provider.SecurityContextImpl; import org.apache.cxf.jaxrs.provider.UriInfoImpl; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageImpl; import org.apache.cxf.transport.http.AbstractHTTPDestination; - +import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.replay; - public class JAXRSUtilsTest extends Assert { public class Customer { @@ -73,6 +75,7 @@ @Resource private HttpServletResponse servletResponse; @Resource private ServletContext servletContext; + public UriInfo getUriInfo() { return uriInfo; } @@ -142,6 +145,12 @@ @HeaderParam("Foo") String h) { // complete } + + @Path("{id1}/{id2}") + public void testConversion(@PathParam("id1") PathSegmentImpl id1, + @PathParam("id2") SimpleFactory f) { + // complete + } }; @Before @@ -618,12 +627,12 @@ Customer c = new Customer(); // Creating mocks for the servlet request, response and context - HttpServletRequest request = createMock(HttpServletRequest.class); - HttpServletResponse response = createMock(HttpServletResponse.class); - ServletContext context = createMock(ServletContext.class); - replay(request); - replay(response); - replay(context); + HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); + HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class); + ServletContext context = EasyMock.createMock(ServletContext.class); + EasyMock.replay(request); + EasyMock.replay(response); + EasyMock.replay(context); Message m = new MessageImpl(); m.put(AbstractHTTPDestination.HTTP_REQUEST, request); @@ -635,5 +644,32 @@ assertSame(response.getClass(), c.getServletResponse().getClass()); assertSame(context.getClass(), c.getServletContext().getClass()); + } + + @Test + public void testConversion() throws Exception { + ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true); + OperationResourceInfo ori = + new OperationResourceInfo( + Customer.class.getMethod("testConversion", + new Class[]{PathSegmentImpl.class, + SimpleFactory.class}), + cri); + ori.setHttpMethod("GET"); + ori.setURITemplate(new URITemplate("{id1}/{id2}")); + MultivaluedMap<String, String> values = new MetadataMap<String, String>(); + values.putSingle("id1", "1"); + values.putSingle("id2", "2"); + + Message m = new MessageImpl(); + + + List<Object> params = + JAXRSUtils.processParameters(ori, values, m); + PathSegment ps = (PathSegment)params.get(0); + assertEquals("1", ps.getPath()); + + SimpleFactory sf = (SimpleFactory)params.get(1); + assertEquals(2, sf.getId()); } } Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,35 @@ +/** + * 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.jaxrs; + +public final class SimpleFactory { + private int id; + private SimpleFactory(String s) { + id = Integer.valueOf(s); + } + + public int getId() { + return id; + } + + public static SimpleFactory valueOf(String s) { + return new SimpleFactory(s); + } +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SimpleFactory.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java Mon Apr 14 09:45:50 2008 @@ -28,6 +28,9 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.ConsumeMime; +import javax.ws.rs.Path; +import javax.ws.rs.ProduceMime; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriInfo; @@ -37,6 +40,9 @@ public class ClassResourceInfoTest extends Assert { + @Path("/bar") + @ProduceMime("test/bar") + @ConsumeMime("test/foo") private static class TestClass { @Context UriInfo u; @Context HttpHeaders h; @@ -46,6 +52,13 @@ int i; } + private static class TestClass1 extends TestClass { + } + + private static class TestClass2 extends TestClass1 { + } + + @Test public void testGetHttpContexts() { ClassResourceInfo c = new ClassResourceInfo(TestClass.class); @@ -79,5 +92,41 @@ clses.contains(HttpServletRequest.class) && clses.contains(HttpServletResponse.class) && clses.contains(ServletContext.class)); + } + + @Test + public void testGetPath() { + ClassResourceInfo c = new ClassResourceInfo(TestClass.class); + assertEquals("/bar", c.getPath().value()); + + c = new ClassResourceInfo(TestClass1.class); + assertEquals("/bar", c.getPath().value()); + + c = new ClassResourceInfo(TestClass2.class); + assertEquals("/bar", c.getPath().value()); + } + + @Test + public void testGetProduce() { + ClassResourceInfo c = new ClassResourceInfo(TestClass.class); + assertEquals("test/bar", c.getProduceMime().value()[0]); + + c = new ClassResourceInfo(TestClass1.class); + assertEquals("test/bar", c.getProduceMime().value()[0]); + + c = new ClassResourceInfo(TestClass2.class); + assertEquals("test/bar", c.getProduceMime().value()[0]); + } + + @Test + public void testGetConsume() { + ClassResourceInfo c = new ClassResourceInfo(TestClass.class); + assertEquals("test/foo", c.getConsumeMime().value()[0]); + + c = new ClassResourceInfo(TestClass1.class); + assertEquals("test/foo", c.getConsumeMime().value()[0]); + + c = new ClassResourceInfo(TestClass2.class); + assertEquals("test/foo", c.getConsumeMime().value()[0]); } } Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,34 @@ +/** + * 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.jaxrs.resources; + +import javax.ws.rs.ConsumeMime; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.ProduceMime; + +public interface BookInterface { + + @GET + @Path("/path2") + @ProduceMime("text/bar2") + @ConsumeMime("text/foo2") + String getAuthor(); +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java (original) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java Mon Apr 14 09:45:50 2008 @@ -28,7 +28,7 @@ import javax.ws.rs.core.Response; @Path("/bookstore/") -public class BookStore { +public class BookStore extends BookSuperClass implements BookInterface { public BookStore() { } @@ -53,6 +53,17 @@ @DELETE @Path("/books/{bookId}/") public Response deleteBook(@PathParam("bookId") String id) { + return null; + } + + @Override + public String getDescription() { + // TODO Auto-generated method stub + return null; + } + + public String getAuthor() { + // TODO Auto-generated method stub return null; } } Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java (added) +++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,35 @@ +/** + * 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.jaxrs.resources; + +import javax.ws.rs.ConsumeMime; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.ProduceMime; + + +public abstract class BookSuperClass { + + @GET + @Path("/path") + @ProduceMime("text/bar") + @ConsumeMime("text/foo") + public abstract String getDescription(); +} Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,34 @@ +/** + * 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.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.ProduceMime; + +import org.apache.cxf.customer.book.BookNotFoundFault; + +public interface BookInterface { + + @GET + @Path("/thosebooks/{bookId}/") + @ProduceMime("application/xml") + Book getThatBook(Long id) throws BookNotFoundFault; +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,31 @@ +/** + * 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.Path; + [EMAIL PROTECTED]("/bookstorestorage/") +public abstract class BookStoreStorage { + protected Map<Long, Book> books = new HashMap<Long, Book>(); + protected long bookId = 123; +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreStorage.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java?rev=647895&view=auto ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java Mon Apr 14 09:45:50 2008 @@ -0,0 +1,73 @@ +/** + * 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. + */ + +/** + * 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.ws.rs.PathParam; + +import org.apache.cxf.customer.book.BookNotFoundDetails; +import org.apache.cxf.customer.book.BookNotFoundFault; + + +public class BookStoreWithInterface extends BookStoreStorage implements BookInterface { + + public BookStoreWithInterface() { + Book book = new Book(); + book.setId(bookId); + book.setName("CXF in Action"); + books.put(book.getId(), book); + } + + + public Book getThatBook(@PathParam("bookId") Long id) throws BookNotFoundFault { + return doGetBook(id); + } + + private Book doGetBook(Long id) throws BookNotFoundFault { + System.out.println("----invoking getBook with id: " + id); + Book book = books.get(id); + if (book != null) { + return book; + } else { + BookNotFoundDetails details = new BookNotFoundDetails(); + details.setId(id); + throw new BookNotFoundFault(details); + } + } + +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java Mon Apr 14 09:45:50 2008 @@ -38,6 +38,22 @@ } @Test + public void testGetThatBook123() throws Exception { + String endpointAddress = + "http://localhost:9080/bookstorestorage/thosebooks/123"; + URL url = new URL(endpointAddress); + URLConnection connect = url.openConnection(); + connect.addRequestProperty("Accept", "application/xml"); + InputStream in = connect.getInputStream(); + + InputStream expected = getClass() + .getResourceAsStream("resources/expected_get_book123.txt"); + + //System.out.println("---" + getStringFromInputStream(in)); + assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); + } + + @Test public void testGetBook123() throws Exception { String endpointAddress = "http://localhost:9080/bookstore/books/123"; Modified: incubator/cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml?rev=647895&r1=647894&r2=647895&view=diff ============================================================================== --- incubator/cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml (original) +++ incubator/cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml Mon Apr 14 09:45:50 2008 @@ -44,18 +44,20 @@ address="/"> <jaxrs:serviceBeans> <ref bean="bookstore"/> + <ref bean="bookstoreInterface"/> </jaxrs:serviceBeans> </jaxrs:server> <bean id="bookstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStore"/> + <bean id="bookstoreInterface" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStoreWithInterface"/> <aop:config> <aop:aspect id="loggingAspect" ref="simpleLogger"> <aop:before method="logBefore" - pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore.*(..))"/> + pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore*.*(..))"/> <aop:after-returning method="logAfter" - pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore.*(..))"/> + pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore*.*(..))"/> </aop:aspect> </aop:config>