src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/ActionBasedOperationFinder.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/wsdl/ActionBasedOperationFinder.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,168 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.wsdl;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.istack.internal.Nullable;
    1.33 +import com.sun.xml.internal.ws.api.WSBinding;
    1.34 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.35 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.36 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    1.37 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    1.38 +import com.sun.xml.internal.ws.api.message.HeaderList;
    1.39 +import com.sun.xml.internal.ws.api.message.Message;
    1.40 +import com.sun.xml.internal.ws.api.message.Messages;
    1.41 +import com.sun.xml.internal.ws.api.message.Packet;
    1.42 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    1.43 +import com.sun.xml.internal.ws.model.JavaMethodImpl;
    1.44 +import static com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.*;
    1.45 +import com.sun.xml.internal.ws.resources.AddressingMessages;
    1.46 +
    1.47 +import javax.xml.namespace.QName;
    1.48 +import java.util.HashMap;
    1.49 +import java.util.Map;
    1.50 +import java.util.logging.Logger;
    1.51 +
    1.52 +/**
    1.53 + * An {@link WSDLOperationFinder} implementation that uses
    1.54 + * WS-Addressing Action Message Addressing Property, <code>wsa:Action</code> and SOAP Payload QName,
    1.55 + * as the key for dispatching.
    1.56 + * <p/>
    1.57 + * This should be used only when AddressingFeature is enabled.
    1.58 + * A map of all {@link ActionBasedOperationSignature}s in the port and the corresponding and the WSDL Operation QNames
    1.59 + * is maintained.
    1.60 + * <p/>
    1.61 + *
    1.62 + * @author Rama Pulavarthi
    1.63 + */
    1.64 +final class ActionBasedOperationFinder extends WSDLOperationFinder {
    1.65 +
    1.66 +    private static final Logger LOGGER = Logger.getLogger(ActionBasedOperationFinder.class.getName());
    1.67 +    private final Map<ActionBasedOperationSignature, QName> uniqueOpSignatureMap;
    1.68 +    private final Map<String, QName> actionMap;
    1.69 +
    1.70 +    private final @NotNull AddressingVersion av;
    1.71 +
    1.72 +    public ActionBasedOperationFinder(WSDLPort wsdlModel, WSBinding binding, @Nullable SEIModel seiModel) {
    1.73 +        super(wsdlModel, binding, seiModel);
    1.74 +
    1.75 +        assert binding.getAddressingVersion() != null;    // this dispatcher can be only used when addressing is on.
    1.76 +        av = binding.getAddressingVersion();
    1.77 +        uniqueOpSignatureMap = new HashMap<ActionBasedOperationSignature, QName>();
    1.78 +        actionMap = new HashMap<String,QName>();
    1.79 +
    1.80 +        if (seiModel != null) {
    1.81 +            for (JavaMethodImpl m : ((AbstractSEIModelImpl) seiModel).getJavaMethods()) {
    1.82 +                if(m.getMEP().isAsync)
    1.83 +                    continue;
    1.84 +
    1.85 +                String action = m.getInputAction();
    1.86 +                QName payloadName = m.getRequestPayloadName();
    1.87 +                if (payloadName == null)
    1.88 +                    payloadName = EMPTY_PAYLOAD;
    1.89 +                //first look at annotations and then in wsdlmodel
    1.90 +                if (action == null || action.equals("")) {
    1.91 +                    if (m.getOperation() != null) action = m.getOperation().getOperation().getInput().getAction();
    1.92 +//                    action = m.getInputAction();
    1.93 +                }
    1.94 +                if (action != null) {
    1.95 +                    ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(action, payloadName);
    1.96 +                    if(uniqueOpSignatureMap.get(opSignature) != null) {
    1.97 +                        LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE(
    1.98 +                                uniqueOpSignatureMap.get(opSignature),m.getOperationQName(),action,payloadName));
    1.99 +                    }
   1.100 +                    uniqueOpSignatureMap.put(opSignature, m.getOperationQName());
   1.101 +                    actionMap.put(action,m.getOperationQName());
   1.102 +                }
   1.103 +            }
   1.104 +        } else {
   1.105 +            for (WSDLBoundOperation wsdlOp : wsdlModel.getBinding().getBindingOperations()) {
   1.106 +                QName payloadName = wsdlOp.getReqPayloadName();
   1.107 +                if (payloadName == null)
   1.108 +                    payloadName = EMPTY_PAYLOAD;
   1.109 +                String action = wsdlOp.getOperation().getInput().getAction();
   1.110 +                ActionBasedOperationSignature opSignature = new ActionBasedOperationSignature(
   1.111 +                        action, payloadName);
   1.112 +                if(uniqueOpSignatureMap.get(opSignature) != null) {
   1.113 +                    LOGGER.warning(AddressingMessages.NON_UNIQUE_OPERATION_SIGNATURE(
   1.114 +                                    uniqueOpSignatureMap.get(opSignature),wsdlOp.getName(),action,payloadName));
   1.115 +
   1.116 +                }
   1.117 +                uniqueOpSignatureMap.put(opSignature, wsdlOp.getName());
   1.118 +                actionMap.put(action,wsdlOp.getName());
   1.119 +            }
   1.120 +        }
   1.121 +    }
   1.122 +
   1.123 +    /**
   1.124 +     *
   1.125 +     * @param request  Request Packet that is used to find the associated WSDLOperation
   1.126 +     * @return WSDL operation Qname.
   1.127 +     *         return null if WS-Addressing is not engaged.
   1.128 +     * @throws DispatchException with WSA defined fault message when it cannot find an associated WSDL operation.
   1.129 +     *
   1.130 +     */
   1.131 +    @Override
   1.132 +    public QName getWSDLOperationQName(Packet request) throws DispatchException {
   1.133 +        HeaderList hl = request.getMessage().getHeaders();
   1.134 +        String action = hl.getAction(av, binding.getSOAPVersion());
   1.135 +
   1.136 +        if (action == null)
   1.137 +            // Addressing is not enagaged, return null to use other ways to dispatch.
   1.138 +            return null;
   1.139 +
   1.140 +        Message message = request.getMessage();
   1.141 +        QName payloadName;
   1.142 +        String localPart = message.getPayloadLocalPart();
   1.143 +        if (localPart == null) {
   1.144 +            payloadName = EMPTY_PAYLOAD;
   1.145 +        } else {
   1.146 +            String nsUri = message.getPayloadNamespaceURI();
   1.147 +            if (nsUri == null)
   1.148 +                nsUri = EMPTY_PAYLOAD_NSURI;
   1.149 +            payloadName = new QName(nsUri, localPart);
   1.150 +        }
   1.151 +
   1.152 +        QName opName = uniqueOpSignatureMap.get(new ActionBasedOperationSignature(action, payloadName));
   1.153 +        if (opName != null)
   1.154 +            return opName;
   1.155 +
   1.156 +        //Seems like in Wstrust STS wsdls, the payload does not match what is specified in the wsdl leading to incorrect
   1.157 +        //  wsdl operation resolution. Use just wsa:Action to dispatch as a last resort.
   1.158 +        //try just with wsa:Action
   1.159 +        opName = actionMap.get(action);
   1.160 +        if (opName != null)
   1.161 +            return opName;
   1.162 +
   1.163 +        // invalid action header
   1.164 +        Message result = Messages.create(action, av, binding.getSOAPVersion());
   1.165 +
   1.166 +        throw new DispatchException(result);
   1.167 +
   1.168 +    }
   1.169 +
   1.170 +
   1.171 +}

mercurial