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 2008/07/30 23:53:08 UTC
svn commit: r681215 - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/
rt/frontend/jaxrs/src/main/java/org/...
Author: sergeyb
Date: Wed Jul 30 14:53:07 2008
New Revision: 681215
URL: http://svn.apache.org/viewvc?rev=681215&view=rev
Log:
Various minor JAX-RS fixes
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt (with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
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/model/ClassResourceInfo.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.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/ProviderFactory.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Jul 30 14:53:07 2008
@@ -86,7 +86,7 @@
cri.getMethodDispatcher().getMethod(ori), resourceObject);
if (cri.isRoot()) {
- JAXRSUtils.handleSetters(cri, resourceObject,
+ JAXRSUtils.handleSetters(ori, resourceObject,
exchange.getInMessage());
InjectionUtils.injectContextFields(resourceObject,
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Wed Jul 30 14:53:07 2008
@@ -29,6 +29,7 @@
import javax.ws.rs.core.UriInfo;
import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Message;
@@ -43,7 +44,7 @@
}
public URI getAbsolutePath() {
- String address = getEndpointAddress();
+ String address = getBaseUri().toString();
address = address.endsWith("/") ? address.substring(0, address.length() - 1)
: address;
return URI.create(address + getPath());
@@ -54,7 +55,8 @@
}
public URI getBaseUri() {
- return URI.create(getEndpointAddress());
+ URI u = URI.create(getEndpointAddress());
+ return HttpUtils.toAbsoluteUri(u, message);
}
public UriBuilder getBaseUriBuilder() {
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=681215&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java Wed Jul 30 14:53:07 2008
@@ -0,0 +1,33 @@
+/**
+ * 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.impl;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class WebApplicationExceptionMapper
+ implements ExceptionMapper<WebApplicationException> {
+
+ public Response toResponse(WebApplicationException ex) {
+ return ex.getResponse();
+ }
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java Wed Jul 30 14:53:07 2008
@@ -23,6 +23,7 @@
import java.util.ResourceBundle;
import java.util.logging.Logger;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -120,7 +121,7 @@
BUNDLE,
path);
LOG.severe(errorMsg.toString());
- throw new Fault(errorMsg);
+ throw new WebApplicationException(404);
}
List<ProviderInfo<RequestHandler>> shs =
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=681215&r1=681214&r2=681215&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 Wed Jul 30 14:53:07 2008
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
@@ -73,21 +74,11 @@
@SuppressWarnings("unchecked")
private void processResponse(Message message) {
- Exchange exchange = message.getExchange();
- OperationResourceInfo operation = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
- .getName());
-
- if (operation == null) {
- return;
- }
-
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null || objs.size() == 0) {
return;
}
- OutputStream out = message.getContent(OutputStream.class);
-
if (objs.get(0) != null) {
Object responseObj = objs.get(0);
Response response = null;
@@ -97,6 +88,10 @@
response = Response.ok(responseObj).build();
}
+ Exchange exchange = message.getExchange();
+ OperationResourceInfo operation = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
+ .getName());
+
List<ProviderInfo<ResponseHandler>> handlers =
ProviderFactory.getInstance().getResponseHandlers();
for (ProviderInfo<ResponseHandler> rh : handlers) {
@@ -118,16 +113,15 @@
List<MediaType> availableContentTypes =
computeAvailableContentTypes(message, response);
- Method invoked = ((OperationResourceInfo)message.getExchange()
- .get(OperationResourceInfo.class)).getMethodToInvoke();
+ Method invoked = operation == null ? null : operation.getMethodToInvoke();
MessageBodyWriter writer = null;
MediaType responseType = null;
for (MediaType type : availableContentTypes) {
writer = ProviderFactory.getInstance()
.createMessageBodyWriter(targetType,
- invoked.getGenericReturnType(),
- invoked.getAnnotations(),
+ invoked != null ? invoked.getGenericReturnType() : null,
+ invoked != null ? invoked.getAnnotations() : new Annotation[]{},
type,
exchange.getInMessage());
@@ -136,12 +130,13 @@
break;
}
}
-
+
+ OutputStream out = message.getContent(OutputStream.class);
if (writer == null) {
message.put(Message.RESPONSE_CODE, 406);
writeResponseErrorMessage(out,
- "NO_MSG_WRITER",
- invoked.getReturnType().getSimpleName());
+ "NO_MSG_WRITER",
+ invoked != null ? invoked.getReturnType().getSimpleName() : "");
return;
}
@@ -153,7 +148,7 @@
LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
writer.writeTo(responseObj, targetType, invoked.getGenericReturnType(),
- invoked.getAnnotations(),
+ invoked != null ? invoked.getAnnotations() : new Annotation[]{},
responseType,
response.getMetadata(),
out);
@@ -191,15 +186,18 @@
response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);
Exchange exchange = message.getExchange();
List<MediaType> produceTypes = null;
+ OperationResourceInfo operation = exchange.get(OperationResourceInfo.class);
if (contentType != null) {
produceTypes = Collections.singletonList(MediaType.valueOf(contentType.toString()));
+ } else if (operation != null) {
+ produceTypes = operation.getProduceTypes();
} else {
- produceTypes = exchange.get(OperationResourceInfo.class).getProduceTypes();
+ produceTypes = Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM_TYPE);
}
List<MediaType> acceptContentTypes =
(List<MediaType>)exchange.get(Message.ACCEPT_CONTENT_TYPE);
- return JAXRSUtils.intersectMimeTypes(acceptContentTypes, produceTypes, true);
+ return JAXRSUtils.intersectMimeTypes(acceptContentTypes, produceTypes);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java Wed Jul 30 14:53:07 2008
@@ -27,7 +27,6 @@
import java.util.List;
import javax.ws.rs.ConsumeMime;
-import javax.ws.rs.Encoded;
import javax.ws.rs.Path;
import javax.ws.rs.ProduceMime;
@@ -143,11 +142,6 @@
return (ConsumeMime)AnnotationUtils.getClassAnnotation(getServiceClass(), ConsumeMime.class);
}
- public boolean isEncodedEnabled() {
- return AnnotationUtils.getClassAnnotation(getServiceClass(),
- Encoded.class) != null;
- }
-
public Path getPath() {
return (Path)AnnotationUtils.getClassAnnotation(getServiceClass(), Path.class);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java Wed Jul 30 14:53:07 2008
@@ -23,6 +23,8 @@
import java.util.List;
import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.Encoded;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.core.MediaType;
@@ -37,12 +39,16 @@
private String httpMethod;
private List<MediaType> produceMimes;
private List<MediaType> consumeMimes;
+ private boolean encoded;
+ private String defaultParamValue;
public OperationResourceInfo(Method m, ClassResourceInfo cri) {
methodToInvoke = m;
annotatedMethod = m;
classResourceInfo = cri;
checkMediaTypes();
+ checkEncoded();
+ checkDefaultParameterValue();
}
public URITemplate getURITemplate() {
@@ -120,4 +126,34 @@
JAXRSUtils.getProduceTypes(classResourceInfo.getProduceMime()));
}
}
+
+ public boolean isEncodedEnabled() {
+ return encoded;
+ }
+
+ public String getDefaultParameterValue() {
+ return defaultParamValue;
+ }
+
+ private void checkEncoded() {
+ encoded = AnnotationUtils.getMethodAnnotation(annotatedMethod,
+ Encoded.class) != null;
+ if (!encoded && classResourceInfo != null) {
+ encoded = AnnotationUtils.getClassAnnotation(classResourceInfo.getServiceClass(),
+ Encoded.class) != null;
+ }
+ }
+
+ private void checkDefaultParameterValue() {
+ DefaultValue dv = (DefaultValue)AnnotationUtils.getMethodAnnotation(annotatedMethod,
+ DefaultValue.class);
+ if (dv == null && classResourceInfo != null) {
+ dv = (DefaultValue)AnnotationUtils.getClassAnnotation(
+ classResourceInfo.getServiceClass(),
+ DefaultValue.class);
+ }
+ if (dv != null) {
+ defaultParamValue = dv.value();
+ }
+ }
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java Wed Jul 30 14:53:07 2008
@@ -35,26 +35,25 @@
// subresource method takes precedence over a subresource locator
return e1.getHttpMethod() != null ? -1 : 1;
}
-
+
+
String l1 = e1.getURITemplate().getLiteralChars();
String l2 = e2.getURITemplate().getLiteralChars();
if (!l1.equals(l2)) {
// descending order
return l1.length() < l2.length() ? 1 : -1;
}
-
- if (e1.getHttpMethod() == null && e2.getHttpMethod() == null) {
- // with two subresource locators, those with more capturing groups win
- int g1 = e1.getURITemplate().getNumberOfGroups();
- int g2 = e2.getURITemplate().getNumberOfGroups();
+
+ int g1 = e1.getURITemplate().getNumberOfGroups();
+ int g2 = e2.getURITemplate().getNumberOfGroups();
+ if (g1 != g2) {
// descending order
- return g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
+ return g1 < g2 ? 1 : -1;
}
List<MediaType> mimeType1 = e1.getConsumeTypes();
List<MediaType> mimeType2 = e2.getConsumeTypes();
- // TODO: we actually need to check all consume and produce types here ?
int result = JAXRSUtils.compareMediaTypes(mimeType1.get(0),
mimeType2.get(0));
if (result == 0) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java Wed Jul 30 14:53:07 2008
@@ -40,7 +40,8 @@
/**
* The regular expression for matching URI templates and names.
*/
- private static final Pattern TEMPLATE_NAMES_PATTERN = Pattern.compile("\\{([a-zA-Z0-9][-\\w.]*)\\}");
+ private static final Pattern TEMPLATE_NAMES_PATTERN =
+ Pattern.compile("\\{(\\w[-\\w\\.]*)\\}");
/**
* A URI template is converted into a regular expression by substituting
@@ -51,20 +52,16 @@
private static final String PATH_UNLIMITED_VARIABLE_REGEX = "(.*?)";
private final String template;
- private final boolean limited;
- private final boolean encoded;
private final List<String> templateVariables;
private final Pattern templateRegexPattern;
private final String literals;
public URITemplate(String theTemplate) {
- this(theTemplate, true, false);
+ this(theTemplate, true);
}
- public URITemplate(String theTemplate, boolean limited, boolean encoded) {
+ public URITemplate(String theTemplate, boolean limited) {
this.template = theTemplate;
- this.limited = limited;
- this.encoded = encoded;
StringBuilder literalChars = new StringBuilder();
StringBuilder stringBuilder = new StringBuilder();
@@ -101,14 +98,6 @@
templateRegexPattern = Pattern.compile(stringBuilder.toString());
}
- public boolean isLimited() {
- return limited;
- }
-
- public boolean encode() {
- return encoded;
- }
-
public String getLiteralChars() {
return literals;
}
@@ -175,6 +164,6 @@
pathValue = "/" + pathValue;
}
- return new URITemplate(pathValue, path.limited(), path.encode());
+ return new URITemplate(pathValue, path.limited());
}
}
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=681215&r1=681214&r2=681215&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 Wed Jul 30 14:53:07 2008
@@ -77,6 +77,14 @@
return context;
}
}
+
+ synchronized (classContexts) {
+ JAXBContext context = classContexts.get(type);
+ if (context != null) {
+ return context;
+ }
+ }
+
JAXBContext context = getPackageContext(type);
if (context == null && type != genericType) {
context = getPackageContext(InjectionUtils.getActualType(genericType));
@@ -109,7 +117,7 @@
packageContexts.put(packageName, context);
return context;
} catch (JAXBException ex) {
- LOG.warning("Error creating a JAXBContext using ObjectFactory : "
+ LOG.fine("Error creating a JAXBContext using ObjectFactory : "
+ ex.getMessage());
return null;
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Wed Jul 30 14:53:07 2008
@@ -39,6 +39,7 @@
import org.apache.cxf.jaxrs.ext.RequestHandler;
import org.apache.cxf.jaxrs.ext.ResponseHandler;
import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
+import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
import org.apache.cxf.jaxrs.model.ProviderInfo;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -82,6 +83,7 @@
new SourceProvider(),
new FormEncodingReaderProvider(),
new PrimitiveTextProvider(),
+ new WebApplicationExceptionMapper(),
new MappingsHandler());
}
@@ -120,7 +122,7 @@
ParameterizedType pt = (ParameterizedType)t;
Type[] args = pt.getActualTypeArguments();
for (int i = 0; i < args.length; i++) {
- if (exceptionType.isAssignableFrom((Class<?>)args[i])) {
+ if (((Class<?>)args[i]).isAssignableFrom(exceptionType)) {
InjectionUtils.injectContextFields(em.getProvider(), em, m);
InjectionUtils.injectContextMethods(em.getProvider(), em, m);
return em.getProvider();
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java Wed Jul 30 14:53:07 2008
@@ -29,6 +29,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.CookieParam;
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.Encoded;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
@@ -44,7 +45,7 @@
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.MessageBodyWorkers;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
public final class AnnotationUtils {
@@ -220,13 +221,28 @@
return null;
}
- public static boolean isEncoded(Annotation[] anns, ClassResourceInfo cri) {
- if (cri == null) {
+ public static boolean isEncoded(Annotation[] anns, OperationResourceInfo ori) {
+
+ if (AnnotationUtils.getAnnotation(anns, Encoded.class) != null) {
+ return true;
+ }
+
+ if (ori == null) {
return false;
}
- if (cri.isEncodedEnabled()) {
- return true;
+ return ori.isEncodedEnabled();
+ }
+
+ public static String getDefaultParameterValue(Annotation[] anns, OperationResourceInfo ori) {
+
+ DefaultValue dv = AnnotationUtils.getAnnotation(anns, DefaultValue.class);
+ if (dv != null) {
+ return dv.value();
+ }
+
+ if (ori == null) {
+ return null;
}
- return AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
+ return ori.getDefaultParameterValue();
}
}
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=681215&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Wed Jul 30 14:53:07 2008
@@ -0,0 +1,54 @@
+/**
+ * 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.utils;
+
+import java.net.URI;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+
+public final class HttpUtils {
+
+ private static final String LOCAL_IP_ADDRESS = "127.0.0.1";
+ private static final String LOCAL_HOST = "localhost";
+
+
+ private HttpUtils() {
+ }
+
+ public static URI toAbsoluteUri(URI u, Message message) {
+ if (!u.isAbsolute()) {
+ HttpServletRequest httpRequest =
+ (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
+ if (httpRequest != null) {
+ String scheme = httpRequest.isSecure() ? "https" : "http";
+ String host = httpRequest.getLocalName();
+ if (LOCAL_IP_ADDRESS.equals(host)) {
+ host = LOCAL_HOST;
+ }
+ int port = httpRequest.getLocalPort();
+ return URI.create(scheme + "://" + host + ':' + port + u.toString());
+ }
+ }
+ return u;
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
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=681215&r1=681214&r2=681215&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 Wed Jul 30 14:53:07 2008
@@ -244,7 +244,12 @@
if (defaultValue != null) {
paramValues = Collections.singletonList(defaultValue);
} else {
- return null;
+ if (paramType.isPrimitive()) {
+ paramValues = Collections.singletonList(
+ boolean.class == paramType ? "false" : "0");
+ } else {
+ return null;
+ }
}
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Wed Jul 30 14:53:07 2008
@@ -47,7 +47,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.CookieParam;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
@@ -129,9 +128,10 @@
@SuppressWarnings("unchecked")
- public static void handleSetters(ClassResourceInfo cri,
+ public static void handleSetters(OperationResourceInfo ori,
Object requestObject,
Message message) {
+ ClassResourceInfo cri = ori.getClassResourceInfo();
InjectionUtils.injectContextMethods(requestObject, cri, message);
// Param methods
String relativePath = (String)message.get(JAXRSInInterceptor.RELATIVE_PATH);
@@ -144,7 +144,7 @@
message,
values,
relativePath,
- cri);
+ ori);
if (o != null) {
InjectionUtils.injectThroughMethod(requestObject, m, o);
}
@@ -157,7 +157,7 @@
message,
values,
relativePath,
- cri);
+ ori);
if (o != null) {
InjectionUtils.injectFieldValue(f, requestObject, o);
}
@@ -254,6 +254,8 @@
return null;
}
+
+
public static List<MediaType> getConsumeTypes(ConsumeMime cm) {
return cm == null ? Collections.singletonList(ALL_TYPES)
: getMediaTypes(cm.value());
@@ -370,7 +372,7 @@
message,
values,
path,
- ori.getClassResourceInfo());
+ ori);
}
}
@@ -380,19 +382,17 @@
Message message,
MultivaluedMap<String, String> values,
String path,
- ClassResourceInfo cri) {
+ OperationResourceInfo ori) {
- boolean isEncoded = AnnotationUtils.isEncoded(anns, cri);
+ boolean isEncoded = AnnotationUtils.isEncoded(anns, ori);
+ String defaultValue = AnnotationUtils.getDefaultParameterValue(anns, ori);
PathParam pathParam = AnnotationUtils.getAnnotation(anns, PathParam.class);
if (pathParam != null) {
return readFromUriParam(pathParam, parameterClass, genericParam, path,
- values, !isEncoded);
+ values, defaultValue, !isEncoded);
}
- DefaultValue defaultAnn = AnnotationUtils.getAnnotation(anns, DefaultValue.class);
- String defaultValue = defaultAnn != null ? defaultAnn.value() : null;
-
QueryParam qp = AnnotationUtils.getAnnotation(anns, QueryParam.class);
if (qp != null) {
return readQueryString(qp, parameterClass, genericParam, message,
@@ -540,6 +540,7 @@
Type genericType,
String path,
MultivaluedMap<String, String> values,
+ String defaultValue,
boolean decoded) {
String parameterName = uriParamAnnotation.value();
if ("".equals(parameterName)) {
@@ -549,7 +550,7 @@
return InjectionUtils.createParameterObject(results,
paramType,
genericType,
- null,
+ defaultValue,
true,
decoded);
}
@@ -701,7 +702,7 @@
* @param mimeTypesB
* @return return a list of intersected mime types
*/
- private static List<MediaType> doIntersectMimeTypes(List<MediaType> requiredMediaTypes,
+ public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes,
List<MediaType> userMediaTypes) {
Set<MediaType> supportedMimeTypeList = new LinkedHashSet<MediaType>();
@@ -709,8 +710,8 @@
for (MediaType userType : userMediaTypes) {
if (requiredType.isCompatible(userType) || userType.isCompatible(requiredType)) {
- for (Map.Entry<String, String> entry : requiredType.getParameters().entrySet()) {
- String value = userType.getParameters().get(entry.getKey());
+ for (Map.Entry<String, String> entry : userType.getParameters().entrySet()) {
+ String value = requiredType.getParameters().get(entry.getKey());
if (value != null && !value.equals(entry.getValue())) {
continue;
}
@@ -720,7 +721,7 @@
? userType.getType() : requiredType.getType();
String subtype = requiredType.getSubtype().equals(MediaType.MEDIA_TYPE_WILDCARD)
? userType.getSubtype() : requiredType.getSubtype();
- supportedMimeTypeList.add(new MediaType(type, subtype, requiredType.getParameters()));
+ supportedMimeTypeList.add(new MediaType(type, subtype, userType.getParameters()));
}
}
}
@@ -729,18 +730,6 @@
}
- public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes,
- List<MediaType> userMediaTypes,
- boolean userTypes) {
- return userTypes ? doIntersectMimeTypes(userMediaTypes, requiredMediaTypes)
- : doIntersectMimeTypes(requiredMediaTypes, userMediaTypes);
- }
-
- public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes,
- List<MediaType> userMediaTypes) {
- return intersectMimeTypes(requiredMediaTypes, userMediaTypes, false);
- }
-
public static List<MediaType> intersectMimeTypes(List<MediaType> mimeTypesA,
MediaType mimeTypeB) {
return intersectMimeTypes(mimeTypesA,
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java Wed Jul 30 14:53:07 2008
@@ -42,12 +42,12 @@
List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
- String acceptContentTypes = "*/*";
+ String acceptContentTypes = "application/xml";
//If acceptContentTypes does not specify a specific Mime type, the
//method is declared with a most specific ProduceMime type is selected.
MetadataMap<String, String> values = new MetadataMap<String, String>();
- ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/", values);
+ ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d", values);
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
values.getFirst(URITemplate.FINAL_MATCH_GROUP),
"GET", values, contentTypes,
@@ -56,5 +56,59 @@
assertEquals("listMethod needs to be selected", "listMethod",
ori.getMethodToInvoke().getName());
+
+ acceptContentTypes = "*/*";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
+ assertNotNull(ori);
+ assertEquals("listMethod needs to be selected", "unlimitedPath",
+ ori.getMethodToInvoke().getName());
+
+
+ contentTypes = "application/xml";
+ acceptContentTypes = "application/xml";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
+ assertNotNull(ori);
+ assertEquals("listMethod needs to be selected", "readMethod",
+ ori.getMethodToInvoke().getName());
+
+ contentTypes = "application/json";
+ acceptContentTypes = "application/json";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/bar/baz/baz", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
+ assertNotNull(ori);
+ assertEquals("listMethod needs to be selected", "readMethod2",
+ ori.getMethodToInvoke().getName());
+
+ contentTypes = "application/json";
+ acceptContentTypes = "application/json";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
+ assertNotNull(ori);
+ assertEquals("listMethod needs to be selected", "unlimitedPath",
+ ori.getMethodToInvoke().getName());
+
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/2", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
+ assertNotNull(ori);
+ assertEquals("listMethod needs to be selected", "limitedPath",
+ ori.getMethodToInvoke().getName());
+
}
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java Wed Jul 30 14:53:07 2008
@@ -122,7 +122,7 @@
// with suffix
values.clear();
- new URITemplate("/bar", false, false).match("/bar", values);
+ new URITemplate("/bar", false).match("/bar", values);
u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
values);
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java Wed Jul 30 14:53:07 2008
@@ -36,7 +36,7 @@
@Test
public void testMatchBasic() throws Exception {
URITemplate uriTemplate = new URITemplate("/customers/{id}",
- false, false);
+ false);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/customers/123/", values);
@@ -48,7 +48,7 @@
@Test
public void testMatchBasicTwoParametersVariation1() throws Exception {
URITemplate uriTemplate = new URITemplate("/customers/{name}/{department}",
- false, false);
+ false);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/customers/john/CS", values);
@@ -62,7 +62,7 @@
@Test
public void testMatchBasicTwoParametersVariation2() throws Exception {
URITemplate uriTemplate = new URITemplate("/customers/name/{name}/dep/{department}",
- false, false);
+ false);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/customers/name/john/dep/CS", values);
@@ -76,7 +76,7 @@
@Test
public void testURITemplateWithSubResource() throws Exception {
//So "/customers" is the URITemplate for the root resource class
- URITemplate uriTemplate = new URITemplate("/customers", true, false);
+ URITemplate uriTemplate = new URITemplate("/customers", true);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/customers/123", values);
@@ -88,7 +88,7 @@
@Test
public void testURITemplateWithSubResourceVariation2() throws Exception {
//So "/customers" is the URITemplate for the root resource class
- URITemplate uriTemplate = new URITemplate("/customers", true, false);
+ URITemplate uriTemplate = new URITemplate("/customers", true);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/customers/name/john/dep/CS", values);
@@ -103,7 +103,7 @@
* public Book getBook(@UriParam("bookId") String id)
*/
public void testURITemplateWithSubResourceVariation3() throws Exception {
- URITemplate uriTemplate = new URITemplate("/books/{bookId}/", true, false);
+ URITemplate uriTemplate = new URITemplate("/books/{bookId}/", true);
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
boolean match = uriTemplate.match("/books/123/chapter/1", values);
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java Wed Jul 30 14:53:07 2008
@@ -22,6 +22,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.ProduceMime;
@Path("/{a}/{b}/{c}/d")
public class TestResource {
@@ -29,17 +30,41 @@
public TestResource() {
}
+
+
@GET
@Path("/")
+ @ProduceMime("application/xml")
public String listMethod() {
return "This is a list method";
}
-
+
@GET
@Path("/{e}")
+ @ProduceMime("application/xml")
public String readMethod() {
return "This is a list method";
}
+
+ @GET
+ @Path("/{a}/{b}")
+ public String limitedPath() {
+ return "This is a list method";
+ }
+
+ @GET
+ @Path(value = "/{e}", limited = false)
+ @ProduceMime("application/json")
+ public String unlimitedPath() {
+ return "This is a list method";
+ }
+
+ @GET
+ @Path("/{e}/bar/baz/baz")
+ @ProduceMime("application/json")
+ public String readMethod2() {
+ return "This is a list method";
+ }
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Wed Jul 30 14:53:07 2008
@@ -699,7 +699,11 @@
cri.setResourceProvider(new SingletonResourceProvider(c));
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
- JAXRSUtils.handleSetters(cri, c, new MessageImpl());
+ OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
+ cri);
+
+
+ JAXRSUtils.handleSetters(ori, c, new MessageImpl());
assertNotNull(c.getUriInfo());
assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
assertSame(UriInfoImpl.class,
@@ -711,9 +715,11 @@
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
+ OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
+ cri);
Message m = new MessageImpl();
m.put(Message.QUERY_STRING, "a=aValue&query2=b");
- JAXRSUtils.handleSetters(cri, c, m);
+ JAXRSUtils.handleSetters(ori, c, m);
assertEquals("aValue", c.getQueryParam());
}
@@ -723,9 +729,11 @@
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
+ OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
+ cri);
Message m = new MessageImpl();
m.put(Message.QUERY_STRING, "b=bValue");
- JAXRSUtils.handleSetters(cri, c, m);
+ JAXRSUtils.handleSetters(ori, c, m);
assertEquals("bValue", c.getB());
}
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java Wed Jul 30 14:53:07 2008
@@ -68,6 +68,14 @@
}
@GET
+ @Path("/books/jsonfeed")
+ @ProduceMime({"application/xml", "application/json", "text/html", "application/atom+xml" })
+ public Feed getBooksAsJsonFeed(@Context UriInfo uParam) {
+ return getBooksAsFeed(uParam);
+ }
+
+
+ @GET
@Path("/books/feed")
@ProduceMime({"application/json", "application/atom+xml" })
public Feed getBooksAsFeed(@Context UriInfo uParam) {
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java Wed Jul 30 14:53:07 2008
@@ -56,13 +56,20 @@
String endpointAddress =
"http://localhost:9080/bookstore/books/feed";
Feed feed = getFeed(endpointAddress, null);
- assertEquals("/bookstore/books/feed", feed.getBaseUri().toString());
+ assertEquals("http://localhost:9080/bookstore/books/feed",
+ feed.getBaseUri().toString());
assertEquals("Collection of Books", feed.getTitle());
getAndCompareJson("http://localhost:9080/bookstore/books/feed",
"resources/expected_atom_books_json.txt",
"application/json");
+ getAndCompareJson("http://localhost:9080/bookstore/books/jsonfeed",
+ "resources/expected_atom_books_jsonfeed.txt",
+ "application/json, text/html, application/xml;q=0.9,"
+ + " application/xhtml+xml, image/png, image/jpeg, image/gif,"
+ + " image/x-xbitmap, */*;q=0.1");
+
Entry e = createBookEntry(256, "AtomBook");
StringWriter w = new StringWriter();
e.writeTo(w);
@@ -83,7 +90,7 @@
post.releaseConnection();
}
- Entry entry = getEntry("http://localhost:9080" + location, null);
+ Entry entry = getEntry(location, null);
assertEquals(location, entry.getBaseUri().toString());
assertEquals("AtomBook", entry.getTitle());
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Wed Jul 30 14:53:07 2008
@@ -85,8 +85,8 @@
@GET
@Path("/books/query")
- public Book getBookQuery(@QueryParam("bookId") String id) throws BookNotFoundFault {
- return doGetBook(id);
+ public Book getBookQuery(@QueryParam("bookId") long id) throws BookNotFoundFault {
+ return doGetBook(Long.toString(id));
}
@GET
@@ -97,6 +97,16 @@
}
@GET
+ @Path("/books/missingquery")
+ public Book getBookMissingQuery(@QueryParam("bookId") long id)
+ throws BookNotFoundFault {
+ if (id != 0) {
+ throw new RuntimeException();
+ }
+ return doGetBook("123");
+ }
+
+ @GET
@Path("/books/element")
public JAXBElement<Book> getBookElement() throws Exception {
return new JAXBElement<Book>(new QName("", "Book"),
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Wed Jul 30 14:53:07 2008
@@ -41,7 +41,7 @@
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServer.class));
+ launchServer(BookServer.class, true));
}
@Test
@@ -52,6 +52,14 @@
}
@Test
+ public void testNoRootResourceException() throws Exception {
+ getAndCompare("http://localhost:9080/nobookstore/webappexception",
+ "",
+ "application/xml", 404);
+ }
+
+
+ @Test
public void testAcceptTypeMismatch() throws Exception {
// TODO : more specific message is needed
String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
@@ -145,6 +153,10 @@
"resources/expected_get_book123.txt",
"application/xml", 200);
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/missingquery",
+ "resources/expected_get_book123.txt",
+ "application/xml", 200);
+
getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
"resources/expected_get_book123json.txt",
"application/xml,application/json", 200);
@@ -552,9 +564,9 @@
try {
int result = httpClient.executeMethod(get);
assertEquals(expectedStatus, result);
- String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
+ String content = getStringFromInputStream(get.getResponseBodyAsStream());
assertEquals("Expected value is wrong",
- expectedValue, jsonContent);
+ expectedValue, content);
} finally {
get.releaseConnection();
}
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt Wed Jul 30 14:53:07 2008
@@ -9,6 +9,6 @@
]
},
"attributes":{
- "xml:base":"/bookstore/books/entries/123"
+ "xml:base":"http://localhost:9080/bookstore/books/entries/123"
}
}
\ No newline at end of file
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt?rev=681215&r1=681214&r2=681215&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt Wed Jul 30 14:53:07 2008
@@ -18,7 +18,7 @@
}
],
"attributes":{
- "xml:base":"/bookstore/books/feed"
+ "xml:base":"http://localhost:9080/bookstore/books/feed"
}
}
Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt?rev=681215&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt Wed Jul 30 14:53:07 2008
@@ -0,0 +1,24 @@
+{
+ "id":"http://www.books.com",
+ "title":"Collection of Books",
+ "authors":[{
+ "name":"BookStore Management Company"
+ }
+ ],
+ "entries":[{
+ "id":"123",
+ "title":"CXF in Action",
+ "content":{
+ "attributes":{
+ "type":"application/xml"
+ },
+ "children":["<Book><id>123<\/id><name>CXF in Action<\/name><\/Book>"
+ ]
+ }
+ }
+ ],
+ "attributes":{
+ "xml:base":"http://localhost:9080/bookstore/books/jsonfeed"
+ }
+}
+
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_jsonfeed.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain