001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.handler;
038:
039: import com.sun.xml.ws.api.WSBinding;
040: import com.sun.xml.ws.api.message.Packet;
041: import com.sun.xml.ws.api.message.Attachment;
042: import com.sun.xml.ws.api.message.AttachmentSet;
043: import com.sun.xml.ws.api.pipe.TubeCloner;
044: import com.sun.xml.ws.api.pipe.Tube;
045: import com.sun.xml.ws.api.pipe.helper.AbstractFilterTubeImpl;
046: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
047: import com.sun.xml.ws.client.HandlerConfiguration;
048: import com.sun.xml.ws.binding.BindingImpl;
049: import com.sun.xml.ws.message.DataHandlerAttachment;
050:
051: import javax.xml.ws.handler.soap.SOAPHandler;
052: import javax.xml.ws.handler.MessageContext;
053: import javax.xml.ws.handler.Handler;
054: import javax.xml.ws.WebServiceException;
055: import javax.activation.DataHandler;
056: import java.util.*;
057:
058: /**
059: *
060: * @author WS Development Team
061: */
062: public class ClientSOAPHandlerTube extends HandlerTube {
063:
064: private WSBinding binding;
065: private Set<String> roles;
066:
067: /**
068: * Creates a new instance of SOAPHandlerTube
069: */
070: public ClientSOAPHandlerTube(WSBinding binding, WSDLPort port,
071: Tube next) {
072: super (next, port);
073: if (binding.getSOAPVersion() != null) {
074: // SOAPHandlerTube should n't be used for bindings other than SOAP.
075: // TODO: throw Exception
076: }
077: this .binding = binding;
078: }
079:
080: // Handle to LogicalHandlerTube means its used on SERVER-SIDE
081:
082: /**
083: * This constructor is used on client-side where, LogicalHandlerTube is created
084: * first and then a SOAPHandlerTube is created with a handler to that
085: * LogicalHandlerTube.
086: * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
087: */
088: public ClientSOAPHandlerTube(WSBinding binding, Tube next,
089: HandlerTube cousinTube) {
090: super (next, cousinTube);
091: this .binding = binding;
092: }
093:
094: /**
095: * Copy constructor for {@link com.sun.xml.ws.api.pipe.Tube#copy(com.sun.xml.ws.api.pipe.TubeCloner)}.
096: */
097: private ClientSOAPHandlerTube(ClientSOAPHandlerTube that,
098: TubeCloner cloner) {
099: super (that, cloner);
100: this .binding = that.binding;
101: }
102:
103: public AbstractFilterTubeImpl copy(TubeCloner cloner) {
104: return new ClientSOAPHandlerTube(this , cloner);
105: }
106:
107: void setUpProcessor() {
108: // Take a snapshot, User may change chain after invocation, Same chain
109: // should be used for the entire MEP
110: handlers = new ArrayList<Handler>();
111: HandlerConfiguration handlerConfig = ((BindingImpl) binding)
112: .getHandlerConfig();
113: List<SOAPHandler> soapSnapShot = handlerConfig
114: .getSoapHandlers();
115: if (!soapSnapShot.isEmpty()) {
116: handlers.addAll(soapSnapShot);
117: roles = new HashSet<String>();
118: roles.addAll(handlerConfig.getRoles());
119: processor = new SOAPHandlerProcessor(true, this , binding,
120: handlers);
121: }
122: }
123:
124: MessageUpdatableContext getContext(Packet packet) {
125: SOAPMessageContextImpl context = new SOAPMessageContextImpl(
126: binding, packet, roles);
127: return context;
128: }
129:
130: boolean callHandlersOnRequest(MessageUpdatableContext context,
131: boolean isOneWay) {
132:
133: boolean handlerResult;
134: //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
135: Map<String, DataHandler> atts = (Map<String, DataHandler>) context
136: .get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
137: AttachmentSet attSet = packet.getMessage().getAttachments();
138: for (String cid : atts.keySet()) {
139: if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
140: Attachment att = new DataHandlerAttachment(cid, atts
141: .get(cid));
142: attSet.add(att);
143: }
144: }
145:
146: try {
147: //CLIENT-SIDE
148: handlerResult = processor.callHandlersRequest(
149: HandlerProcessor.Direction.OUTBOUND, context,
150: !isOneWay);
151: } catch (WebServiceException wse) {
152: remedyActionTaken = true;
153: //no rewrapping
154: throw wse;
155: } catch (RuntimeException re) {
156: remedyActionTaken = true;
157:
158: throw new WebServiceException(re);
159:
160: }
161: if (!handlerResult) {
162: remedyActionTaken = true;
163: }
164: return handlerResult;
165: }
166:
167: void callHandlersOnResponse(MessageUpdatableContext context,
168: boolean handleFault) {
169: try {
170:
171: //CLIENT-SIDE
172: processor.callHandlersResponse(
173: HandlerProcessor.Direction.INBOUND, context,
174: handleFault);
175:
176: } catch (WebServiceException wse) {
177: //no rewrapping
178: throw wse;
179: } catch (RuntimeException re) {
180: throw new WebServiceException(re);
181: }
182: }
183:
184: void closeHandlers(MessageContext mc) {
185: closeClientsideHandlers(mc);
186:
187: }
188: }
|