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

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

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

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.client.sei;
aoqi@0 27
aoqi@0 28 import com.sun.istack.internal.NotNull;
aoqi@0 29 import com.sun.istack.internal.Nullable;
aoqi@0 30 import com.sun.xml.internal.ws.api.SOAPVersion;
aoqi@0 31 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
aoqi@0 32 import com.sun.xml.internal.ws.api.client.WSPortInfo;
aoqi@0 33 import com.sun.xml.internal.ws.api.databinding.Databinding;
aoqi@0 34 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
aoqi@0 35 import com.sun.xml.internal.ws.api.message.Header;
aoqi@0 36 import com.sun.xml.internal.ws.api.message.Headers;
aoqi@0 37 import com.sun.xml.internal.ws.api.message.Packet;
aoqi@0 38 import com.sun.xml.internal.ws.api.model.MEP;
aoqi@0 39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
aoqi@0 40 import com.sun.xml.internal.ws.api.pipe.Fiber;
aoqi@0 41 import com.sun.xml.internal.ws.api.pipe.Tube;
aoqi@0 42 import com.sun.xml.internal.ws.api.server.Container;
aoqi@0 43 import com.sun.xml.internal.ws.api.server.ContainerResolver;
aoqi@0 44 import com.sun.xml.internal.ws.binding.BindingImpl;
aoqi@0 45 import com.sun.xml.internal.ws.client.AsyncResponseImpl;
aoqi@0 46 import com.sun.xml.internal.ws.client.RequestContext;
aoqi@0 47 import com.sun.xml.internal.ws.client.ResponseContextReceiver;
aoqi@0 48 import com.sun.xml.internal.ws.client.Stub;
aoqi@0 49 import com.sun.xml.internal.ws.client.WSServiceDelegate;
aoqi@0 50 import com.sun.xml.internal.ws.model.JavaMethodImpl;
aoqi@0 51 import com.sun.xml.internal.ws.model.SOAPSEIModel;
aoqi@0 52 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
aoqi@0 53
aoqi@0 54 import javax.xml.namespace.QName;
aoqi@0 55 import java.lang.reflect.InvocationHandler;
aoqi@0 56 import java.lang.reflect.InvocationTargetException;
aoqi@0 57 import java.lang.reflect.Method;
aoqi@0 58 import java.lang.reflect.Modifier;
aoqi@0 59 import java.lang.reflect.Proxy;
aoqi@0 60 import java.util.HashMap;
aoqi@0 61 import java.util.Map;
aoqi@0 62
aoqi@0 63 /**
aoqi@0 64 * {@link Stub} that handles method invocations
aoqi@0 65 * through a strongly-typed endpoint interface.
aoqi@0 66 *
aoqi@0 67 * @author Kohsuke Kawaguchi
aoqi@0 68 */
aoqi@0 69 public final class SEIStub extends Stub implements InvocationHandler {
aoqi@0 70
aoqi@0 71 Databinding databinding;
aoqi@0 72
aoqi@0 73 @Deprecated
aoqi@0 74 public SEIStub(WSServiceDelegate owner, BindingImpl binding, SOAPSEIModel seiModel, Tube master, WSEndpointReference epr) {
aoqi@0 75 super(owner, master, binding, seiModel.getPort(), seiModel.getPort().getAddress(), epr);
aoqi@0 76 this.seiModel = seiModel;
aoqi@0 77 this.soapVersion = binding.getSOAPVersion();
aoqi@0 78 databinding = seiModel.getDatabinding();
aoqi@0 79 initMethodHandlers();
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 // added portInterface to the constructor, otherwise AsyncHandler won't work
aoqi@0 83 public SEIStub(WSPortInfo portInfo, BindingImpl binding, SOAPSEIModel seiModel, WSEndpointReference epr) {
aoqi@0 84 super(portInfo, binding, seiModel.getPort().getAddress(),epr);
aoqi@0 85 this.seiModel = seiModel;
aoqi@0 86 this.soapVersion = binding.getSOAPVersion();
aoqi@0 87 databinding = seiModel.getDatabinding();
aoqi@0 88 initMethodHandlers();
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 private void initMethodHandlers() {
aoqi@0 92 Map<WSDLBoundOperation, JavaMethodImpl> syncs = new HashMap<WSDLBoundOperation, JavaMethodImpl>();
aoqi@0 93
aoqi@0 94 // fill in methodHandlers.
aoqi@0 95 // first fill in sychronized versions
aoqi@0 96 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
aoqi@0 97 if (!m.getMEP().isAsync) {
aoqi@0 98 SyncMethodHandler handler = new SyncMethodHandler(this, m);
aoqi@0 99 syncs.put(m.getOperation(), m);
aoqi@0 100 methodHandlers.put(m.getMethod(), handler);
aoqi@0 101 }
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
aoqi@0 105 JavaMethodImpl sync = syncs.get(jm.getOperation());
aoqi@0 106 if (jm.getMEP() == MEP.ASYNC_CALLBACK) {
aoqi@0 107 Method m = jm.getMethod();
aoqi@0 108 CallbackMethodHandler handler = new CallbackMethodHandler(
aoqi@0 109 this, m, m.getParameterTypes().length - 1);
aoqi@0 110 methodHandlers.put(m, handler);
aoqi@0 111 }
aoqi@0 112 if (jm.getMEP() == MEP.ASYNC_POLL) {
aoqi@0 113 Method m = jm.getMethod();
aoqi@0 114 PollingMethodHandler handler = new PollingMethodHandler(this, m);
aoqi@0 115 methodHandlers.put(m, handler);
aoqi@0 116 }
aoqi@0 117 }
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 public final SOAPSEIModel seiModel;
aoqi@0 121
aoqi@0 122 public final SOAPVersion soapVersion;
aoqi@0 123
aoqi@0 124 /**
aoqi@0 125 * Nullable when there is no associated WSDL Model
aoqi@0 126 * @return
aoqi@0 127 */
aoqi@0 128 public @Nullable
aoqi@0 129 OperationDispatcher getOperationDispatcher() {
aoqi@0 130 if(operationDispatcher == null && wsdlPort != null)
aoqi@0 131 operationDispatcher = new OperationDispatcher(wsdlPort,binding,seiModel);
aoqi@0 132 return operationDispatcher;
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 /**
aoqi@0 136 * For each method on the port interface we have
aoqi@0 137 * a {@link MethodHandler} that processes it.
aoqi@0 138 */
aoqi@0 139 private final Map<Method, MethodHandler> methodHandlers = new HashMap<Method, MethodHandler>();
aoqi@0 140
aoqi@0 141 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
aoqi@0 142 validateInputs(proxy, method);
aoqi@0 143 Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
aoqi@0 144 try {
aoqi@0 145 MethodHandler handler = methodHandlers.get(method);
aoqi@0 146 if (handler != null) {
aoqi@0 147 return handler.invoke(proxy, args);
aoqi@0 148 } else {
aoqi@0 149 // we handle the other method invocations by ourselves
aoqi@0 150 try {
aoqi@0 151 return method.invoke(this, args);
aoqi@0 152 } catch (IllegalAccessException e) {
aoqi@0 153 // impossible
aoqi@0 154 throw new AssertionError(e);
aoqi@0 155 } catch (IllegalArgumentException e) {
aoqi@0 156 throw new AssertionError(e);
aoqi@0 157 } catch (InvocationTargetException e) {
aoqi@0 158 throw e.getCause();
aoqi@0 159 }
aoqi@0 160 }
aoqi@0 161 } finally {
aoqi@0 162 ContainerResolver.getDefault().exitContainer(old);
aoqi@0 163 }
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 private void validateInputs(Object proxy, Method method) {
aoqi@0 167 if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
aoqi@0 168 throw new IllegalStateException("Passed object is not proxy!");
aoqi@0 169 }
aoqi@0 170 Class<?> declaringClass = method.getDeclaringClass();
aoqi@0 171 if (method == null || declaringClass == null
aoqi@0 172 || Modifier.isStatic(method.getModifiers())) {
aoqi@0 173 throw new IllegalStateException("Invoking static method is not allowed!");
aoqi@0 174 }
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 public final Packet doProcess(Packet request, RequestContext rc, ResponseContextReceiver receiver) {
aoqi@0 178 return super.process(request, rc, receiver);
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 public final void doProcessAsync(AsyncResponseImpl<?> receiver, Packet request, RequestContext rc, Fiber.CompletionCallback callback) {
aoqi@0 182 super.processAsync(receiver, request, rc, callback);
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 protected final @NotNull QName getPortName() {
aoqi@0 186 return wsdlPort.getName();
aoqi@0 187 }
aoqi@0 188
aoqi@0 189
aoqi@0 190 public void setOutboundHeaders(Object... headers) {
aoqi@0 191 if(headers==null)
aoqi@0 192 throw new IllegalArgumentException();
aoqi@0 193 Header[] hl = new Header[headers.length];
aoqi@0 194 for( int i=0; i<hl.length; i++ ) {
aoqi@0 195 if(headers[i]==null)
aoqi@0 196 throw new IllegalArgumentException();
aoqi@0 197 hl[i] = Headers.create(seiModel.getBindingContext(),headers[i]);
aoqi@0 198 }
aoqi@0 199 super.setOutboundHeaders(hl);
aoqi@0 200 }
aoqi@0 201 }

mercurial