src/share/jaxws_classes/com/sun/xml/internal/ws/client/sei/SEIStub.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2011, 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.client.sei;
    28 import com.sun.istack.internal.NotNull;
    29 import com.sun.istack.internal.Nullable;
    30 import com.sun.xml.internal.ws.api.SOAPVersion;
    31 import com.sun.xml.internal.ws.api.client.WSPortInfo;
    32 import com.sun.xml.internal.ws.api.databinding.Databinding;
    33 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
    34 import com.sun.xml.internal.ws.api.message.Header;
    35 import com.sun.xml.internal.ws.api.message.Headers;
    36 import com.sun.xml.internal.ws.api.message.Packet;
    37 import com.sun.xml.internal.ws.api.model.MEP;
    38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
    39 import com.sun.xml.internal.ws.api.pipe.Tube;
    40 import com.sun.xml.internal.ws.api.pipe.Fiber;
    41 import com.sun.xml.internal.ws.binding.BindingImpl;
    42 import com.sun.xml.internal.ws.client.AsyncResponseImpl;
    43 import com.sun.xml.internal.ws.client.*;
    44 import com.sun.xml.internal.ws.model.JavaMethodImpl;
    45 import com.sun.xml.internal.ws.model.SOAPSEIModel;
    46 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
    48 import javax.xml.namespace.QName;
    49 import java.lang.reflect.InvocationHandler;
    50 import java.lang.reflect.InvocationTargetException;
    51 import java.lang.reflect.Method;
    52 import java.util.HashMap;
    53 import java.util.Map;
    55 /**
    56  * {@link Stub} that handles method invocations
    57  * through a strongly-typed endpoint interface.
    58  *
    59  * @author Kohsuke Kawaguchi
    60  */
    61 public final class SEIStub extends Stub implements InvocationHandler {
    63         Databinding databinding;
    65     @Deprecated
    66     public SEIStub(WSServiceDelegate owner, BindingImpl binding, SOAPSEIModel seiModel, Tube master, WSEndpointReference epr) {
    67         super(owner, master, binding, seiModel.getPort(), seiModel.getPort().getAddress(), epr);
    68         this.seiModel = seiModel;
    69         this.soapVersion = binding.getSOAPVersion();
    70         databinding = seiModel.getDatabinding();
    71         initMethodHandlers();
    72     }
    74     // added portInterface to the constructor, otherwise AsyncHandler won't work
    75     public SEIStub(WSPortInfo portInfo, BindingImpl binding, SOAPSEIModel seiModel, WSEndpointReference epr) {
    76         super(portInfo, binding, seiModel.getPort().getAddress(),epr);
    77         this.seiModel = seiModel;
    78         this.soapVersion = binding.getSOAPVersion();
    79         databinding = seiModel.getDatabinding();
    80         initMethodHandlers();
    81     }
    83     private void initMethodHandlers() {
    84         Map<WSDLBoundOperation, JavaMethodImpl> syncs = new HashMap<WSDLBoundOperation, JavaMethodImpl>();
    86         // fill in methodHandlers.
    87         // first fill in sychronized versions
    88         for (JavaMethodImpl m : seiModel.getJavaMethods()) {
    89             if (!m.getMEP().isAsync) {
    90                 SyncMethodHandler handler = new SyncMethodHandler(this, m.getMethod());
    91                 syncs.put(m.getOperation(), m);
    92                 methodHandlers.put(m.getMethod(), handler);
    93             }
    94         }
    96         for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
    97             JavaMethodImpl sync = syncs.get(jm.getOperation());
    98             if (jm.getMEP() == MEP.ASYNC_CALLBACK) {
    99                 Method m = jm.getMethod();
   100                 CallbackMethodHandler handler = new CallbackMethodHandler(
   101                         this, m, m.getParameterTypes().length - 1);
   102                 methodHandlers.put(m, handler);
   103             }
   104             if (jm.getMEP() == MEP.ASYNC_POLL) {
   105                 Method m = jm.getMethod();
   106                 PollingMethodHandler handler = new PollingMethodHandler(this, m);
   107                 methodHandlers.put(m, handler);
   108             }
   109         }
   110     }
   112     public final SOAPSEIModel seiModel;
   114     public final SOAPVersion soapVersion;
   116     /**
   117      * Nullable when there is no associated WSDL Model
   118      * @return
   119      */
   120     public @Nullable
   121     OperationDispatcher getOperationDispatcher() {
   122         if(operationDispatcher == null && wsdlPort != null)
   123             operationDispatcher = new OperationDispatcher(wsdlPort,binding,seiModel);
   124         return operationDispatcher;
   125     }
   127     /**
   128      * For each method on the port interface we have
   129      * a {@link MethodHandler} that processes it.
   130      */
   131     private final Map<Method, MethodHandler> methodHandlers = new HashMap<Method, MethodHandler>();
   133     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
   134         MethodHandler handler = methodHandlers.get(method);
   135         if (handler != null) {
   136             return handler.invoke(proxy, args);
   137         } else {
   138             // we handle the other method invocations by ourselves
   139             try {
   140                 return method.invoke(this, args);
   141             } catch (IllegalAccessException e) {
   142                 // impossible
   143                 throw new AssertionError(e);
   144             } catch (IllegalArgumentException e) {
   145                 throw new AssertionError(e);
   146             } catch (InvocationTargetException e) {
   147                 throw e.getCause();
   148             }
   149         }
   150     }
   152     public final Packet doProcess(Packet request, RequestContext rc, ResponseContextReceiver receiver) {
   153         return super.process(request, rc, receiver);
   154     }
   156     public final void doProcessAsync(AsyncResponseImpl<?> receiver, Packet request, RequestContext rc, Fiber.CompletionCallback callback) {
   157         super.processAsync(receiver, request, rc, callback);
   158     }
   160     protected final @NotNull QName getPortName() {
   161         return wsdlPort.getName();
   162     }
   165     public void setOutboundHeaders(Object... headers) {
   166         if(headers==null)
   167             throw new IllegalArgumentException();
   168         Header[] hl = new Header[headers.length];
   169         for( int i=0; i<hl.length; i++ ) {
   170             if(headers[i]==null)
   171                 throw new IllegalArgumentException();
   172             hl[i] = Headers.create(seiModel.getBindingContext(),headers[i]);
   173         }
   174         super.setOutboundHeaders(hl);
   175     }
   176 }

mercurial