Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
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.db; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.IOException; |
aoqi@0 | 29 | import java.io.InputStream; |
aoqi@0 | 30 | import java.io.OutputStream; |
aoqi@0 | 31 | import java.lang.reflect.Method; |
aoqi@0 | 32 | import java.util.HashMap; |
aoqi@0 | 33 | import java.util.Map; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 36 | |
aoqi@0 | 37 | import com.oracle.webservices.internal.api.databinding.JavaCallInfo; |
aoqi@0 | 38 | import com.oracle.webservices.internal.api.message.MessageContext; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.api.databinding.Databinding; |
aoqi@0 | 42 | import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; |
aoqi@0 | 43 | import com.sun.xml.internal.ws.api.databinding.ClientCallBridge; |
aoqi@0 | 44 | import com.sun.xml.internal.ws.api.message.Message; |
aoqi@0 | 45 | import com.sun.xml.internal.ws.api.message.MessageContextFactory; |
aoqi@0 | 46 | import com.sun.xml.internal.ws.api.message.Packet; |
aoqi@0 | 47 | import com.sun.xml.internal.ws.api.model.MEP; |
aoqi@0 | 48 | import com.sun.xml.internal.ws.api.model.SEIModel; |
aoqi@0 | 49 | import com.sun.xml.internal.ws.api.model.WSDLOperationMapping; |
aoqi@0 | 50 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
aoqi@0 | 51 | import com.sun.xml.internal.ws.api.pipe.Codec; |
aoqi@0 | 52 | import com.sun.xml.internal.ws.api.pipe.ContentType; |
aoqi@0 | 53 | import com.sun.xml.internal.ws.binding.BindingImpl; |
aoqi@0 | 54 | import com.sun.xml.internal.ws.client.sei.StubAsyncHandler; |
aoqi@0 | 55 | import com.sun.xml.internal.ws.client.sei.StubHandler; |
aoqi@0 | 56 | import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; |
aoqi@0 | 57 | import com.sun.xml.internal.ws.model.JavaMethodImpl; |
aoqi@0 | 58 | import com.sun.xml.internal.ws.model.RuntimeModeler; |
aoqi@0 | 59 | import com.sun.xml.internal.ws.server.sei.TieHandler; |
aoqi@0 | 60 | import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature; |
aoqi@0 | 61 | import com.sun.xml.internal.ws.wsdl.DispatchException; |
aoqi@0 | 62 | import com.sun.xml.internal.ws.wsdl.OperationDispatcher; |
aoqi@0 | 63 | |
aoqi@0 | 64 | /** |
aoqi@0 | 65 | * WsRuntimeImpl is the databinding processor built on SEIModel |
aoqi@0 | 66 | * |
aoqi@0 | 67 | * @author shih-chang.chen@oracle.com |
aoqi@0 | 68 | */ |
aoqi@0 | 69 | public final class DatabindingImpl implements Databinding { |
aoqi@0 | 70 | |
aoqi@0 | 71 | AbstractSEIModelImpl seiModel; |
aoqi@0 | 72 | Map<Method, StubHandler> stubHandlers; |
aoqi@0 | 73 | // QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>(); |
aoqi@0 | 74 | Map<JavaMethodImpl, TieHandler> wsdlOpMap = new HashMap<JavaMethodImpl, TieHandler>(); |
aoqi@0 | 75 | Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>(); |
aoqi@0 | 76 | OperationDispatcher operationDispatcher; |
aoqi@0 | 77 | OperationDispatcher operationDispatcherNoWsdl; |
aoqi@0 | 78 | boolean clientConfig = false; |
aoqi@0 | 79 | Codec codec; |
aoqi@0 | 80 | MessageContextFactory packetFactory = null; |
aoqi@0 | 81 | |
aoqi@0 | 82 | public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) { |
aoqi@0 | 83 | RuntimeModeler modeler = new RuntimeModeler(config); |
aoqi@0 | 84 | modeler.setClassLoader(config.getClassLoader()); |
aoqi@0 | 85 | seiModel = modeler.buildRuntimeModel(); |
aoqi@0 | 86 | WSDLPort wsdlport = config.getWsdlPort(); |
aoqi@0 | 87 | packetFactory = new MessageContextFactory(seiModel.getWSBinding().getFeatures()); |
aoqi@0 | 88 | clientConfig = isClientConfig(config); |
aoqi@0 | 89 | if (clientConfig) { |
aoqi@0 | 90 | initStubHandlers(); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | seiModel.setDatabinding(this); |
aoqi@0 | 93 | if (wsdlport != null) { |
aoqi@0 | 94 | freeze(wsdlport); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | if (operationDispatcher == null) { |
aoqi@0 | 97 | operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | // if(!clientConfig) { |
aoqi@0 | 100 | for (JavaMethodImpl jm : seiModel.getJavaMethods()) { |
aoqi@0 | 101 | if (!jm.isAsync()) { |
aoqi@0 | 102 | TieHandler th = new TieHandler(jm, seiModel.getWSBinding(), packetFactory); |
aoqi@0 | 103 | wsdlOpMap.put(jm, th); |
aoqi@0 | 104 | tieHandlers.put(th.getMethod(), th); |
aoqi@0 | 105 | } |
aoqi@0 | 106 | } |
aoqi@0 | 107 | // } |
aoqi@0 | 108 | } |
aoqi@0 | 109 | |
aoqi@0 | 110 | //TODO isClientConfig |
aoqi@0 | 111 | private boolean isClientConfig(DatabindingConfig config) { |
aoqi@0 | 112 | if (config.getContractClass() == null) { |
aoqi@0 | 113 | return false; |
aoqi@0 | 114 | } |
aoqi@0 | 115 | if (!config.getContractClass().isInterface()) { |
aoqi@0 | 116 | return false; |
aoqi@0 | 117 | } |
aoqi@0 | 118 | return (config.getEndpointClass() == null || config.getEndpointClass().isInterface()); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | //TODO fix freeze |
aoqi@0 | 121 | |
aoqi@0 | 122 | public void freeze(WSDLPort port) { |
aoqi@0 | 123 | if (clientConfig) { |
aoqi@0 | 124 | return; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | synchronized(this) { |
aoqi@0 | 127 | if (operationDispatcher == null) { |
aoqi@0 | 128 | operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel); |
aoqi@0 | 129 | } |
aoqi@0 | 130 | } |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | public SEIModel getModel() { |
aoqi@0 | 134 | return seiModel; |
aoqi@0 | 135 | } |
aoqi@0 | 136 | //Refactored from SEIStub |
aoqi@0 | 137 | |
aoqi@0 | 138 | private void initStubHandlers() { |
aoqi@0 | 139 | stubHandlers = new HashMap<Method, StubHandler>(); |
aoqi@0 | 140 | Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>(); |
aoqi@0 | 141 | // fill in methodHandlers. |
aoqi@0 | 142 | // first fill in sychronized versions |
aoqi@0 | 143 | for (JavaMethodImpl m : seiModel.getJavaMethods()) { |
aoqi@0 | 144 | if (!m.getMEP().isAsync) { |
aoqi@0 | 145 | StubHandler handler = new StubHandler(m, packetFactory); |
aoqi@0 | 146 | syncs.put(m.getOperationSignature(), m); |
aoqi@0 | 147 | stubHandlers.put(m.getMethod(), handler); |
aoqi@0 | 148 | } |
aoqi@0 | 149 | } |
aoqi@0 | 150 | for (JavaMethodImpl jm : seiModel.getJavaMethods()) { |
aoqi@0 | 151 | JavaMethodImpl sync = syncs.get(jm.getOperationSignature()); |
aoqi@0 | 152 | if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) { |
aoqi@0 | 153 | Method m = jm.getMethod(); |
aoqi@0 | 154 | StubAsyncHandler handler = new StubAsyncHandler(jm, sync, packetFactory); |
aoqi@0 | 155 | stubHandlers.put(m, handler); |
aoqi@0 | 156 | } |
aoqi@0 | 157 | } |
aoqi@0 | 158 | } |
aoqi@0 | 159 | |
aoqi@0 | 160 | JavaMethodImpl resolveJavaMethod(Packet req) throws DispatchException { |
aoqi@0 | 161 | WSDLOperationMapping m = req.getWSDLOperationMapping(); |
aoqi@0 | 162 | if (m == null) { |
aoqi@0 | 163 | synchronized (this) { |
aoqi@0 | 164 | m = (operationDispatcher != null) |
aoqi@0 | 165 | ? operationDispatcher.getWSDLOperationMapping(req) |
aoqi@0 | 166 | : operationDispatcherNoWsdl.getWSDLOperationMapping(req); |
aoqi@0 | 167 | } |
aoqi@0 | 168 | } |
aoqi@0 | 169 | return (JavaMethodImpl) m.getJavaMethod(); |
aoqi@0 | 170 | } |
aoqi@0 | 171 | |
aoqi@0 | 172 | public JavaCallInfo deserializeRequest(Packet req) { |
aoqi@0 | 173 | com.sun.xml.internal.ws.api.databinding.JavaCallInfo call = new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(); |
aoqi@0 | 174 | try { |
aoqi@0 | 175 | JavaMethodImpl wsdlOp = resolveJavaMethod(req); |
aoqi@0 | 176 | TieHandler tie = wsdlOpMap.get(wsdlOp); |
aoqi@0 | 177 | call.setMethod(tie.getMethod()); |
aoqi@0 | 178 | Object[] args = tie.readRequest(req.getMessage()); |
aoqi@0 | 179 | call.setParameters(args); |
aoqi@0 | 180 | } catch (DispatchException e) { |
aoqi@0 | 181 | call.setException(e); |
aoqi@0 | 182 | } |
aoqi@0 | 183 | return call; |
aoqi@0 | 184 | } |
aoqi@0 | 185 | |
aoqi@0 | 186 | public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) { |
aoqi@0 | 187 | StubHandler stubHandler = stubHandlers.get(call.getMethod()); |
aoqi@0 | 188 | try { |
aoqi@0 | 189 | return stubHandler.readResponse(res, call); |
aoqi@0 | 190 | } catch (Throwable e) { |
aoqi@0 | 191 | call.setException(e); |
aoqi@0 | 192 | return call; |
aoqi@0 | 193 | } |
aoqi@0 | 194 | } |
aoqi@0 | 195 | |
aoqi@0 | 196 | public WebServiceFeature[] getFeatures() { |
aoqi@0 | 197 | // TODO Auto-generated method stub |
aoqi@0 | 198 | return null; |
aoqi@0 | 199 | } |
aoqi@0 | 200 | |
aoqi@0 | 201 | @Override |
aoqi@0 | 202 | public Packet serializeRequest(JavaCallInfo call) { |
aoqi@0 | 203 | StubHandler stubHandler = stubHandlers.get(call.getMethod()); |
aoqi@0 | 204 | Packet p = stubHandler.createRequestPacket(call); |
aoqi@0 | 205 | p.setState(Packet.State.ClientRequest); |
aoqi@0 | 206 | return p; |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | @Override |
aoqi@0 | 210 | public Packet serializeResponse(JavaCallInfo call) { |
aoqi@0 | 211 | Method method = call.getMethod(); |
aoqi@0 | 212 | Message message = null; |
aoqi@0 | 213 | if (method != null) { |
aoqi@0 | 214 | TieHandler th = tieHandlers.get(method); |
aoqi@0 | 215 | if (th != null) { |
aoqi@0 | 216 | return th.serializeResponse(call); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | } |
aoqi@0 | 219 | if (call.getException() instanceof DispatchException) { |
aoqi@0 | 220 | message = ((DispatchException) call.getException()).fault; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | Packet p = (Packet) packetFactory.createContext(message); |
aoqi@0 | 223 | p.setState(Packet.State.ServerResponse); |
aoqi@0 | 224 | return p; |
aoqi@0 | 225 | } |
aoqi@0 | 226 | |
aoqi@0 | 227 | @Override |
aoqi@0 | 228 | public ClientCallBridge getClientBridge(Method method) { |
aoqi@0 | 229 | return stubHandlers.get(method); |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | @Override |
aoqi@0 | 233 | public void generateWSDL(WSDLGenInfo info) { |
aoqi@0 | 234 | com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator( |
aoqi@0 | 235 | seiModel, |
aoqi@0 | 236 | info.getWsdlResolver(), |
aoqi@0 | 237 | seiModel.getWSBinding(), |
aoqi@0 | 238 | info.getContainer(), seiModel.getEndpointClass(), |
aoqi@0 | 239 | info.isInlineSchemas(), |
aoqi@0 | 240 | info.isSecureXmlProcessingDisabled(), |
aoqi@0 | 241 | info.getExtensions()); |
aoqi@0 | 242 | wsdlGen.doGeneration(); |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | @Override |
aoqi@0 | 246 | public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException { |
aoqi@0 | 247 | JavaMethodImpl wsdlOp = resolveJavaMethod(req); |
aoqi@0 | 248 | return wsdlOpMap.get(wsdlOp); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | Codec getCodec() { |
aoqi@0 | 252 | if (codec == null) { |
aoqi@0 | 253 | codec = ((BindingImpl) seiModel.getWSBinding()).createCodec(); |
aoqi@0 | 254 | } |
aoqi@0 | 255 | return codec; |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | @Override |
aoqi@0 | 259 | public ContentType encode(Packet packet, OutputStream out) throws IOException { |
aoqi@0 | 260 | return getCodec().encode(packet, out); |
aoqi@0 | 261 | } |
aoqi@0 | 262 | |
aoqi@0 | 263 | @Override |
aoqi@0 | 264 | public void decode(InputStream in, String ct, Packet p) throws IOException { |
aoqi@0 | 265 | getCodec().decode(in, ct, p); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | |
aoqi@0 | 268 | @Override |
aoqi@0 | 269 | public com.oracle.webservices.internal.api.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) { |
aoqi@0 | 270 | return new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(method, args); |
aoqi@0 | 271 | } |
aoqi@0 | 272 | |
aoqi@0 | 273 | @Override |
aoqi@0 | 274 | public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeResponse( |
aoqi@0 | 275 | MessageContext message, com.oracle.webservices.internal.api.databinding.JavaCallInfo call) { |
aoqi@0 | 276 | return deserializeResponse((Packet) message, (JavaCallInfo) call); |
aoqi@0 | 277 | } |
aoqi@0 | 278 | |
aoqi@0 | 279 | @Override |
aoqi@0 | 280 | public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeRequest(MessageContext message) { |
aoqi@0 | 281 | return deserializeRequest((Packet) message); |
aoqi@0 | 282 | } |
aoqi@0 | 283 | |
aoqi@0 | 284 | @Override |
aoqi@0 | 285 | public MessageContextFactory getMessageContextFactory() { |
aoqi@0 | 286 | return packetFactory; |
aoqi@0 | 287 | } |
aoqi@0 | 288 | } |