View Javadoc
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   */
25  
26  package com.sun.xml.internal.ws.wsdl;
27  
28  import com.sun.istack.internal.NotNull;
29  import com.sun.istack.internal.Nullable;
30  import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
31  import com.sun.xml.internal.ws.api.model.SEIModel;
32  import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
33  import com.sun.xml.internal.ws.api.WSBinding;
34  import com.sun.xml.internal.ws.api.message.Packet;
35  import com.sun.xml.internal.ws.api.message.Message;
36  import com.sun.xml.internal.ws.resources.ServerMessages;
37  import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
38  
39  import javax.xml.namespace.QName;
40  import java.util.List;
41  import java.util.ArrayList;
42  import java.text.MessageFormat;
43  
44  /**
45   * This class abstracts the process of identifying the wsdl operation from a SOAP Message request.
46   * This is primarily for dispatching the request messages to an endpoint method.
47   *
48   * Different implementations of {@link WSDLOperationFinder} are used underneath to identify the wsdl operation based on
49   * if AddressingFeature is enabled or not.
50   *
51   * @author Rama Pulavarthi
52   */
53  public class OperationDispatcher {
54      private List<WSDLOperationFinder> opFinders;
55      private WSBinding binding;
56  
57      public OperationDispatcher(@NotNull WSDLPort wsdlModel, @NotNull WSBinding binding, @Nullable SEIModel seiModel) {
58          this.binding = binding;
59          opFinders = new ArrayList<WSDLOperationFinder>();
60          if (binding.getAddressingVersion() != null) {
61              opFinders.add(new ActionBasedOperationFinder(wsdlModel, binding, seiModel));
62          }
63          opFinders.add(new PayloadQNameBasedOperationFinder(wsdlModel, binding, seiModel));
64          opFinders.add(new SOAPActionBasedOperationFinder(wsdlModel, binding, seiModel));
65  
66      }
67  
68      /**
69       * @deprecated use getWSDLOperationMapping(Packet request)
70       * @param request Packet
71       * @return QName of the wsdl operation.
72       * @throws DispatchException if a unique operartion cannot be associated with this packet.
73       */
74      public @NotNull QName getWSDLOperationQName(Packet request) throws DispatchException {
75          WSDLOperationMapping m = getWSDLOperationMapping(request);
76          return m != null ? m.getOperationName() : null;
77      }
78  
79      public @NotNull WSDLOperationMapping getWSDLOperationMapping(Packet request) throws DispatchException {
80          WSDLOperationMapping opName;
81          for(WSDLOperationFinder finder: opFinders) {
82              opName = finder.getWSDLOperationMapping(request);
83              if(opName != null)
84                  return opName;
85          }
86          //No way to dispatch this request
87          String err = MessageFormat.format("Request=[SOAPAction={0},Payload='{'{1}'}'{2}]",
88                  request.soapAction, request.getMessage().getPayloadNamespaceURI(),
89                  request.getMessage().getPayloadLocalPart());
90          String faultString = ServerMessages.DISPATCH_CANNOT_FIND_METHOD(err);
91          Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(
92                  binding.getSOAPVersion(), faultString, binding.getSOAPVersion().faultCodeClient);
93          throw new DispatchException(faultMsg);
94      }
95  }