169N/A/*
0N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.xml.internal.ws.handler;
0N/A
0N/Aimport com.sun.xml.internal.ws.api.WSBinding;
0N/Aimport com.sun.xml.internal.ws.api.message.Packet;
0N/Aimport com.sun.xml.internal.ws.api.message.Attachment;
0N/Aimport com.sun.xml.internal.ws.api.message.AttachmentSet;
0N/Aimport com.sun.xml.internal.ws.api.pipe.TubeCloner;
0N/Aimport com.sun.xml.internal.ws.api.pipe.Tube;
0N/Aimport com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
0N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
0N/Aimport com.sun.xml.internal.ws.client.HandlerConfiguration;
0N/Aimport com.sun.xml.internal.ws.binding.BindingImpl;
0N/Aimport com.sun.xml.internal.ws.message.DataHandlerAttachment;
0N/A
0N/Aimport javax.xml.ws.handler.soap.SOAPHandler;
0N/Aimport javax.xml.ws.handler.MessageContext;
0N/Aimport javax.xml.ws.handler.Handler;
0N/Aimport javax.xml.ws.WebServiceException;
0N/Aimport javax.activation.DataHandler;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A *
0N/A * @author WS Development Team
0N/A */
0N/Apublic class ClientSOAPHandlerTube extends HandlerTube {
169N/A
0N/A private WSBinding binding;
0N/A private Set<String> roles;
169N/A
169N/A /**
169N/A * Creates a new instance of SOAPHandlerTube
169N/A */
169N/A public ClientSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) {
169N/A super(next, port);
169N/A if (binding.getSOAPVersion() != null) {
169N/A // SOAPHandlerTube should n't be used for bindings other than SOAP.
169N/A // TODO: throw Exception
169N/A }
169N/A this.binding = binding;
0N/A }
169N/A
169N/A // Handle to LogicalHandlerTube means its used on SERVER-SIDE
169N/A
169N/A /**
169N/A * This constructor is used on client-side where, LogicalHandlerTube is created
169N/A * first and then a SOAPHandlerTube is created with a handler to that
169N/A * LogicalHandlerTube.
169N/A * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
169N/A */
169N/A public ClientSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
169N/A super(next, cousinTube);
0N/A this.binding = binding;
169N/A }
169N/A
169N/A /**
169N/A * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
169N/A */
169N/A private ClientSOAPHandlerTube(ClientSOAPHandlerTube that, TubeCloner cloner) {
169N/A super(that, cloner);
169N/A this.binding = that.binding;
169N/A }
0N/A
169N/A public AbstractFilterTubeImpl copy(TubeCloner cloner) {
169N/A return new ClientSOAPHandlerTube(this, cloner);
169N/A }
169N/A
169N/A void setUpProcessor() {
169N/A // Take a snapshot, User may change chain after invocation, Same chain
169N/A // should be used for the entire MEP
169N/A handlers = new ArrayList<Handler>();
169N/A HandlerConfiguration handlerConfig = ((BindingImpl) binding).getHandlerConfig();
169N/A List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
169N/A if (!soapSnapShot.isEmpty()) {
169N/A handlers.addAll(soapSnapShot);
169N/A roles = new HashSet<String>();
169N/A roles.addAll(handlerConfig.getRoles());
169N/A processor = new SOAPHandlerProcessor(true, this, binding, handlers);
169N/A }
169N/A }
169N/A
169N/A MessageUpdatableContext getContext(Packet packet) {
169N/A SOAPMessageContextImpl context = new SOAPMessageContextImpl(binding, packet,roles);
169N/A return context;
169N/A }
169N/A
169N/A boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
169N/A
169N/A boolean handlerResult;
0N/A //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
0N/A Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
0N/A AttachmentSet attSet = packet.getMessage().getAttachments();
169N/A for(String cid : atts.keySet()){
169N/A if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
0N/A Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
169N/A attSet.add(att);
0N/A }
169N/A }
169N/A
169N/A try {
169N/A //CLIENT-SIDE
169N/A handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
0N/A } catch (WebServiceException wse) {
0N/A remedyActionTaken = true;
//no rewrapping
throw wse;
} catch (RuntimeException re) {
remedyActionTaken = true;
throw new WebServiceException(re);
}
if (!handlerResult) {
remedyActionTaken = true;
}
return handlerResult;
}
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
try {
//CLIENT-SIDE
processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
} catch (WebServiceException wse) {
//no rewrapping
throw wse;
} catch (RuntimeException re) {
throw new WebServiceException(re);
}
}
void closeHandlers(MessageContext mc) {
closeClientsideHandlers(mc);
}
}