src/share/jaxws_classes/com/sun/xml/internal/ws/db/DatabindingImpl.java

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 384
8f2986ff0235
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.db;
ohair@286 27
ohair@286 28 import java.io.IOException;
ohair@286 29 import java.io.InputStream;
ohair@286 30 import java.io.OutputStream;
ohair@286 31 import java.lang.reflect.Method;
ohair@286 32 import java.util.HashMap;
ohair@286 33 import java.util.Map;
ohair@286 34
ohair@286 35 import javax.xml.ws.WebServiceFeature;
ohair@286 36
alanb@368 37 import com.oracle.webservices.internal.api.databinding.JavaCallInfo;
alanb@368 38 import com.oracle.webservices.internal.api.message.MessageContext;
ohair@286 39 import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge;
ohair@286 40 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
ohair@286 41 import com.sun.xml.internal.ws.api.databinding.Databinding;
ohair@286 42 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
ohair@286 43 import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
ohair@286 44 import com.sun.xml.internal.ws.api.message.Message;
alanb@368 45 import com.sun.xml.internal.ws.api.message.MessageContextFactory;
ohair@286 46 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 47 import com.sun.xml.internal.ws.api.model.MEP;
ohair@286 48 import com.sun.xml.internal.ws.api.model.SEIModel;
alanb@368 49 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
ohair@286 50 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 51 import com.sun.xml.internal.ws.api.pipe.Codec;
ohair@286 52 import com.sun.xml.internal.ws.api.pipe.ContentType;
ohair@286 53 import com.sun.xml.internal.ws.binding.BindingImpl;
ohair@286 54 import com.sun.xml.internal.ws.client.sei.StubAsyncHandler;
ohair@286 55 import com.sun.xml.internal.ws.client.sei.StubHandler;
ohair@286 56 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
ohair@286 57 import com.sun.xml.internal.ws.model.JavaMethodImpl;
ohair@286 58 import com.sun.xml.internal.ws.model.RuntimeModeler;
ohair@286 59 import com.sun.xml.internal.ws.server.sei.TieHandler;
ohair@286 60 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
ohair@286 61 import com.sun.xml.internal.ws.wsdl.DispatchException;
ohair@286 62 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
ohair@286 63
ohair@286 64 /**
ohair@286 65 * WsRuntimeImpl is the databinding processor built on SEIModel
ohair@286 66 *
ohair@286 67 * @author shih-chang.chen@oracle.com
ohair@286 68 */
mkos@384 69 public final class DatabindingImpl implements Databinding {
ohair@286 70
ohair@286 71 AbstractSEIModelImpl seiModel;
mkos@384 72 Map<Method, StubHandler> stubHandlers;
alanb@368 73 // QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
mkos@384 74 Map<JavaMethodImpl, TieHandler> wsdlOpMap = new HashMap<JavaMethodImpl, TieHandler>();
mkos@384 75 Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>();
ohair@286 76 OperationDispatcher operationDispatcher;
ohair@286 77 OperationDispatcher operationDispatcherNoWsdl;
ohair@286 78 boolean clientConfig = false;
ohair@286 79 Codec codec;
alanb@368 80 MessageContextFactory packetFactory = null;
ohair@286 81
mkos@384 82 public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
mkos@384 83 RuntimeModeler modeler = new RuntimeModeler(config);
mkos@384 84 modeler.setClassLoader(config.getClassLoader());
mkos@384 85 seiModel = modeler.buildRuntimeModel();
mkos@384 86 WSDLPort wsdlport = config.getWsdlPort();
mkos@384 87 packetFactory = new MessageContextFactory(seiModel.getWSBinding().getFeatures());
mkos@384 88 clientConfig = isClientConfig(config);
mkos@384 89 if (clientConfig) {
mkos@384 90 initStubHandlers();
mkos@384 91 }
mkos@384 92 seiModel.setDatabinding(this);
mkos@384 93 if (wsdlport != null) {
mkos@384 94 freeze(wsdlport);
mkos@384 95 }
mkos@384 96 if (operationDispatcher == null) {
mkos@384 97 operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
mkos@384 98 }
ohair@286 99 // if(!clientConfig) {
mkos@384 100 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
mkos@384 101 if (!jm.isAsync()) {
mkos@384 102 TieHandler th = new TieHandler(jm, seiModel.getWSBinding(), packetFactory);
mkos@384 103 wsdlOpMap.put(jm, th);
mkos@384 104 tieHandlers.put(th.getMethod(), th);
mkos@384 105 }
ohair@286 106 }
ohair@286 107 // }
mkos@384 108 }
mkos@384 109
mkos@384 110 //TODO isClientConfig
mkos@384 111 private boolean isClientConfig(DatabindingConfig config) {
mkos@384 112 if (config.getContractClass() == null) {
mkos@384 113 return false;
ohair@286 114 }
mkos@384 115 if (!config.getContractClass().isInterface()) {
mkos@384 116 return false;
mkos@384 117 }
mkos@384 118 return (config.getEndpointClass() == null || config.getEndpointClass().isInterface());
mkos@384 119 }
mkos@384 120 //TODO fix freeze
ohair@286 121
mkos@384 122 public void freeze(WSDLPort port) {
mkos@384 123 if (clientConfig) {
mkos@384 124 return;
ohair@286 125 }
mkos@384 126 synchronized(this) {
mkos@384 127 if (operationDispatcher == null) {
ohair@286 128 operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel);
mkos@384 129 }
ohair@286 130 }
mkos@384 131 }
ohair@286 132
mkos@384 133 public SEIModel getModel() {
mkos@384 134 return seiModel;
mkos@384 135 }
ohair@286 136 //Refactored from SEIStub
mkos@384 137
ohair@286 138 private void initStubHandlers() {
mkos@384 139 stubHandlers = new HashMap<Method, StubHandler>();
ohair@286 140 Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
ohair@286 141 // fill in methodHandlers.
ohair@286 142 // first fill in sychronized versions
ohair@286 143 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
ohair@286 144 if (!m.getMEP().isAsync) {
alanb@368 145 StubHandler handler = new StubHandler(m, packetFactory);
ohair@286 146 syncs.put(m.getOperationSignature(), m);
ohair@286 147 stubHandlers.put(m.getMethod(), handler);
ohair@286 148 }
ohair@286 149 }
ohair@286 150 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
ohair@286 151 JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
ohair@286 152 if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
ohair@286 153 Method m = jm.getMethod();
alanb@368 154 StubAsyncHandler handler = new StubAsyncHandler(jm, sync, packetFactory);
ohair@286 155 stubHandlers.put(m, handler);
ohair@286 156 }
ohair@286 157 }
ohair@286 158 }
ohair@286 159
mkos@384 160 JavaMethodImpl resolveJavaMethod(Packet req) throws DispatchException {
alanb@368 161 WSDLOperationMapping m = req.getWSDLOperationMapping();
mkos@384 162 if (m == null) {
mkos@384 163 synchronized (this) {
mkos@384 164 m = (operationDispatcher != null)
mkos@384 165 ? operationDispatcher.getWSDLOperationMapping(req)
mkos@384 166 : operationDispatcherNoWsdl.getWSDLOperationMapping(req);
mkos@384 167 }
mkos@384 168 }
alanb@368 169 return (JavaMethodImpl) m.getJavaMethod();
ohair@286 170 }
ohair@286 171
mkos@384 172 public JavaCallInfo deserializeRequest(Packet req) {
mkos@384 173 com.sun.xml.internal.ws.api.databinding.JavaCallInfo call = new com.sun.xml.internal.ws.api.databinding.JavaCallInfo();
mkos@384 174 try {
mkos@384 175 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
mkos@384 176 TieHandler tie = wsdlOpMap.get(wsdlOp);
mkos@384 177 call.setMethod(tie.getMethod());
mkos@384 178 Object[] args = tie.readRequest(req.getMessage());
mkos@384 179 call.setParameters(args);
mkos@384 180 } catch (DispatchException e) {
mkos@384 181 call.setException(e);
ohair@286 182 }
mkos@384 183 return call;
mkos@384 184 }
ohair@286 185
mkos@384 186 public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) {
ohair@286 187 StubHandler stubHandler = stubHandlers.get(call.getMethod());
ohair@286 188 try {
ohair@286 189 return stubHandler.readResponse(res, call);
ohair@286 190 } catch (Throwable e) {
ohair@286 191 call.setException(e);
ohair@286 192 return call;
ohair@286 193 }
mkos@384 194 }
ohair@286 195
mkos@384 196 public WebServiceFeature[] getFeatures() {
mkos@384 197 // TODO Auto-generated method stub
mkos@384 198 return null;
mkos@384 199 }
ohair@286 200
mkos@384 201 @Override
mkos@384 202 public Packet serializeRequest(JavaCallInfo call) {
ohair@286 203 StubHandler stubHandler = stubHandlers.get(call.getMethod());
alanb@368 204 Packet p = stubHandler.createRequestPacket(call);
alanb@368 205 p.setState(Packet.State.ClientRequest);
alanb@368 206 return p;
mkos@384 207 }
mkos@384 208
mkos@384 209 @Override
mkos@384 210 public Packet serializeResponse(JavaCallInfo call) {
mkos@384 211 Method method = call.getMethod();
mkos@384 212 Message message = null;
mkos@384 213 if (method != null) {
mkos@384 214 TieHandler th = tieHandlers.get(method);
mkos@384 215 if (th != null) {
mkos@384 216 return th.serializeResponse(call);
mkos@384 217 }
ohair@286 218 }
mkos@384 219 if (call.getException() instanceof DispatchException) {
mkos@384 220 message = ((DispatchException) call.getException()).fault;
mkos@384 221 }
mkos@384 222 Packet p = (Packet) packetFactory.createContext(message);
alanb@368 223 p.setState(Packet.State.ServerResponse);
alanb@368 224 return p;
mkos@384 225 }
mkos@384 226
mkos@384 227 @Override
mkos@384 228 public ClientCallBridge getClientBridge(Method method) {
mkos@384 229 return stubHandlers.get(method);
mkos@384 230 }
mkos@384 231
mkos@384 232 @Override
mkos@384 233 public void generateWSDL(WSDLGenInfo info) {
mkos@384 234 com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator(
mkos@384 235 seiModel,
mkos@384 236 info.getWsdlResolver(),
mkos@384 237 seiModel.getWSBinding(),
mkos@384 238 info.getContainer(), seiModel.getEndpointClass(),
mkos@384 239 info.isInlineSchemas(),
mkos@384 240 info.isSecureXmlProcessingDisabled(),
mkos@384 241 info.getExtensions());
mkos@384 242 wsdlGen.doGeneration();
mkos@384 243 }
mkos@384 244
mkos@384 245 @Override
mkos@384 246 public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
mkos@384 247 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
mkos@384 248 return wsdlOpMap.get(wsdlOp);
mkos@384 249 }
mkos@384 250
mkos@384 251 Codec getCodec() {
mkos@384 252 if (codec == null) {
mkos@384 253 codec = ((BindingImpl) seiModel.getWSBinding()).createCodec();
ohair@286 254 }
mkos@384 255 return codec;
mkos@384 256 }
ohair@286 257
mkos@384 258 @Override
mkos@384 259 public ContentType encode(Packet packet, OutputStream out) throws IOException {
ohair@286 260 return getCodec().encode(packet, out);
ohair@286 261 }
ohair@286 262
mkos@384 263 @Override
mkos@384 264 public void decode(InputStream in, String ct, Packet p) throws IOException {
ohair@286 265 getCodec().decode(in, ct, p);
ohair@286 266 }
ohair@286 267
mkos@384 268 @Override
alanb@368 269 public com.oracle.webservices.internal.api.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
alanb@368 270 return new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(method, args);
ohair@286 271 }
ohair@286 272
mkos@384 273 @Override
alanb@368 274 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeResponse(
alanb@368 275 MessageContext message, com.oracle.webservices.internal.api.databinding.JavaCallInfo call) {
mkos@384 276 return deserializeResponse((Packet) message, (JavaCallInfo) call);
ohair@286 277 }
ohair@286 278
mkos@384 279 @Override
alanb@368 280 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
mkos@384 281 return deserializeRequest((Packet) message);
ohair@286 282 }
ohair@286 283
mkos@384 284 @Override
alanb@368 285 public MessageContextFactory getMessageContextFactory() {
alanb@368 286 return packetFactory;
ohair@286 287 }
ohair@286 288 }

mercurial