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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 384
8f2986ff0235
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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 */
alanb@368 69 public class DatabindingImpl implements Databinding {
ohair@286 70
ohair@286 71 AbstractSEIModelImpl seiModel;
ohair@286 72 Map<Method, StubHandler> stubHandlers;
alanb@368 73 // QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
alanb@368 74 Map<JavaMethodImpl, TieHandler> wsdlOpMap = new HashMap<JavaMethodImpl, TieHandler>();
ohair@286 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
ohair@286 82 public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
ohair@286 83 RuntimeModeler modeler = new RuntimeModeler(config);
ohair@286 84 modeler.setClassLoader(config.getClassLoader());
ohair@286 85 seiModel = modeler.buildRuntimeModel();
ohair@286 86 WSDLPort wsdlport = config.getWsdlPort();
alanb@368 87 packetFactory = new MessageContextFactory(seiModel.getWSBinding().getFeatures());
ohair@286 88 clientConfig = isClientConfig(config);
ohair@286 89 if ( clientConfig ) initStubHandlers();
ohair@286 90 seiModel.setDatabinding(this);
ohair@286 91 if (wsdlport != null) freeze(wsdlport);
ohair@286 92 if (operationDispatcher == null) operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
ohair@286 93 // if(!clientConfig) {
ohair@286 94 for(JavaMethodImpl jm: seiModel.getJavaMethods()) if (!jm.isAsync()) {
alanb@368 95 TieHandler th = new TieHandler(jm, seiModel.getWSBinding(), packetFactory);
alanb@368 96 wsdlOpMap.put(jm, th);
ohair@286 97 tieHandlers.put(th.getMethod(), th);
ohair@286 98 }
ohair@286 99 // }
ohair@286 100 }
ohair@286 101
ohair@286 102 //TODO isClientConfig
ohair@286 103 private boolean isClientConfig(DatabindingConfig config) {
ohair@286 104 if (config.getContractClass() == null) return false;
ohair@286 105 if (!config.getContractClass().isInterface()) return false;
ohair@286 106 return (config.getEndpointClass() == null || config.getEndpointClass().isInterface());
ohair@286 107 }
ohair@286 108 //TODO fix freeze
ohair@286 109 public synchronized void freeze(WSDLPort port) {
ohair@286 110 if (clientConfig) return;
ohair@286 111 if (operationDispatcher != null) return;
ohair@286 112 operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel);
ohair@286 113 }
ohair@286 114
ohair@286 115 public SEIModel getModel() {
ohair@286 116 return seiModel;
ohair@286 117 }
ohair@286 118 //Refactored from SEIStub
ohair@286 119 private void initStubHandlers() {
ohair@286 120 stubHandlers = new HashMap<Method, StubHandler>();
ohair@286 121 Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
ohair@286 122 // fill in methodHandlers.
ohair@286 123 // first fill in sychronized versions
ohair@286 124 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
ohair@286 125 if (!m.getMEP().isAsync) {
alanb@368 126 StubHandler handler = new StubHandler(m, packetFactory);
ohair@286 127 syncs.put(m.getOperationSignature(), m);
ohair@286 128 stubHandlers.put(m.getMethod(), handler);
ohair@286 129 }
ohair@286 130 }
ohair@286 131 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
ohair@286 132 JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
ohair@286 133 if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
ohair@286 134 Method m = jm.getMethod();
alanb@368 135 StubAsyncHandler handler = new StubAsyncHandler(jm, sync, packetFactory);
ohair@286 136 stubHandlers.put(m, handler);
ohair@286 137 }
ohair@286 138 }
ohair@286 139 }
ohair@286 140
alanb@368 141 public JavaMethodImpl resolveJavaMethod(Packet req) throws DispatchException {
alanb@368 142 WSDLOperationMapping m = req.getWSDLOperationMapping();
alanb@368 143 if (m == null) m = (operationDispatcher != null) ?
alanb@368 144 operationDispatcher.getWSDLOperationMapping(req):
alanb@368 145 operationDispatcherNoWsdl.getWSDLOperationMapping(req);
alanb@368 146 return (JavaMethodImpl) m.getJavaMethod();
ohair@286 147 }
ohair@286 148
ohair@286 149 public JavaCallInfo deserializeRequest(Packet req) {
alanb@368 150 com.sun.xml.internal.ws.api.databinding.JavaCallInfo call = new com.sun.xml.internal.ws.api.databinding.JavaCallInfo();
ohair@286 151 try {
alanb@368 152 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
ohair@286 153 TieHandler tie = wsdlOpMap.get(wsdlOp);
ohair@286 154 call.setMethod(tie.getMethod());
ohair@286 155 Object[] args = tie.readRequest(req.getMessage());
ohair@286 156 call.setParameters(args);
ohair@286 157 } catch (DispatchException e) {
ohair@286 158 call.setException(e);
ohair@286 159 }
ohair@286 160 return call;
ohair@286 161 }
ohair@286 162
ohair@286 163 public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) {
ohair@286 164 StubHandler stubHandler = stubHandlers.get(call.getMethod());
ohair@286 165 try {
ohair@286 166 return stubHandler.readResponse(res, call);
ohair@286 167 } catch (Throwable e) {
ohair@286 168 call.setException(e);
ohair@286 169 return call;
ohair@286 170 }
ohair@286 171 }
ohair@286 172
ohair@286 173 public WebServiceFeature[] getFeatures() {
ohair@286 174 // TODO Auto-generated method stub
ohair@286 175 return null;
ohair@286 176 }
ohair@286 177
ohair@286 178 public Packet serializeRequest(JavaCallInfo call) {
ohair@286 179 StubHandler stubHandler = stubHandlers.get(call.getMethod());
alanb@368 180 Packet p = stubHandler.createRequestPacket(call);
alanb@368 181 p.setState(Packet.State.ClientRequest);
alanb@368 182 return p;
ohair@286 183 }
ohair@286 184
ohair@286 185 public Packet serializeResponse(JavaCallInfo call) {
ohair@286 186 Method method = call.getMethod();
ohair@286 187 Message message = null;
ohair@286 188 if (method != null) {
ohair@286 189 TieHandler th = tieHandlers.get(method);
ohair@286 190 if (th != null) {
ohair@286 191 return th.serializeResponse(call);
ohair@286 192 }
ohair@286 193 }
ohair@286 194 if (call.getException() instanceof DispatchException) {
ohair@286 195 message = ((DispatchException)call.getException()).fault;
ohair@286 196 }
alanb@368 197 Packet p = (Packet)packetFactory.createContext(message);
alanb@368 198 p.setState(Packet.State.ServerResponse);
alanb@368 199 return p;
ohair@286 200 }
ohair@286 201
ohair@286 202 public ClientCallBridge getClientBridge(Method method) {
ohair@286 203 return stubHandlers.get(method);
ohair@286 204 }
ohair@286 205
ohair@286 206
ohair@286 207 public void generateWSDL(WSDLGenInfo info) {
ohair@286 208 com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator(
ohair@286 209 seiModel,
ohair@286 210 info.getWsdlResolver(),
ohair@286 211 seiModel.getWSBinding(),
ohair@286 212 info.getContainer(), seiModel.getEndpointClass(),
ohair@286 213 info.isInlineSchemas(),
alanb@368 214 info.isSecureXmlProcessingDisabled(),
alanb@368 215 info.getExtensions());
ohair@286 216 wsdlGen.doGeneration();
ohair@286 217 }
ohair@286 218
ohair@286 219 public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
alanb@368 220 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
ohair@286 221 return wsdlOpMap.get(wsdlOp);
ohair@286 222 }
ohair@286 223
ohair@286 224
ohair@286 225 Codec getCodec() {
ohair@286 226 if (codec == null) codec = ((BindingImpl)seiModel.getWSBinding()).createCodec();
ohair@286 227 return codec;
ohair@286 228 }
ohair@286 229
ohair@286 230 public ContentType encode( Packet packet, OutputStream out ) throws IOException {
ohair@286 231 return getCodec().encode(packet, out);
ohair@286 232 }
ohair@286 233
ohair@286 234 public void decode( InputStream in, String ct, Packet p ) throws IOException{
ohair@286 235 getCodec().decode(in, ct, p);
ohair@286 236 }
ohair@286 237
alanb@368 238 public com.oracle.webservices.internal.api.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
alanb@368 239 return new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(method, args);
ohair@286 240 }
ohair@286 241
alanb@368 242 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeResponse(
alanb@368 243 MessageContext message, com.oracle.webservices.internal.api.databinding.JavaCallInfo call) {
ohair@286 244 return deserializeResponse((Packet)message, (JavaCallInfo)call);
ohair@286 245 }
ohair@286 246
alanb@368 247 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
ohair@286 248 return deserializeRequest((Packet)message);
ohair@286 249 }
ohair@286 250
alanb@368 251 public MessageContextFactory getMessageContextFactory() {
alanb@368 252 return packetFactory;
ohair@286 253 }
ohair@286 254 }

mercurial