1 17 package org.apache.geronimo.cxf; 18 19 import java.io.IOException ; 20 import java.io.OutputStream ; 21 import java.io.Serializable ; 22 import java.lang.reflect.Field ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.StringTokenizer ; 27 28 import org.apache.cxf.Bus; 29 import org.apache.cxf.message.Exchange; 30 import org.apache.cxf.message.Message; 31 import org.apache.cxf.message.MessageImpl; 32 import org.apache.cxf.service.model.EndpointInfo; 33 import org.apache.cxf.transport.Conduit; 34 import org.apache.cxf.transport.ConduitInitiator; 35 import org.apache.cxf.transport.Destination; 36 import org.apache.cxf.transport.MessageObserver; 37 import org.apache.cxf.transport.http.AbstractHTTPDestination; 38 import org.apache.cxf.ws.addressing.EndpointReferenceType; 39 import org.apache.cxf.wsdl.EndpointReferenceUtils; 40 import org.apache.geronimo.webservices.WebServiceContainer.Request; 41 import org.apache.geronimo.webservices.WebServiceContainer.Response; 42 43 public class GeronimoDestination extends AbstractHTTPDestination 44 implements Serializable { 45 46 private MessageObserver messageObserver; 47 48 public GeronimoDestination(Bus bus, ConduitInitiator conduitInitiator, EndpointInfo endpointInfo) throws IOException { 49 super(bus, conduitInitiator, endpointInfo); 50 } 51 52 53 public void invoke(Request request, Response response) { 54 Message message = new MessageImpl(); 55 message.put(Request.class, request); 56 message.put(Response.class, response); 57 messageObserver.onMessage(message); 58 } 59 60 public Conduit getBackChannel(Message inMessage, Message partialResponse, EndpointReferenceType address) throws IOException { 61 Response response = inMessage.get(Response.class); 62 Conduit backChannel; 63 Exchange ex = inMessage.getExchange(); 64 EndpointReferenceType target = address != null 65 ? address 66 : ex.get(EndpointReferenceType.class); 67 if (target == null) { 68 backChannel = new BackChannelConduit(response); 69 } else { 70 throw new IllegalArgumentException ("RM not yet implemented"); 71 } 72 return backChannel; 73 } 74 75 public void shutdown() { 76 } 77 78 @Override 79 protected void copyRequestHeaders(Message message, Map <String , List <String >> headers) { 80 Request req = message.get(Request.class); 81 82 for (Field field : Request.class.getFields()) { 85 if (field.getName().startsWith("HEADER_")) { 86 try { 87 assert field.getType().equals(String .class) : "unexpected field type"; 88 String headerName = (String ) field.get(null); 89 String headerValue = req.getHeader(headerName); 90 if (headerValue != null) { 91 List <String > values = headers.get(headerName); 92 if (values == null) { 93 values = new LinkedList <String >(); 94 headers.put(headerName, values); 95 } 96 values.addAll(splitMultipleHeaderValues(headerValue)); 97 } 98 } catch (IllegalAccessException ex) { 99 } 101 } 102 } 103 } 104 105 private List <String > splitMultipleHeaderValues(String value) { 106 107 List <String > allValues = new LinkedList <String >(); 108 if (value.contains(",")) { 109 StringTokenizer st = new StringTokenizer (value, ","); 110 while (st.hasMoreTokens()) { 111 allValues.add(st.nextToken().trim()); 112 } 113 114 } else { 115 allValues.add(value); 116 } 117 return allValues; 118 } 119 120 121 public void setMessageObserver(MessageObserver messageObserver) { 122 this.messageObserver = messageObserver; 123 } 124 125 protected class BackChannelConduit implements Conduit { 126 127 private static final String ANONYMOUS_ADDRESS = 129 "http://www.w3.org/2005/08/addressing/anonymous"; 130 protected Response response; 131 protected EndpointReferenceType target; 132 133 BackChannelConduit(Response resp) { 134 response = resp; 135 target = EndpointReferenceUtils.getEndpointReference(ANONYMOUS_ADDRESS); 136 } 137 138 public void close(Message msg) throws IOException { 139 msg.getContent(OutputStream .class).close(); 140 } 141 142 147 public void setMessageObserver(MessageObserver observer) { 148 } 150 151 157 public void send(Message message) throws IOException { 158 message.put(Response.class, response); 159 message.setContent(OutputStream .class, response.getOutputStream()); 162 } 163 164 167 public EndpointReferenceType getTarget() { 168 return target; 169 } 170 171 177 public Destination getBackChannel() { 178 return null; 179 } 180 181 184 public void close() { 185 } 186 } 187 188 } 189 | Popular Tags |