src/share/jaxws_classes/com/sun/xml/internal/ws/handler/ClientSOAPHandlerTube.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.handler;
    28 import com.sun.xml.internal.ws.api.WSBinding;
    29 import com.sun.xml.internal.ws.api.message.Packet;
    30 import com.sun.xml.internal.ws.api.message.Attachment;
    31 import com.sun.xml.internal.ws.api.message.AttachmentSet;
    32 import com.sun.xml.internal.ws.api.pipe.TubeCloner;
    33 import com.sun.xml.internal.ws.api.pipe.Tube;
    34 import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
    35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    36 import com.sun.xml.internal.ws.client.HandlerConfiguration;
    37 import com.sun.xml.internal.ws.binding.BindingImpl;
    38 import com.sun.xml.internal.ws.message.DataHandlerAttachment;
    40 import javax.xml.ws.handler.soap.SOAPHandler;
    41 import javax.xml.ws.handler.MessageContext;
    42 import javax.xml.ws.handler.Handler;
    43 import javax.xml.ws.WebServiceException;
    44 import javax.activation.DataHandler;
    45 import java.util.*;
    46 import java.util.Map.Entry;
    48 /**
    49  *
    50  * @author WS Development Team
    51  */
    52 public class ClientSOAPHandlerTube extends HandlerTube {
    54     private Set<String> roles;
    56     /**
    57      * Creates a new instance of SOAPHandlerTube
    58      */
    59     public ClientSOAPHandlerTube(WSBinding binding, WSDLPort port, Tube next) {
    60         super(next, port, binding);
    61         if (binding.getSOAPVersion() != null) {
    62             // SOAPHandlerTube should n't be used for bindings other than SOAP.
    63             // TODO: throw Exception
    64         }
    65     }
    67     // Handle to LogicalHandlerTube means its used on SERVER-SIDE
    69     /**
    70      * This constructor is used on client-side where, LogicalHandlerTube is created
    71      * first and then a SOAPHandlerTube is created with a handler to that
    72      * LogicalHandlerTube.
    73      * With this handle, SOAPHandlerTube can call LogicalHandlerTube.closeHandlers()
    74      */
    75     public ClientSOAPHandlerTube(WSBinding binding, Tube next, HandlerTube cousinTube) {
    76         super(next, cousinTube, binding);
    77     }
    79     /**
    80      * Copy constructor for {@link com.sun.xml.internal.ws.api.pipe.Tube#copy(com.sun.xml.internal.ws.api.pipe.TubeCloner)}.
    81      */
    82     private ClientSOAPHandlerTube(ClientSOAPHandlerTube that, TubeCloner cloner) {
    83         super(that, cloner);
    84     }
    86    public AbstractFilterTubeImpl copy(TubeCloner cloner) {
    87         return new ClientSOAPHandlerTube(this, cloner);
    88     }
    90     void setUpProcessor() {
    91         if (handlers == null) {
    92                 // Take a snapshot, User may change chain after invocation, Same chain
    93                 // should be used for the entire MEP
    94                 handlers = new ArrayList<Handler>();
    95                 HandlerConfiguration handlerConfig = ((BindingImpl) getBinding()).getHandlerConfig();
    96                 List<SOAPHandler> soapSnapShot= handlerConfig.getSoapHandlers();
    97                 if (!soapSnapShot.isEmpty()) {
    98                     handlers.addAll(soapSnapShot);
    99                     roles = new HashSet<String>();
   100                     roles.addAll(handlerConfig.getRoles());
   101                     processor = new SOAPHandlerProcessor(true, this, getBinding(), handlers);
   102                 }
   103         }
   104     }
   106     MessageUpdatableContext getContext(Packet packet) {
   107         SOAPMessageContextImpl context = new SOAPMessageContextImpl(getBinding(), packet,roles);
   108         return context;
   109     }
   111     boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
   113         boolean handlerResult;
   114         //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
   115         Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
   116         AttachmentSet attSet = context.packet.getMessage().getAttachments();
   117         for (Entry<String, DataHandler> entry : atts.entrySet()) {
   118             String cid = entry.getKey();
   119             if (attSet.get(cid) == null) {  // Otherwise we would be adding attachments twice
   120                 Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
   121                 attSet.add(att);
   122             }
   123         }
   125         try {
   126             //CLIENT-SIDE
   127             handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
   128         } catch (WebServiceException wse) {
   129             remedyActionTaken = true;
   130             //no rewrapping
   131             throw wse;
   132         } catch (RuntimeException re) {
   133             remedyActionTaken = true;
   135             throw new WebServiceException(re);
   137         }
   138         if (!handlerResult) {
   139             remedyActionTaken = true;
   140         }
   141         return handlerResult;
   142     }
   144     void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
   145         try {
   147             //CLIENT-SIDE
   148             processor.callHandlersResponse(HandlerProcessor.Direction.INBOUND, context, handleFault);
   150         } catch (WebServiceException wse) {
   151             //no rewrapping
   152             throw wse;
   153         } catch (RuntimeException re) {
   154             throw new WebServiceException(re);
   155         }
   156     }
   158     void closeHandlers(MessageContext mc) {
   159         closeClientsideHandlers(mc);
   161     }
   162 }

mercurial