001: package org.objectweb.celtix.geronimo.container;
002:
003: import java.io.IOException;
004: import java.io.Serializable;
005: import java.lang.reflect.Field;
006: import java.util.LinkedList;
007: import java.util.List;
008: import java.util.Map;
009: import java.util.StringTokenizer;
010: import java.util.logging.Logger;
011:
012: import javax.wsdl.WSDLException;
013: import javax.xml.ws.handler.MessageContext;
014:
015: import org.apache.geronimo.webservices.WebServiceContainer.Request;
016: import org.apache.geronimo.webservices.WebServiceContainer.Response;
017: import org.objectweb.celtix.Bus;
018: import org.objectweb.celtix.bus.transports.http.AbstractHTTPServerTransport;
019: import org.objectweb.celtix.context.OutputStreamMessageContext;
020: import org.objectweb.celtix.transports.ServerTransportCallback;
021: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
022:
023: public class GeronimoServerTransport extends
024: AbstractHTTPServerTransport implements Serializable {
025:
026: private static final Logger LOG = Logger
027: .getLogger(GeronimoServerTransport.class.getName());
028:
029: public GeronimoServerTransport(Bus bus,
030: EndpointReferenceType address) throws WSDLException,
031: IOException {
032: super (bus, address);
033: }
034:
035: public void invoke(Request request, Response response) {
036: assert callback != null : "callback is null";
037:
038: GeronimoInputStreamMessageContext msgCtx = createInputStreamMessageContext();
039: msgCtx.setRequest(request);
040: msgCtx.setResponse(response);
041: callback.dispatch(msgCtx, this );
042: }
043:
044: public void activate(ServerTransportCallback aCallback)
045: throws IOException {
046: LOG.fine("geronimo server transport activating: " + callback);
047: callback = aCallback;
048: }
049:
050: public void deactivate() throws IOException {
051: System.out.println("geronimo server transport deactivating");
052: }
053:
054: public OutputStreamMessageContext rebase(MessageContext context,
055: EndpointReferenceType decoupledResponseEndpoint)
056: throws IOException {
057: // TODO Auto-generated method stub
058: return null;
059: }
060:
061: public void postDispatch(MessageContext bindingContext,
062: OutputStreamMessageContext context) {
063: System.out.println("geronimo server transport postDispatch");
064: }
065:
066: public void shutdown() {
067: // TODO Auto-generated method stub
068:
069: }
070:
071: public OutputStreamMessageContext createOutputStreamContext(
072: MessageContext context) throws IOException {
073: return new GeronimoOutputStreamServerMessageContext(context);
074: }
075:
076: public void finalPrepareOutputStreamContext(
077: OutputStreamMessageContext context) throws IOException {
078: // do nothing
079: }
080:
081: @Override
082: protected void copyRequestHeaders(MessageContext ctx,
083: Map<String, List<String>> headers) {
084: assert ctx instanceof GeronimoInputStreamMessageContext;
085: GeronimoInputStreamMessageContext gctx = (GeronimoInputStreamMessageContext) ctx;
086: Request req = gctx.getRequest();
087:
088: // no map of headers so just find all static field constants that begin with HEADER_, get
089: // its value and get the corresponding header.
090: for (Field field : Request.class.getFields()) {
091: if (field.getName().startsWith("HEADER_")) {
092: try {
093: assert field.getType().equals(String.class) : "unexpected field type";
094: String headerName = (String) field.get(null);
095: String headerValue = req.getHeader(headerName);
096: if (headerValue != null) {
097: List<String> values = headers.get(headerName);
098: if (values == null) {
099: values = new LinkedList<String>();
100: headers.put(headerName, values);
101: }
102: values
103: .addAll(splitMultipleHeaderValues(headerValue));
104: }
105: } catch (IllegalAccessException ex) {
106: // ignore
107: }
108: }
109: }
110: }
111:
112: private List<String> splitMultipleHeaderValues(String value) {
113:
114: List<String> allValues = new LinkedList<String>();
115: if (value.contains(",")) {
116: StringTokenizer st = new StringTokenizer(value, ",");
117: while (st.hasMoreTokens()) {
118: allValues.add(st.nextToken().trim());
119: }
120:
121: } else {
122: allValues.add(value);
123: }
124: return allValues;
125: }
126:
127: protected GeronimoInputStreamMessageContext createInputStreamMessageContext() {
128: return new GeronimoInputStreamMessageContext();
129: }
130:
131: }
|