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