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

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 384
8f2986ff0235
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
30 import java.io.OutputStream; 30 import java.io.OutputStream;
31 import java.lang.reflect.Method; 31 import java.lang.reflect.Method;
32 import java.util.HashMap; 32 import java.util.HashMap;
33 import java.util.Map; 33 import java.util.Map;
34 34
35 import javax.xml.namespace.QName;
36 import javax.xml.ws.WebServiceFeature; 35 import javax.xml.ws.WebServiceFeature;
37 36
38 import com.sun.xml.internal.org.jvnet.ws.message.MessageContext; 37 import com.oracle.webservices.internal.api.databinding.JavaCallInfo;
39 38 import com.oracle.webservices.internal.api.message.MessageContext;
40 import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge; 39 import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge;
41 import com.sun.xml.internal.ws.api.databinding.JavaCallInfo;
42 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo; 40 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
43 import com.sun.xml.internal.ws.api.databinding.Databinding; 41 import com.sun.xml.internal.ws.api.databinding.Databinding;
44 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; 42 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
45 import com.sun.xml.internal.ws.api.databinding.ClientCallBridge; 43 import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
46 import com.sun.xml.internal.ws.api.message.Message; 44 import com.sun.xml.internal.ws.api.message.Message;
45 import com.sun.xml.internal.ws.api.message.MessageContextFactory;
47 import com.sun.xml.internal.ws.api.message.Packet; 46 import com.sun.xml.internal.ws.api.message.Packet;
48 import com.sun.xml.internal.ws.api.model.MEP; 47 import com.sun.xml.internal.ws.api.model.MEP;
49 import com.sun.xml.internal.ws.api.model.SEIModel; 48 import com.sun.xml.internal.ws.api.model.SEIModel;
49 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
50 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; 50 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
51 import com.sun.xml.internal.ws.api.pipe.Codec; 51 import com.sun.xml.internal.ws.api.pipe.Codec;
52 import com.sun.xml.internal.ws.api.pipe.ContentType; 52 import com.sun.xml.internal.ws.api.pipe.ContentType;
53 import com.sun.xml.internal.ws.binding.BindingImpl; 53 import com.sun.xml.internal.ws.binding.BindingImpl;
54 import com.sun.xml.internal.ws.client.sei.StubAsyncHandler; 54 import com.sun.xml.internal.ws.client.sei.StubAsyncHandler;
55 import com.sun.xml.internal.ws.client.sei.StubHandler; 55 import com.sun.xml.internal.ws.client.sei.StubHandler;
56 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl; 56 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
57 import com.sun.xml.internal.ws.model.JavaMethodImpl; 57 import com.sun.xml.internal.ws.model.JavaMethodImpl;
58 import com.sun.xml.internal.ws.model.RuntimeModeler; 58 import com.sun.xml.internal.ws.model.RuntimeModeler;
59 import com.sun.xml.internal.ws.server.sei.TieHandler; 59 import com.sun.xml.internal.ws.server.sei.TieHandler;
60 import com.sun.xml.internal.ws.util.QNameMap;
61 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature; 60 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
62 import com.sun.xml.internal.ws.wsdl.DispatchException; 61 import com.sun.xml.internal.ws.wsdl.DispatchException;
63 import com.sun.xml.internal.ws.wsdl.OperationDispatcher; 62 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
64 63
65 /** 64 /**
66 * WsRuntimeImpl is the databinding processor built on SEIModel 65 * WsRuntimeImpl is the databinding processor built on SEIModel
67 * 66 *
68 * @author shih-chang.chen@oracle.com 67 * @author shih-chang.chen@oracle.com
69 */ 68 */
70 public class DatabindingImpl implements Databinding, com.sun.xml.internal.org.jvnet.ws.databinding.Databinding { 69 public class DatabindingImpl implements Databinding {
71 70
72 AbstractSEIModelImpl seiModel; 71 AbstractSEIModelImpl seiModel;
73 Map<Method, StubHandler> stubHandlers; 72 Map<Method, StubHandler> stubHandlers;
74 QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>(); 73 // QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
74 Map<JavaMethodImpl, TieHandler> wsdlOpMap = new HashMap<JavaMethodImpl, TieHandler>();
75 Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>(); 75 Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>();
76 OperationDispatcher operationDispatcher; 76 OperationDispatcher operationDispatcher;
77 OperationDispatcher operationDispatcherNoWsdl; 77 OperationDispatcher operationDispatcherNoWsdl;
78 boolean clientConfig = false; 78 boolean clientConfig = false;
79 Codec codec; 79 Codec codec;
80 MessageContextFactory packetFactory = null;
80 81
81 public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) { 82 public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
82 RuntimeModeler modeler = new RuntimeModeler(config); 83 RuntimeModeler modeler = new RuntimeModeler(config);
83 modeler.setClassLoader(config.getClassLoader()); 84 modeler.setClassLoader(config.getClassLoader());
84 seiModel = modeler.buildRuntimeModel(); 85 seiModel = modeler.buildRuntimeModel();
85 WSDLPort wsdlport = config.getWsdlPort(); 86 WSDLPort wsdlport = config.getWsdlPort();
87 packetFactory = new MessageContextFactory(seiModel.getWSBinding().getFeatures());
86 clientConfig = isClientConfig(config); 88 clientConfig = isClientConfig(config);
87 if ( clientConfig ) initStubHandlers(); 89 if ( clientConfig ) initStubHandlers();
88 seiModel.setDatabinding(this); 90 seiModel.setDatabinding(this);
89 if (wsdlport != null) freeze(wsdlport); 91 if (wsdlport != null) freeze(wsdlport);
90 if (operationDispatcher == null) operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel); 92 if (operationDispatcher == null) operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
91 // if(!clientConfig) { 93 // if(!clientConfig) {
92 for(JavaMethodImpl jm: seiModel.getJavaMethods()) if (!jm.isAsync()) { 94 for(JavaMethodImpl jm: seiModel.getJavaMethods()) if (!jm.isAsync()) {
93 TieHandler th = new TieHandler(jm, seiModel.getWSBinding()); 95 TieHandler th = new TieHandler(jm, seiModel.getWSBinding(), packetFactory);
94 wsdlOpMap.put(jm.getOperationQName(), th); 96 wsdlOpMap.put(jm, th);
95 tieHandlers.put(th.getMethod(), th); 97 tieHandlers.put(th.getMethod(), th);
96 } 98 }
97 // } 99 // }
98 } 100 }
99 101
119 Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>(); 121 Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
120 // fill in methodHandlers. 122 // fill in methodHandlers.
121 // first fill in sychronized versions 123 // first fill in sychronized versions
122 for (JavaMethodImpl m : seiModel.getJavaMethods()) { 124 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
123 if (!m.getMEP().isAsync) { 125 if (!m.getMEP().isAsync) {
124 StubHandler handler = new StubHandler(m); 126 StubHandler handler = new StubHandler(m, packetFactory);
125 syncs.put(m.getOperationSignature(), m); 127 syncs.put(m.getOperationSignature(), m);
126 stubHandlers.put(m.getMethod(), handler); 128 stubHandlers.put(m.getMethod(), handler);
127 } 129 }
128 } 130 }
129 for (JavaMethodImpl jm : seiModel.getJavaMethods()) { 131 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
130 JavaMethodImpl sync = syncs.get(jm.getOperationSignature()); 132 JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
131 if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) { 133 if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
132 Method m = jm.getMethod(); 134 Method m = jm.getMethod();
133 StubAsyncHandler handler = new StubAsyncHandler(jm, sync); 135 StubAsyncHandler handler = new StubAsyncHandler(jm, sync, packetFactory);
134 stubHandlers.put(m, handler); 136 stubHandlers.put(m, handler);
135 } 137 }
136 } 138 }
137 } 139 }
138 140
139 public QName resolveOperationQName(Packet req) throws DispatchException { 141 public JavaMethodImpl resolveJavaMethod(Packet req) throws DispatchException {
140 return (operationDispatcher != null)? 142 WSDLOperationMapping m = req.getWSDLOperationMapping();
141 operationDispatcher.getWSDLOperationQName(req): 143 if (m == null) m = (operationDispatcher != null) ?
142 operationDispatcherNoWsdl.getWSDLOperationQName(req); 144 operationDispatcher.getWSDLOperationMapping(req):
145 operationDispatcherNoWsdl.getWSDLOperationMapping(req);
146 return (JavaMethodImpl) m.getJavaMethod();
143 } 147 }
144 148
145 public JavaCallInfo deserializeRequest(Packet req) { 149 public JavaCallInfo deserializeRequest(Packet req) {
146 JavaCallInfo call = new JavaCallInfo(); 150 com.sun.xml.internal.ws.api.databinding.JavaCallInfo call = new com.sun.xml.internal.ws.api.databinding.JavaCallInfo();
147 try { 151 try {
148 QName wsdlOp = resolveOperationQName(req); 152 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
149 TieHandler tie = wsdlOpMap.get(wsdlOp); 153 TieHandler tie = wsdlOpMap.get(wsdlOp);
150 call.setMethod(tie.getMethod()); 154 call.setMethod(tie.getMethod());
151 Object[] args = tie.readRequest(req.getMessage()); 155 Object[] args = tie.readRequest(req.getMessage());
152 call.setParameters(args); 156 call.setParameters(args);
153 } catch (DispatchException e) { 157 } catch (DispatchException e) {
171 return null; 175 return null;
172 } 176 }
173 177
174 public Packet serializeRequest(JavaCallInfo call) { 178 public Packet serializeRequest(JavaCallInfo call) {
175 StubHandler stubHandler = stubHandlers.get(call.getMethod()); 179 StubHandler stubHandler = stubHandlers.get(call.getMethod());
176 return stubHandler.createRequestPacket(call); 180 Packet p = stubHandler.createRequestPacket(call);
181 p.setState(Packet.State.ClientRequest);
182 return p;
177 } 183 }
178 184
179 public Packet serializeResponse(JavaCallInfo call) { 185 public Packet serializeResponse(JavaCallInfo call) {
180 Method method = call.getMethod(); 186 Method method = call.getMethod();
181 Message message = null; 187 Message message = null;
186 } 192 }
187 } 193 }
188 if (call.getException() instanceof DispatchException) { 194 if (call.getException() instanceof DispatchException) {
189 message = ((DispatchException)call.getException()).fault; 195 message = ((DispatchException)call.getException()).fault;
190 } 196 }
191 Packet response = new Packet(); 197 Packet p = (Packet)packetFactory.createContext(message);
192 response.setMessage(message); 198 p.setState(Packet.State.ServerResponse);
193 return response; 199 return p;
194 } 200 }
195 201
196 public ClientCallBridge getClientBridge(Method method) { 202 public ClientCallBridge getClientBridge(Method method) {
197 return stubHandlers.get(method); 203 return stubHandlers.get(method);
198 } 204 }
203 seiModel, 209 seiModel,
204 info.getWsdlResolver(), 210 info.getWsdlResolver(),
205 seiModel.getWSBinding(), 211 seiModel.getWSBinding(),
206 info.getContainer(), seiModel.getEndpointClass(), 212 info.getContainer(), seiModel.getEndpointClass(),
207 info.isInlineSchemas(), 213 info.isInlineSchemas(),
208 info.getExtensions()); 214 info.isSecureXmlProcessingDisabled(),
215 info.getExtensions());
209 wsdlGen.doGeneration(); 216 wsdlGen.doGeneration();
210 } 217 }
211 218
212 public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException { 219 public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
213 QName wsdlOp = resolveOperationQName(req); 220 JavaMethodImpl wsdlOp = resolveJavaMethod(req);
214 return wsdlOpMap.get(wsdlOp); 221 return wsdlOpMap.get(wsdlOp);
215 } 222 }
216 223
217 224
218 Codec getCodec() { 225 Codec getCodec() {
226 233
227 public void decode( InputStream in, String ct, Packet p ) throws IOException{ 234 public void decode( InputStream in, String ct, Packet p ) throws IOException{
228 getCodec().decode(in, ct, p); 235 getCodec().decode(in, ct, p);
229 } 236 }
230 237
231 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) { 238 public com.oracle.webservices.internal.api.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
232 return new JavaCallInfo(method, args); 239 return new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(method, args);
233 } 240 }
234 241
235 public MessageContext serializeRequest(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) { 242 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeResponse(
236 return serializeRequest((JavaCallInfo)call); 243 MessageContext message, com.oracle.webservices.internal.api.databinding.JavaCallInfo call) {
237 }
238
239 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeResponse(
240 MessageContext message, com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
241 return deserializeResponse((Packet)message, (JavaCallInfo)call); 244 return deserializeResponse((Packet)message, (JavaCallInfo)call);
242 } 245 }
243 246
244 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeRequest(MessageContext message) { 247 public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
245 return deserializeRequest((Packet)message); 248 return deserializeRequest((Packet)message);
246 } 249 }
247 250
248 public MessageContext serializeResponse(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) { 251 public MessageContextFactory getMessageContextFactory() {
249 return serializeResponse((JavaCallInfo)call); 252 return packetFactory;
250 } 253 }
251 } 254 }

mercurial