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.binding.BindingImpl;
048: import com.sun.xml.ws.message.DataHandlerAttachment;
049:
050: import javax.xml.ws.handler.LogicalHandler;
051: import javax.xml.ws.handler.MessageContext;
052: import javax.xml.ws.handler.Handler;
053: import javax.xml.ws.WebServiceException;
054: import javax.activation.DataHandler;
055: import java.util.List;
056: import java.util.ArrayList;
057: import java.util.Map;
058:
059: /**
060: *
061: * @author WS Development Team
062: */
063: public class ServerLogicalHandlerTube extends HandlerTube {
064:
065: private WSBinding binding;
066:
067: /**
068: * Creates a new instance of LogicalHandlerTube
069: */
070: public ServerLogicalHandlerTube(WSBinding binding, WSDLPort port,
071: Tube next) {
072: super (next, port);
073: this .binding = binding;
074: setUpProcessorOnce();
075: }
076:
077: /**
078: * This constructor is used on client-side where, SOAPHandlerTube is created
079: * first and then a LogicalHandlerTube is created with a handler to that
080: * SOAPHandlerTube.
081: * With this handle, LogicalHandlerTube can call
082: * SOAPHandlerTube.closeHandlers()
083: */
084: public ServerLogicalHandlerTube(WSBinding binding, Tube next,
085: HandlerTube cousinTube) {
086: super (next, cousinTube);
087: this .binding = binding;
088: setUpProcessorOnce();
089: }
090:
091: /**
092: * Copy constructor for {@link com.sun.xml.ws.api.pipe.Tube#copy(com.sun.xml.ws.api.pipe.TubeCloner)}.
093: */
094:
095: private ServerLogicalHandlerTube(ServerLogicalHandlerTube that,
096: TubeCloner cloner) {
097: super (that, cloner);
098: this .binding = that.binding;
099: setUpProcessorOnce();
100: }
101:
102: //should be overridden by DriverHandlerTubes
103: @Override
104: protected void initiateClosing(MessageContext mc) {
105: if (binding.getSOAPVersion() != null) {
106: super .initiateClosing(mc);
107: } else {
108: close(mc);
109: super .initiateClosing(mc);
110: }
111: }
112:
113: public AbstractFilterTubeImpl copy(TubeCloner cloner) {
114: return new ServerLogicalHandlerTube(this , cloner);
115: }
116:
117: private void setUpProcessorOnce() {
118: handlers = new ArrayList<Handler>();
119: List<LogicalHandler> logicalSnapShot = ((BindingImpl) binding)
120: .getHandlerConfig().getLogicalHandlers();
121: if (!logicalSnapShot.isEmpty()) {
122: handlers.addAll(logicalSnapShot);
123: if (binding.getSOAPVersion() == null) {
124: processor = new XMLHandlerProcessor(this , binding,
125: handlers);
126: } else {
127: processor = new SOAPHandlerProcessor(false, this ,
128: binding, handlers);
129: }
130: }
131: }
132:
133: void setUpProcessor() {
134: // Do nothing, Processor is setup in the constructor.
135: }
136:
137: MessageUpdatableContext getContext(Packet packet) {
138: return new LogicalMessageContextImpl(binding, packet);
139: }
140:
141: boolean callHandlersOnRequest(MessageUpdatableContext context,
142: boolean isOneWay) {
143:
144: boolean handlerResult;
145: try {
146: //SERVER-SIDE
147: handlerResult = processor.callHandlersRequest(
148: HandlerProcessor.Direction.INBOUND, context,
149: !isOneWay);
150:
151: } catch (RuntimeException re) {
152: remedyActionTaken = true;
153: throw re;
154: }
155: if (!handlerResult) {
156: remedyActionTaken = true;
157: }
158: return handlerResult;
159: }
160:
161: void callHandlersOnResponse(MessageUpdatableContext context,
162: boolean handleFault) {
163: //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
164: Map<String, DataHandler> atts = (Map<String, DataHandler>) context
165: .get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
166: AttachmentSet attSet = packet.getMessage().getAttachments();
167: for (String cid : atts.keySet()) {
168: Attachment att = new DataHandlerAttachment(cid, atts
169: .get(cid));
170: attSet.add(att);
171: }
172:
173: try {
174: //SERVER-SIDE
175: processor.callHandlersResponse(
176: HandlerProcessor.Direction.OUTBOUND, context,
177: handleFault);
178:
179: } catch (WebServiceException wse) {
180: //no rewrapping
181: throw wse;
182: } catch (RuntimeException re) {
183: throw re;
184: }
185: }
186:
187: void closeHandlers(MessageContext mc) {
188: closeServersideHandlers(mc);
189:
190: }
191: }
|