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