Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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 */
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.api.server.Container;
42 import com.sun.xml.internal.ws.api.server.ContainerResolver;
43 import com.sun.xml.internal.ws.binding.BindingImpl;
44 import com.sun.xml.internal.ws.client.*;
45 import com.sun.xml.internal.ws.model.JavaMethodImpl;
46 import com.sun.xml.internal.ws.model.SOAPSEIModel;
47 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
49 import javax.xml.namespace.QName;
50 import java.lang.reflect.InvocationHandler;
51 import java.lang.reflect.InvocationTargetException;
52 import java.lang.reflect.Method;
53 import java.util.HashMap;
54 import java.util.Map;
56 /**
57 * {@link Stub} that handles method invocations
58 * through a strongly-typed endpoint interface.
59 *
60 * @author Kohsuke Kawaguchi
61 */
62 public final class SEIStub extends Stub implements InvocationHandler {
64 Databinding databinding;
66 @Deprecated
67 public SEIStub(WSServiceDelegate owner, BindingImpl binding, SOAPSEIModel seiModel, Tube master, WSEndpointReference epr) {
68 super(owner, master, binding, seiModel.getPort(), seiModel.getPort().getAddress(), epr);
69 this.seiModel = seiModel;
70 this.soapVersion = binding.getSOAPVersion();
71 databinding = seiModel.getDatabinding();
72 initMethodHandlers();
73 }
75 // added portInterface to the constructor, otherwise AsyncHandler won't work
76 public SEIStub(WSPortInfo portInfo, BindingImpl binding, SOAPSEIModel seiModel, WSEndpointReference epr) {
77 super(portInfo, binding, seiModel.getPort().getAddress(),epr);
78 this.seiModel = seiModel;
79 this.soapVersion = binding.getSOAPVersion();
80 databinding = seiModel.getDatabinding();
81 initMethodHandlers();
82 }
84 private void initMethodHandlers() {
85 Map<WSDLBoundOperation, JavaMethodImpl> syncs = new HashMap<WSDLBoundOperation, JavaMethodImpl>();
87 // fill in methodHandlers.
88 // first fill in sychronized versions
89 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
90 if (!m.getMEP().isAsync) {
91 SyncMethodHandler handler = new SyncMethodHandler(this, m.getMethod());
92 syncs.put(m.getOperation(), m);
93 methodHandlers.put(m.getMethod(), handler);
94 }
95 }
97 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
98 JavaMethodImpl sync = syncs.get(jm.getOperation());
99 if (jm.getMEP() == MEP.ASYNC_CALLBACK) {
100 Method m = jm.getMethod();
101 CallbackMethodHandler handler = new CallbackMethodHandler(
102 this, m, m.getParameterTypes().length - 1);
103 methodHandlers.put(m, handler);
104 }
105 if (jm.getMEP() == MEP.ASYNC_POLL) {
106 Method m = jm.getMethod();
107 PollingMethodHandler handler = new PollingMethodHandler(this, m);
108 methodHandlers.put(m, handler);
109 }
110 }
111 }
113 public final SOAPSEIModel seiModel;
115 public final SOAPVersion soapVersion;
117 /**
118 * Nullable when there is no associated WSDL Model
119 * @return
120 */
121 public @Nullable
122 OperationDispatcher getOperationDispatcher() {
123 if(operationDispatcher == null && wsdlPort != null)
124 operationDispatcher = new OperationDispatcher(wsdlPort,binding,seiModel);
125 return operationDispatcher;
126 }
128 /**
129 * For each method on the port interface we have
130 * a {@link MethodHandler} that processes it.
131 */
132 private final Map<Method, MethodHandler> methodHandlers = new HashMap<Method, MethodHandler>();
134 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
135 Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
136 try {
137 MethodHandler handler = methodHandlers.get(method);
138 if (handler != null) {
139 return handler.invoke(proxy, args);
140 } else {
141 // we handle the other method invocations by ourselves
142 try {
143 return method.invoke(this, args);
144 } catch (IllegalAccessException e) {
145 // impossible
146 throw new AssertionError(e);
147 } catch (IllegalArgumentException e) {
148 throw new AssertionError(e);
149 } catch (InvocationTargetException e) {
150 throw e.getCause();
151 }
152 }
153 } finally {
154 ContainerResolver.getDefault().exitContainer(old);
155 }
156 }
158 public final Packet doProcess(Packet request, RequestContext rc, ResponseContextReceiver receiver) {
159 return super.process(request, rc, receiver);
160 }
162 public final void doProcessAsync(AsyncResponseImpl<?> receiver, Packet request, RequestContext rc, Fiber.CompletionCallback callback) {
163 super.processAsync(receiver, request, rc, callback);
164 }
166 protected final @NotNull QName getPortName() {
167 return wsdlPort.getName();
168 }
171 public void setOutboundHeaders(Object... headers) {
172 if(headers==null)
173 throw new IllegalArgumentException();
174 Header[] hl = new Header[headers.length];
175 for( int i=0; i<hl.length; i++ ) {
176 if(headers[i]==null)
177 throw new IllegalArgumentException();
178 hl[i] = Headers.create(seiModel.getBindingContext(),headers[i]);
179 }
180 super.setOutboundHeaders(hl);
181 }
182 }