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.AttachmentSet;
042: import com.sun.xml.ws.api.message.Attachment;
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 ServerSOAPHandlerTube extends HandlerTube {
063:
064: private WSBinding binding;
065: private Set<String> roles;
066:
067: /**
068: * Creates a new instance of SOAPHandlerTube
069: */
070: public ServerSOAPHandlerTube(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: setUpProcessorOnce();
079: }
080:
081: // Handle to LogicalHandlerTube means its used on SERVER-SIDE
082:
083: /**
084: * This constructor is used on client-side where, LogicalHandlerTube is created
085: * first and then a SOAPHandlerTube is created with a handler to that
086: * LogicalHandlerTube.
087: * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
088: */
089: public ServerSOAPHandlerTube(WSBinding binding, Tube next,
090: HandlerTube cousinTube) {
091: super (next, cousinTube);
092: this .binding = binding;
093: setUpProcessorOnce();
094: }
095:
096: /**
097: * Copy constructor for {@link com.sun.xml.ws.api.pipe.Tube#copy(com.sun.xml.ws.api.pipe.TubeCloner)}.
098: */
099: private ServerSOAPHandlerTube(ServerSOAPHandlerTube that,
100: TubeCloner cloner) {
101: super (that, cloner);
102: this .binding = that.binding;
103: setUpProcessorOnce();
104: }
105:
106: public AbstractFilterTubeImpl copy(TubeCloner cloner) {
107: return new ServerSOAPHandlerTube(this , cloner);
108: }
109:
110: private void setUpProcessorOnce() {
111: handlers = new ArrayList<Handler>();
112: HandlerConfiguration handlerConfig = ((BindingImpl) binding)
113: .getHandlerConfig();
114: List<SOAPHandler> soapSnapShot = handlerConfig
115: .getSoapHandlers();
116: if (!soapSnapShot.isEmpty()) {
117: handlers.addAll(soapSnapShot);
118: roles = new HashSet<String>();
119: roles.addAll(handlerConfig.getRoles());
120: processor = new SOAPHandlerProcessor(false, this , binding,
121: handlers);
122: }
123: }
124:
125: void setUpProcessor() {
126: // Do nothing, Processor is setup in the constructor.
127: }
128:
129: MessageUpdatableContext getContext(Packet packet) {
130: SOAPMessageContextImpl context = new SOAPMessageContextImpl(
131: binding, packet, roles);
132: return context;
133: }
134:
135: boolean callHandlersOnRequest(MessageUpdatableContext context,
136: boolean isOneWay) {
137:
138: boolean handlerResult;
139: try {
140: //SERVER-SIDE
141: handlerResult = processor.callHandlersRequest(
142: HandlerProcessor.Direction.INBOUND, context,
143: !isOneWay);
144:
145: } catch (RuntimeException re) {
146: remedyActionTaken = true;
147: throw re;
148:
149: }
150: if (!handlerResult) {
151: remedyActionTaken = true;
152: }
153: return handlerResult;
154: }
155:
156: void callHandlersOnResponse(MessageUpdatableContext context,
157: boolean handleFault) {
158:
159: //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
160: Map<String, DataHandler> atts = (Map<String, DataHandler>) context
161: .get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
162: AttachmentSet attSet = packet.getMessage().getAttachments();
163: for (String cid : atts.keySet()) {
164: if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
165: Attachment att = new DataHandlerAttachment(cid, atts
166: .get(cid));
167: attSet.add(att);
168: }
169: }
170:
171: try {
172: //SERVER-SIDE
173: processor.callHandlersResponse(
174: HandlerProcessor.Direction.OUTBOUND, context,
175: handleFault);
176:
177: } catch (WebServiceException wse) {
178: //no rewrapping
179: throw wse;
180: } catch (RuntimeException re) {
181: throw re;
182:
183: }
184: }
185:
186: void closeHandlers(MessageContext mc) {
187: closeServersideHandlers(mc);
188:
189: }
190: }
|