1 package org.objectweb.celtix.bindings; 2 3 import java.io.IOException ; 4 import java.util.logging.Level ; 5 import java.util.logging.Logger ; 6 7 import javax.xml.ws.ProtocolException; 8 import javax.xml.ws.handler.MessageContext; 9 10 import org.objectweb.celtix.common.logging.LogUtils; 11 import org.objectweb.celtix.context.InputStreamMessageContext; 12 import org.objectweb.celtix.context.ObjectMessageContext; 13 import org.objectweb.celtix.handlers.HandlerInvoker; 14 15 import static org.objectweb.celtix.context.ObjectMessageContext.CORRELATION_IN; 16 17 public class Response { 18 19 private static final Logger LOG = LogUtils.getL7dLogger(Response.class); 20 21 AbstractBindingBase binding; 22 ObjectMessageContext objectCtx; 23 HandlerInvoker handlerInvoker; 24 MessageContext bindingCtx; 25 26 public Response(Request request) { 27 binding = request.getBinding(); 28 objectCtx = request.getObjectMessageContext(); 29 bindingCtx = request.getBindingContext(); 30 handlerInvoker = request.getHandlerInvoker(); 31 } 32 33 public Response(AbstractBindingBase b, HandlerInvoker h) { 34 binding = b; 35 handlerInvoker = h; 36 } 37 38 public String getCorrelationId() { 39 if (null != bindingCtx) { 40 return (String )bindingCtx.get(CORRELATION_IN); 41 } 42 return null; 43 } 44 45 public ObjectMessageContext getObjectMessageContext() { 46 return objectCtx; 47 } 48 49 public MessageContext getBindingMessageContext() { 50 return bindingCtx; 51 } 52 53 public void setObjectMessageContext(ObjectMessageContext o) { 54 objectCtx = o; 55 if (null != bindingCtx) { 56 objectCtx.putAll(bindingCtx); 57 } 58 } 59 60 public void setHandlerInvoker(HandlerInvoker h) { 61 h.setInbound(); 62 handlerInvoker = h; 63 } 64 65 public HandlerInvoker getHandlerInvoker() { 66 return handlerInvoker; 67 } 68 69 74 public void processProtocol(InputStreamMessageContext istreamCtx) { 75 76 78 handlerInvoker.setInbound(); 79 handlerInvoker.setFault(istreamCtx.isFault()); 80 handlerInvoker.invokeStreamHandlers(istreamCtx); 81 82 if (null == bindingCtx) { 83 bindingCtx = binding.getBindingImpl() 84 .createBindingMessageContext(istreamCtx); 85 } else { 86 bindingCtx.putAll(istreamCtx); 87 } 88 if (null == bindingCtx) { 89 bindingCtx = istreamCtx; 90 } 91 92 bindingCtx.put(ObjectMessageContext.MESSAGE_INPUT, Boolean.TRUE); 93 94 safeRead(istreamCtx, bindingCtx); 95 96 handlerInvoker.invokeProtocolHandlers(true, bindingCtx); 97 } 98 99 104 105 public void processLogical(DataBindingCallback callback) { 106 assert null != bindingCtx; 107 108 if (null != objectCtx) { 109 objectCtx.putAll(bindingCtx); 110 } else { 111 objectCtx = binding.createObjectContext(); 112 callback.initObjectContext(objectCtx); 113 objectCtx.putAll(bindingCtx); 114 } 115 116 if (!BindingContextUtils.retrieveDecoupledResponse(bindingCtx)) { 117 if (!binding.getBindingImpl().hasFault(bindingCtx)) { 118 binding.getBindingImpl().unmarshal(bindingCtx, objectCtx, callback); 119 } else { 120 binding.getBindingImpl().unmarshalFault(bindingCtx, objectCtx, callback); 121 } 122 } 123 124 objectCtx.put(ObjectMessageContext.MESSAGE_INPUT, Boolean.TRUE); 125 handlerInvoker.invokeLogicalHandlers(true, objectCtx); 126 } 127 128 private void safeRead(InputStreamMessageContext inContext, MessageContext msgContext) { 129 try { 130 binding.getBindingImpl().read(inContext, msgContext); 131 } catch (IOException ex) { 132 LOG.log(Level.SEVERE, "READ_IO_FAILURE_MSG", ex); 133 throw new ProtocolException(ex); 134 } 135 } 136 } 137
| Popular Tags
|