Author: dkulp
Date: Tue Feb 5 18:44:08 2008
New Revision: 618857
URL: http://svn.apache.org/viewvc?rev=618857&view=rev
Log:
Merged revisions 615303 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r615303 | dkulp | 2008-01-25 13:37:58 -0500 (Fri, 25 Jan 2008) | 6 lines
[CXF-1405] Move setting up the incoming message into AbstractHTTPDestination
so that jetty and servlet should always be consistent.
Update JAXRS to properly parse the Accept header
Fix a BUNCH of JAXRS tests that were not setting an Accept header so were now
getting the default */* on the server side and getting json back.
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
Tue Feb 5 18:44:08 2008
@@ -50,7 +50,8 @@
String MTOM_ENABLED = "mtom-enabled";
String SCHEMA_VALIDATION_ENABLED = "schema-validation-enabled";
String FAULT_STACKTRACE_ENABLED = "faultStackTraceEnabled";
- String CONTENT_TYPE = "Content-Type";
+ String CONTENT_TYPE = "Content-Type";
+ String ACCEPT_CONTENT_TYPE = "Accept";
String BASE_PATH = Message.class.getName() + ".BASE_PATH";
String ENCODING = Message.class.getName() + ".ENCODING";
String FIXED_PARAMETER_ORDER = Message.class.getName() +
"FIXED_PARAMETER_ORDER";
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Tue Feb 5 18:44:08 2008
@@ -19,11 +19,9 @@
package org.apache.cxf.transport.http_jetty;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;
-import java.security.Principal;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -34,17 +32,12 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.security.SecurityContext;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.ConduitInitiator;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.HTTPSession;
-import org.apache.cxf.transport.https.SSLUtils;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
import org.apache.cxf.transports.http.StemMatchingQueryHandler;
@@ -172,7 +165,7 @@
return conduitInitiator;
}
- private String getBasePath(String addr) {
+ protected String getBasePathForFullAddress(String addr) {
try {
return new URL(addr).getPath();
} catch (MalformedURLException e) {
@@ -193,7 +186,8 @@
// only update the EndpointAddress if the base path is equal
// make sure we don't broke the get operation?parament query
String address = removeTrailingSeparator(endpointInfo.getAddress());
- if
(getBasePath(address).equals(removeTrailingSeparator(getStem(getBasePath(addr)))))
{
+ if (getBasePathForFullAddress(address)
+
.equals(removeTrailingSeparator(getStem(getBasePathForFullAddress(addr))))) {
endpointInfo.setAddress(addr);
}
return address;
@@ -273,40 +267,9 @@
}
MessageImpl inMessage = new MessageImpl();
- inMessage.setContent(InputStream.class, req.getInputStream());
- inMessage.put(HTTP_REQUEST, req);
- inMessage.put(HTTP_RESPONSE, resp);
- inMessage.put(HTTP_CONTEXT, context);
- inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
- inMessage.put(Message.PATH_INFO, req.getContextPath() +
req.getPathInfo());
- String normalizedEncoding =
HttpHeaderHelper.mapCharset(req.getCharacterEncoding());
- if (normalizedEncoding == null) {
- String m = new
org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
- LOG,
req.getCharacterEncoding()).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- }
- inMessage.put(Message.ENCODING, normalizedEncoding);
- inMessage.put(Message.QUERY_STRING, req.getQueryString());
- inMessage.put(Message.CONTENT_TYPE, req.getContentType());
- if (!StringUtils.isEmpty(endpointInfo.getAddress())) {
- inMessage.put(Message.BASE_PATH, new
URL(endpointInfo.getAddress()).getPath());
- }
- inMessage.put(Message.FIXED_PARAMETER_ORDER,
isFixedParameterOrder());
- inMessage.put(Message.ASYNC_POST_RESPONSE_DISPATCH, Boolean.TRUE);
- inMessage.put(SecurityContext.class, new SecurityContext() {
- public Principal getUserPrincipal() {
- return req.getUserPrincipal();
- }
- public boolean isUserInRole(String role) {
- return req.isUserInRole(role);
- }
- });
+ setupMessage(inMessage, context, req, resp);
- setHeaders(inMessage);
inMessage.setDestination(this);
-
- SSLUtils.propogateSecureSession(req, inMessage);
ExchangeImpl exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Tue Feb 5 18:44:08 2008
@@ -20,9 +20,12 @@
package org.apache.cxf.transport.http;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.ServerSocket;
+import java.net.URL;
+import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@@ -33,6 +36,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
@@ -49,12 +53,14 @@
import org.apache.cxf.io.AbstractWrappedOutputStream;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
+import org.apache.cxf.security.SecurityContext;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.AbstractDestination;
import org.apache.cxf.transport.AbstractMultiplexDestination;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.transport.ConduitInitiator;
import org.apache.cxf.transport.http.policy.PolicyUtils;
+import org.apache.cxf.transport.https.SSLUtils;
import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.apache.cxf.ws.policy.Assertor;
@@ -225,6 +231,68 @@
} else {
response.setContentType(ct);
}
+ }
+
+ protected void setupMessage(Message inMessage,
+ final ServletContext context,
+ final HttpServletRequest req,
+ final HttpServletResponse resp) throws
IOException {
+
+ inMessage.setContent(InputStream.class, req.getInputStream());
+ inMessage.put(HTTP_REQUEST, req);
+ inMessage.put(HTTP_RESPONSE, resp);
+ inMessage.put(HTTP_CONTEXT, context);
+ inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
+ String contextPath = req.getContextPath();
+ if (contextPath == null) {
+ contextPath = "";
+ }
+ inMessage.put(Message.PATH_INFO, contextPath + req.getPathInfo());
+
+ // work around a bug with Jetty which results in the character
+ // encoding not being trimmed correctly.
+ String enc = req.getCharacterEncoding();
+ if (enc != null && enc.endsWith("\"")) {
+ enc = enc.substring(0, enc.length() - 1);
+ }
+ String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
+ if (normalizedEncoding == null) {
+ String m = new
org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
+ LOG,
enc).toString();
+ LOG.log(Level.WARNING, m);
+ throw new IOException(m);
+ }
+
+ inMessage.put(Message.ENCODING, normalizedEncoding);
+
+ inMessage.put(Message.QUERY_STRING, req.getQueryString());
+ inMessage.put(Message.CONTENT_TYPE, req.getContentType());
+ inMessage.put(Message.ACCEPT_CONTENT_TYPE, req.getHeader("Accept"));
+ String basePath = getBasePath(contextPath);
+ if (!StringUtils.isEmpty(basePath)) {
+ inMessage.put(Message.BASE_PATH, basePath);
+ }
+ inMessage.put(Message.FIXED_PARAMETER_ORDER, isFixedParameterOrder());
+ inMessage.put(Message.ASYNC_POST_RESPONSE_DISPATCH, Boolean.TRUE);
+ inMessage.put(SecurityContext.class, new SecurityContext() {
+ public Principal getUserPrincipal() {
+ return req.getUserPrincipal();
+ }
+ public boolean isUserInRole(String role) {
+ return req.isUserInRole(role);
+ }
+ });
+
+ setHeaders(inMessage);
+
+ SSLUtils.propogateSecureSession(req, inMessage);
+ }
+
+ protected String getBasePath(String contextPath) throws IOException {
+ if (StringUtils.isEmpty(endpointInfo.getAddress())) {
+ return "";
+ }
+ return new URL(endpointInfo.getAddress()).getPath();
}
protected static EndpointInfo getAddressValue(EndpointInfo ei) {
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
Tue Feb 5 18:44:08 2008
@@ -23,3 +23,4 @@
NULL_RESPONSE_MSG = Response object is null
DECOUPLED_RESPONSE_FAILED_MSG = Decouple response failed
MISSING_PATH_INFO = PATH_INFO not present in message context, multiplex id is
unavailable. Ensure the portName passed to getCurrentEndpointReferenceId is
correct if the service has multiple ports
+INVALID_ENCODING_MSG = Invalid character set {0} in request.
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Tue Feb 5 18:44:08 2008
@@ -19,9 +19,7 @@
package org.apache.cxf.transport.servlet;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
-import java.security.Principal;
import java.util.Collection;
import java.util.Set;
import java.util.logging.Level;
@@ -34,15 +32,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.security.SecurityContext;
import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-import org.apache.cxf.transport.http.HTTPSession;
-import org.apache.cxf.transport.https.SSLUtils;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
import org.xmlsoap.schemas.wsdl.http.AddressType;
@@ -220,50 +210,13 @@
}
try {
- MessageImpl inMessage = new MessageImpl();
- inMessage.setContent(InputStream.class, request.getInputStream());
- inMessage.put(AbstractHTTPDestination.HTTP_REQUEST, request);
- inMessage.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
- inMessage.put(AbstractHTTPDestination.HTTP_CONTEXT,
cxfServlet.getServletContext());
- inMessage.put(Message.HTTP_REQUEST_METHOD, request.getMethod());
- inMessage.put(Message.PATH_INFO, request.getPathInfo());
- inMessage.put(Message.QUERY_STRING, request.getQueryString());
- inMessage.put(Message.CONTENT_TYPE, request.getContentType());
- inMessage.put(Message.BASE_PATH,
d.getAddress().getAddress().getValue());
- inMessage.put(SecurityContext.class, new SecurityContext() {
- public Principal getUserPrincipal() {
- return request.getUserPrincipal();
- }
- public boolean isUserInRole(String role) {
- return request.isUserInRole(role);
- }
- });
-
- // work around a bug with Jetty which results in the character
- // encoding not being trimmed correctly.
- String enc = request.getCharacterEncoding();
- if (enc != null && enc.endsWith("\"")) {
- enc = enc.substring(0, enc.length() - 1);
- }
-
- String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
- if (normalizedEncoding == null) {
- String m = new
org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
- LOG,
enc).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- }
-
- inMessage.put(Message.ENCODING, normalizedEncoding);
- SSLUtils.propogateSecureSession(request, inMessage);
-
- ExchangeImpl exchange = new ExchangeImpl();
- exchange.setInMessage(inMessage);
- exchange.setSession(new HTTPSession(request));
-
- d.doMessage(inMessage);
+ d.invoke(cxfServlet.getServletContext(), request, response);
} catch (IOException e) {
throw new ServletException(e);
+ } finally {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Finished servicing http request on thread: " +
Thread.currentThread());
+ }
}
}
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?rev=618857&r1=618856&r2=618857&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
Tue Feb 5 18:44:08 2008
@@ -20,17 +20,22 @@
package org.apache.cxf.transport.servlet;
import java.io.IOException;
-import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.ConduitInitiator;
import org.apache.cxf.transport.MessageObserver;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.HTTPSession;
public class ServletDestination extends AbstractHTTPDestination {
@@ -69,20 +74,26 @@
}
- protected void doMessage(MessageImpl inMessage) throws IOException {
- try {
-
- setHeaders(inMessage);
-
- inMessage.setDestination(this);
-
- incomingObserver.onMessage(inMessage);
-
- } finally {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Finished servicing http request on thread: " +
Thread.currentThread());
- }
- }
+ public void invoke(final ServletContext context,
+ final HttpServletRequest req,
+ final HttpServletResponse resp) throws IOException {
+
+ MessageImpl inMessage = new MessageImpl();
+ setupMessage(inMessage,
+ context,
+ req,
+ resp);
+
+ ExchangeImpl exchange = new ExchangeImpl();
+ exchange.setInMessage(inMessage);
+ exchange.setSession(new HTTPSession(req));
+ inMessage.setDestination(this);
+
+ incomingObserver.onMessage(inMessage);
+
+ }
+ protected String getBasePath(String contextPath) throws IOException {
+ return contextPath + getAddress().getAddress().getValue();
}
@Override