src/share/jaxws_classes/com/sun/xml/internal/ws/client/sei/SEIStub.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/client/sei/SEIStub.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,176 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, 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.client.sei;
    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.SOAPVersion;
    1.34 +import com.sun.xml.internal.ws.api.client.WSPortInfo;
    1.35 +import com.sun.xml.internal.ws.api.databinding.Databinding;
    1.36 +import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
    1.37 +import com.sun.xml.internal.ws.api.message.Header;
    1.38 +import com.sun.xml.internal.ws.api.message.Headers;
    1.39 +import com.sun.xml.internal.ws.api.message.Packet;
    1.40 +import com.sun.xml.internal.ws.api.model.MEP;
    1.41 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    1.42 +import com.sun.xml.internal.ws.api.pipe.Tube;
    1.43 +import com.sun.xml.internal.ws.api.pipe.Fiber;
    1.44 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.45 +import com.sun.xml.internal.ws.client.AsyncResponseImpl;
    1.46 +import com.sun.xml.internal.ws.client.*;
    1.47 +import com.sun.xml.internal.ws.model.JavaMethodImpl;
    1.48 +import com.sun.xml.internal.ws.model.SOAPSEIModel;
    1.49 +import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
    1.50 +
    1.51 +import javax.xml.namespace.QName;
    1.52 +import java.lang.reflect.InvocationHandler;
    1.53 +import java.lang.reflect.InvocationTargetException;
    1.54 +import java.lang.reflect.Method;
    1.55 +import java.util.HashMap;
    1.56 +import java.util.Map;
    1.57 +
    1.58 +/**
    1.59 + * {@link Stub} that handles method invocations
    1.60 + * through a strongly-typed endpoint interface.
    1.61 + *
    1.62 + * @author Kohsuke Kawaguchi
    1.63 + */
    1.64 +public final class SEIStub extends Stub implements InvocationHandler {
    1.65 +
    1.66 +        Databinding databinding;
    1.67 +
    1.68 +    @Deprecated
    1.69 +    public SEIStub(WSServiceDelegate owner, BindingImpl binding, SOAPSEIModel seiModel, Tube master, WSEndpointReference epr) {
    1.70 +        super(owner, master, binding, seiModel.getPort(), seiModel.getPort().getAddress(), epr);
    1.71 +        this.seiModel = seiModel;
    1.72 +        this.soapVersion = binding.getSOAPVersion();
    1.73 +        databinding = seiModel.getDatabinding();
    1.74 +        initMethodHandlers();
    1.75 +    }
    1.76 +
    1.77 +    // added portInterface to the constructor, otherwise AsyncHandler won't work
    1.78 +    public SEIStub(WSPortInfo portInfo, BindingImpl binding, SOAPSEIModel seiModel, WSEndpointReference epr) {
    1.79 +        super(portInfo, binding, seiModel.getPort().getAddress(),epr);
    1.80 +        this.seiModel = seiModel;
    1.81 +        this.soapVersion = binding.getSOAPVersion();
    1.82 +        databinding = seiModel.getDatabinding();
    1.83 +        initMethodHandlers();
    1.84 +    }
    1.85 +
    1.86 +    private void initMethodHandlers() {
    1.87 +        Map<WSDLBoundOperation, JavaMethodImpl> syncs = new HashMap<WSDLBoundOperation, JavaMethodImpl>();
    1.88 +
    1.89 +        // fill in methodHandlers.
    1.90 +        // first fill in sychronized versions
    1.91 +        for (JavaMethodImpl m : seiModel.getJavaMethods()) {
    1.92 +            if (!m.getMEP().isAsync) {
    1.93 +                SyncMethodHandler handler = new SyncMethodHandler(this, m.getMethod());
    1.94 +                syncs.put(m.getOperation(), m);
    1.95 +                methodHandlers.put(m.getMethod(), handler);
    1.96 +            }
    1.97 +        }
    1.98 +
    1.99 +        for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
   1.100 +            JavaMethodImpl sync = syncs.get(jm.getOperation());
   1.101 +            if (jm.getMEP() == MEP.ASYNC_CALLBACK) {
   1.102 +                Method m = jm.getMethod();
   1.103 +                CallbackMethodHandler handler = new CallbackMethodHandler(
   1.104 +                        this, m, m.getParameterTypes().length - 1);
   1.105 +                methodHandlers.put(m, handler);
   1.106 +            }
   1.107 +            if (jm.getMEP() == MEP.ASYNC_POLL) {
   1.108 +                Method m = jm.getMethod();
   1.109 +                PollingMethodHandler handler = new PollingMethodHandler(this, m);
   1.110 +                methodHandlers.put(m, handler);
   1.111 +            }
   1.112 +        }
   1.113 +    }
   1.114 +
   1.115 +    public final SOAPSEIModel seiModel;
   1.116 +
   1.117 +    public final SOAPVersion soapVersion;
   1.118 +
   1.119 +    /**
   1.120 +     * Nullable when there is no associated WSDL Model
   1.121 +     * @return
   1.122 +     */
   1.123 +    public @Nullable
   1.124 +    OperationDispatcher getOperationDispatcher() {
   1.125 +        if(operationDispatcher == null && wsdlPort != null)
   1.126 +            operationDispatcher = new OperationDispatcher(wsdlPort,binding,seiModel);
   1.127 +        return operationDispatcher;
   1.128 +    }
   1.129 +
   1.130 +    /**
   1.131 +     * For each method on the port interface we have
   1.132 +     * a {@link MethodHandler} that processes it.
   1.133 +     */
   1.134 +    private final Map<Method, MethodHandler> methodHandlers = new HashMap<Method, MethodHandler>();
   1.135 +
   1.136 +    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   1.137 +        MethodHandler handler = methodHandlers.get(method);
   1.138 +        if (handler != null) {
   1.139 +            return handler.invoke(proxy, args);
   1.140 +        } else {
   1.141 +            // we handle the other method invocations by ourselves
   1.142 +            try {
   1.143 +                return method.invoke(this, args);
   1.144 +            } catch (IllegalAccessException e) {
   1.145 +                // impossible
   1.146 +                throw new AssertionError(e);
   1.147 +            } catch (IllegalArgumentException e) {
   1.148 +                throw new AssertionError(e);
   1.149 +            } catch (InvocationTargetException e) {
   1.150 +                throw e.getCause();
   1.151 +            }
   1.152 +        }
   1.153 +    }
   1.154 +
   1.155 +    public final Packet doProcess(Packet request, RequestContext rc, ResponseContextReceiver receiver) {
   1.156 +        return super.process(request, rc, receiver);
   1.157 +    }
   1.158 +
   1.159 +    public final void doProcessAsync(AsyncResponseImpl<?> receiver, Packet request, RequestContext rc, Fiber.CompletionCallback callback) {
   1.160 +        super.processAsync(receiver, request, rc, callback);
   1.161 +    }
   1.162 +
   1.163 +    protected final @NotNull QName getPortName() {
   1.164 +        return wsdlPort.getName();
   1.165 +    }
   1.166 +
   1.167 +
   1.168 +    public void setOutboundHeaders(Object... headers) {
   1.169 +        if(headers==null)
   1.170 +            throw new IllegalArgumentException();
   1.171 +        Header[] hl = new Header[headers.length];
   1.172 +        for( int i=0; i<hl.length; i++ ) {
   1.173 +            if(headers[i]==null)
   1.174 +                throw new IllegalArgumentException();
   1.175 +            hl[i] = Headers.create(seiModel.getBindingContext(),headers[i]);
   1.176 +        }
   1.177 +        super.setOutboundHeaders(hl);
   1.178 +    }
   1.179 +}

mercurial