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

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

mercurial