Let's go back to Metro 2.1.x

master
David BRASSELY 2013-11-15 16:02:11 +01:00
parent 23e068829a
commit 4d0d8e3f47
1 changed files with 139 additions and 124 deletions

View File

@ -27,6 +27,7 @@
* *
* END_HEADER - DO NOT EDIT * END_HEADER - DO NOT EDIT
*/ */
package com.sun.jbi.httpsoapbc.embedded; package com.sun.jbi.httpsoapbc.embedded;
import com.sun.jbi.internationalization.Messages; import com.sun.jbi.internationalization.Messages;
@ -36,7 +37,6 @@ import com.sun.xml.ws.api.message.Packet;
import com.sun.xml.ws.api.server.WSEndpoint; import com.sun.xml.ws.api.server.WSEndpoint;
import com.sun.xml.ws.api.server.WebServiceContextDelegate; import com.sun.xml.ws.api.server.WebServiceContextDelegate;
import com.sun.xml.ws.transport.http.WSHTTPConnection; import com.sun.xml.ws.transport.http.WSHTTPConnection;
import org.jvnet.ws.message.PropertySet.Property;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -49,7 +49,6 @@ import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -63,15 +62,16 @@ import org.apache.coyote.tomcat5.CoyoteResponse;
import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.http.MimeHeaders;
/** /**
* Based on JAX-WS WSHTTPConnection used with Java SE endpoints. It provides * Based on JAX-WS WSHTTPConnection used with Java SE endpoints. It provides connection
* connection implementation using Grizzly. * implementation using Grizzly.
*/ */
public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implements WebServiceContextDelegate { public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implements WebServiceContextDelegate {
private static final Messages mMessages = private static final Messages mMessages =
Messages.getMessages(JAXWSGrizzlyHttpConnection.class); Messages.getMessages(JAXWSGrizzlyHttpConnection.class);
private final static Logger mLogger = private final static Logger mLogger =
Messages.getLogger(JAXWSGrizzlyHttpConnection.class); Messages.getLogger(JAXWSGrizzlyHttpConnection.class);
//private final HttpExchange httpExchange; //private final HttpExchange httpExchange;
private Request req; private Request req;
private Response res; private Response res;
@ -80,14 +80,14 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
private int status; private int status;
private int responseContentLength = 0; private int responseContentLength = 0;
private Subject basicAuthSubject; private Subject basicAuthSubject;
private boolean outputWritten; private boolean outputWritten;
private boolean isSecure; private boolean isSecure;
private AsyncTask grizzlyAsyncTask;
private Map<String, List<String>> requestHeaders;
private Map<String, List<String>> responseHeaders;
public JAXWSGrizzlyHttpConnection(@NotNull Request request, @NotNull Response response, @NotNull CoyoteRequest coyoteRequest, private AsyncTask grizzlyAsyncTask;
@NotNull CoyoteResponse coyoteResponse, AsyncTask grizzlyAsyncTask, boolean isSecure) {
public JAXWSGrizzlyHttpConnection(@NotNull Request request, @NotNull Response response, @NotNull CoyoteRequest coyoteRequest,
@NotNull CoyoteResponse coyoteResponse, AsyncTask grizzlyAsyncTask, boolean isSecure) {
this.req = request; this.req = request;
this.res = response; this.res = response;
this.coyoteRequest = coyoteRequest; this.coyoteRequest = coyoteRequest;
@ -97,14 +97,11 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property({MessageContext.HTTP_REQUEST_HEADERS, Packet.INBOUND_TRANSPORT_HEADERS}) @Property({MessageContext.HTTP_REQUEST_HEADERS, Packet.INBOUND_TRANSPORT_HEADERS})
public @NotNull public @NotNull Map<String,List<String>> getRequestHeaders() {
Map<String, List<String>> getRequestHeaders() { MimeHeaders mimeHeaders = req.getMimeHeaders();
if (requestHeaders == null) { Map<String, List<String>> jaxWSHeaders = convertHeaders(mimeHeaders);
requestHeaders = initializeRequestHeaders(); return jaxWSHeaders;
}
return requestHeaders;
} }
@Override @Override
@ -112,41 +109,70 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
return req.getHeader(headerName); return req.getHeader(headerName);
} }
@Override
public void setResponseHeaders(Map<String, List<String>> headers) { /**
this.responseHeaders = headers; * there seems to issue with metro implementation while creating soap 1.2
if (headers == null) { * mime headers, for the content-type mime header it does not propagate
return; * the exact value for the content-type mime header, specially in this case
* though the http-request contents the value of the action in the content
} * type , the same value is not propagated from the http transport layer to
if (status != 0) { * the soap message layer
res.setStatus(status); *
} * this is a work around which is used to pass on the action value if
* present in the content-type , this code needs to removed once we have the
res.reset(); // clear all the headers * metro fix
*
for (Map.Entry<String, List<String>> entry : headers.entrySet()) { * @param headerName
String name = entry.getKey(); * @return
if (name.equalsIgnoreCase("Content-Type") || name.equalsIgnoreCase("Content-Length")) { */
continue; // ignore headers that interfere with the operation private String soapActionHeader(String value) {
}
for (String value : entry.getValue()) { StringTokenizer tk = new StringTokenizer(value,";");
res.addHeader(name, value); String soapAction=null;
} while(tk.hasMoreTokens()){
} String t = tk.nextToken();
if(t.startsWith("action=")){
soapAction= t.substring("action=".length());
}
}
return soapAction;
} }
//@Override @Override
public void setResponseHeader(String headerName, List<String> values) { public void setResponseHeaders(Map<String,List<String>> headers) {
responseHeaders.put(headerName, values); if (headers != null) {
for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
List<String> values = entry.getValue();
if (values.size() == 1) {
res.setHeader(key, values.get(1));
} else {
// If the header has multiple values, comma separte them
StringBuffer concat = new StringBuffer();
boolean firstTime = true;
for (String aValue : values) {
if (!firstTime) {
concat.append(',');
}
concat.append(aValue);
firstTime = false;
}
res.setHeader(key, concat.toString());
}
}
}
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property(MessageContext.HTTP_RESPONSE_HEADERS) @Property(MessageContext.HTTP_RESPONSE_HEADERS)
public Map<String, List<String>> getResponseHeaders() { public Map<String,List<String>> getResponseHeaders() {
return responseHeaders; MimeHeaders mimeHeaders = res.getMimeHeaders();
Map<String, List<String>> jaxWSHeaders = convertHeaders(mimeHeaders);
return jaxWSHeaders;
} }
@Override @Override
public void setContentTypeResponseHeader(@NotNull String value) { public void setContentTypeResponseHeader(@NotNull String value) {
res.setHeader("Content-Type", value); res.setHeader("Content-Type", value);
@ -158,29 +184,27 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property(MessageContext.HTTP_RESPONSE_CODE) @Property(MessageContext.HTTP_RESPONSE_CODE)
public int getStatus() { public int getStatus() {
return status; return status;
} }
@org.jvnet.ws.message.PropertySet.Property(MessageContext.SERVLET_REQUEST) @Property(MessageContext.SERVLET_REQUEST)
public HttpServletRequest getRequest() { public HttpServletRequest getRequest() {
return coyoteRequest; return coyoteRequest;
} }
@org.jvnet.ws.message.PropertySet.Property(MessageContext.SERVLET_RESPONSE) @Property(MessageContext.SERVLET_RESPONSE)
public HttpServletResponse getResponse() { public HttpServletResponse getResponse() {
return coyoteResponse; return coyoteResponse;
} }
public @NotNull public @NotNull InputStream getInput() throws IOException{
InputStream getInput() throws IOException {
return coyoteRequest.getInputStream(); return coyoteRequest.getInputStream();
//return httpExchange.getRequestBody(); //return httpExchange.getRequestBody();
} }
public @NotNull public @NotNull OutputStream getOutput() throws IOException {
OutputStream getOutput() throws IOException {
assert !outputWritten; assert !outputWritten;
outputWritten = true; outputWritten = true;
@ -188,8 +212,7 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
return coyoteResponse.getOutputStream(); return coyoteResponse.getOutputStream();
} }
public @NotNull public @NotNull WebServiceContextDelegate getWebServiceContextDelegate() {
WebServiceContextDelegate getWebServiceContextDelegate() {
return this; return this;
} }
@ -201,38 +224,36 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
return false; return false;
} }
public @NotNull public @NotNull String getEPRAddress(Packet request, WSEndpoint endpoint) {
String getEPRAddress(Packet request, WSEndpoint endpoint) {
// TODO: verify the kind of address it wants here // TODO: verify the kind of address it wants here
return coyoteRequest.getRequestURL().toString(); return coyoteRequest.getRequestURL().toString();
} }
public String getWSDLAddress(@NotNull Packet request, @NotNull WSEndpoint endpoint) { public String getWSDLAddress(@NotNull Packet request, @NotNull WSEndpoint endpoint) {
String eprAddress = getEPRAddress(request, endpoint); String eprAddress = getEPRAddress(request,endpoint);
String wsdlAddress = eprAddress + "?wsdl"; String wsdlAddress = eprAddress + "?wsdl";
return wsdlAddress; return wsdlAddress;
} }
//@Override //@Override
public boolean isSecure() { public boolean isSecure() {
return this.isSecure; return this.isSecure;
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property(MessageContext.HTTP_REQUEST_METHOD) @Property(MessageContext.HTTP_REQUEST_METHOD)
public @NotNull public @NotNull String getRequestMethod() {
String getRequestMethod() {
return coyoteRequest.getMethod(); return coyoteRequest.getMethod();
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property(MessageContext.QUERY_STRING) @Property(MessageContext.QUERY_STRING)
public String getQueryString() { public String getQueryString() {
return coyoteRequest.getQueryString(); return coyoteRequest.getQueryString();
} }
@Override @Override
@org.jvnet.ws.message.PropertySet.Property(MessageContext.PATH_INFO) @Property(MessageContext.PATH_INFO)
public String getPathInfo() { public String getPathInfo() {
return coyoteRequest.getRequestURI(); return coyoteRequest.getRequestURI();
} }
@ -245,11 +266,11 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
finishGrizzlyResponse(); finishGrizzlyResponse();
super.close(); super.close();
} }
protected PropertyMap getPropertyMap() { protected PropertyMap getPropertyMap() {
return model; return model;
} }
void finishGrizzlyResponse() { void finishGrizzlyResponse() {
if (grizzlyAsyncTask != null) { if (grizzlyAsyncTask != null) {
JBIGrizzlyAsyncFilter.finishResponse(grizzlyAsyncTask); JBIGrizzlyAsyncFilter.finishResponse(grizzlyAsyncTask);
@ -259,33 +280,57 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
} }
} }
private Map<String, List<String>> initializeRequestHeaders() { /**
final Map<String, List<String>> headers = new HashMap<String, List<String>>(); * Convert from MimeHeaders to the format JAX-WS uses
MimeHeaders mimeHeaders = req.getMimeHeaders(); * with the header name as the map key pointing to a list of values
Enumeration names = mimeHeaders.names(); * for that header
while (names.hasMoreElements()) { *
String name = (String) names.nextElement(); * This conversion might be expesive, if this is frequently used it may
List<String> jaxWsValues = new ArrayList<String>(); * be worth changing Grizzly or JAX-WS to remove the need for the conversion
Enumeration values = mimeHeaders.values(name); */
while (values.hasMoreElements()) { Map<String, List<String>> convertHeaders(MimeHeaders mimeHeaders) {
String aValue = (String) values.nextElement(); Map<String, List<String>> jaxWSHeaders = new HashMap();
jaxWsValues.add(aValue); Enumeration names = mimeHeaders.names();
} while (names.hasMoreElements()) {
headers.put(name, jaxWsValues); String name = (String) names.nextElement();
} List jaxWSHeaderValues = new ArrayList();
Enumeration values = mimeHeaders.values(name);
return headers; if (name.equalsIgnoreCase("Content-Type")) {
while (values.hasMoreElements()) {
String aValue = (String) values.nextElement();
jaxWSHeaderValues.add(aValue);
if(aValue.indexOf("action=") > 0){
List soapActions = new ArrayList();
soapActions.add(soapActionHeader(aValue));
jaxWSHeaders.put("SOAPAction", soapActions);
}
}
} else {
while (values.hasMoreElements()) {
String aValue = (String) values.nextElement();
jaxWSHeaderValues.add(aValue);
}
}
jaxWSHeaders.put(name, jaxWSHeaderValues);
}
return jaxWSHeaders;
} }
private static final PropertyMap model; private static final PropertyMap model;
static { static {
model = parse(JAXWSGrizzlyHttpConnection.class); model = parse(JAXWSGrizzlyHttpConnection.class);
} }
/** /**
* @return the basicAuthSubject * @return the basicAuthSubject
*/ */
@org.jvnet.ws.message.PropertySet.Property("basicAuthSubject")
@Property("basicAuthSubject")
public Subject getBasicAuthSubject() { public Subject getBasicAuthSubject() {
return basicAuthSubject; return basicAuthSubject;
} }
@ -296,34 +341,4 @@ public final class JAXWSGrizzlyHttpConnection extends WSHTTPConnection implement
public void setBasicAuthSubject(Subject basicAuthSubject) { public void setBasicAuthSubject(Subject basicAuthSubject) {
this.basicAuthSubject = basicAuthSubject; this.basicAuthSubject = basicAuthSubject;
} }
}
//@Override
public Set<String> getRequestHeaderNames() {
return requestHeaders.keySet();
}
//@Override
public List<String> getRequestHeaderValues(String headerName) {
return requestHeaders.get(headerName);
}
//@Override
public String getRequestURI() {
return req.requestURI().getString();
}
//@Override
public String getRequestScheme() {
return req.scheme().getString();
}
//@Override
public String getServerName() {
return req.serverName().getString();
}
//@Override
public int getServerPort() {
return req.getServerPort();
}
}