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