001: package com.sun.xml.ws.handler;
002:
003: import com.sun.istack.Nullable;
004: import com.sun.xml.ws.api.WSBinding;
005: import com.sun.xml.ws.api.handler.MessageHandler;
006: import com.sun.xml.ws.api.message.Attachment;
007: import com.sun.xml.ws.api.message.AttachmentSet;
008: import com.sun.xml.ws.api.message.Packet;
009: import com.sun.xml.ws.api.model.SEIModel;
010: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
011: import com.sun.xml.ws.api.pipe.Tube;
012: import com.sun.xml.ws.api.pipe.TubeCloner;
013: import com.sun.xml.ws.api.pipe.helper.AbstractFilterTubeImpl;
014: import com.sun.xml.ws.binding.BindingImpl;
015: import com.sun.xml.ws.client.HandlerConfiguration;
016: import com.sun.xml.ws.message.DataHandlerAttachment;
017:
018: import javax.activation.DataHandler;
019: import javax.xml.ws.WebServiceException;
020: import javax.xml.ws.handler.MessageContext;
021: import javax.xml.ws.handler.Handler;
022: import java.util.*;
023:
024: /**
025: * @author Rama Pulavarthi
026: */
027: public class ClientMessageHandlerTube extends HandlerTube {
028: private SEIModel seiModel;
029: private WSBinding binding;
030: private Set<String> roles;
031:
032: /**
033: * Creates a new instance of MessageHandlerTube
034: */
035: public ClientMessageHandlerTube(@Nullable
036: SEIModel seiModel, WSBinding binding, WSDLPort port, Tube next) {
037: super (next, port);
038: this .seiModel = seiModel;
039: this .binding = binding;
040: }
041:
042: /**
043: * Copy constructor for {@link com.sun.xml.ws.api.pipe.Tube#copy(com.sun.xml.ws.api.pipe.TubeCloner)}.
044: */
045: private ClientMessageHandlerTube(ClientMessageHandlerTube that,
046: TubeCloner cloner) {
047: super (that, cloner);
048: this .seiModel = that.seiModel;
049: this .binding = that.binding;
050: }
051:
052: public AbstractFilterTubeImpl copy(TubeCloner cloner) {
053: return new ClientMessageHandlerTube(this , cloner);
054: }
055:
056: void callHandlersOnResponse(MessageUpdatableContext context,
057: boolean handleFault) {
058: try {
059: //CLIENT-SIDE
060: processor.callHandlersResponse(
061: HandlerProcessor.Direction.INBOUND, context,
062: handleFault);
063:
064: } catch (WebServiceException wse) {
065: //no rewrapping
066: throw wse;
067: } catch (RuntimeException re) {
068: throw new WebServiceException(re);
069: }
070: }
071:
072: boolean callHandlersOnRequest(MessageUpdatableContext context,
073: boolean isOneWay) {
074: boolean handlerResult;
075:
076: //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
077: Map<String, DataHandler> atts = (Map<String, DataHandler>) context
078: .get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
079: AttachmentSet attSet = packet.getMessage().getAttachments();
080: for (String cid : atts.keySet()) {
081: if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
082: Attachment att = new DataHandlerAttachment(cid, atts
083: .get(cid));
084: attSet.add(att);
085: }
086: }
087:
088: try {
089: //CLIENT-SIDE
090: handlerResult = processor.callHandlersRequest(
091: HandlerProcessor.Direction.OUTBOUND, context,
092: !isOneWay);
093: } catch (WebServiceException wse) {
094: remedyActionTaken = true;
095: //no rewrapping
096: throw wse;
097: } catch (RuntimeException re) {
098: remedyActionTaken = true;
099:
100: throw new WebServiceException(re);
101:
102: }
103: if (!handlerResult) {
104: remedyActionTaken = true;
105: }
106: return handlerResult;
107: }
108:
109: void closeHandlers(MessageContext mc) {
110: closeClientsideHandlers(mc);
111:
112: }
113:
114: void setUpProcessor() {
115: // Take a snapshot, User may change chain after invocation, Same chain
116: // should be used for the entire MEP
117: handlers = new ArrayList<Handler>();
118: HandlerConfiguration handlerConfig = ((BindingImpl) binding)
119: .getHandlerConfig();
120: List<MessageHandler> msgHandlersSnapShot = handlerConfig
121: .getMessageHandlers();
122: if (!msgHandlersSnapShot.isEmpty()) {
123: handlers.addAll(msgHandlersSnapShot);
124: roles = new HashSet<String>();
125: roles.addAll(handlerConfig.getRoles());
126: processor = new SOAPHandlerProcessor(true, this , binding,
127: handlers);
128: }
129: }
130:
131: MessageUpdatableContext getContext(Packet p) {
132: MessageHandlerContextImpl context = new MessageHandlerContextImpl(
133: seiModel, binding, packet, roles);
134: return context;
135: }
136:
137: }
|