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

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/db/DatabindingImpl.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,288 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.db;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.io.InputStream;
    1.33 +import java.io.OutputStream;
    1.34 +import java.lang.reflect.Method;
    1.35 +import java.util.HashMap;
    1.36 +import java.util.Map;
    1.37 +
    1.38 +import javax.xml.ws.WebServiceFeature;
    1.39 +
    1.40 +import com.oracle.webservices.internal.api.databinding.JavaCallInfo;
    1.41 +import com.oracle.webservices.internal.api.message.MessageContext;
    1.42 +import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge;
    1.43 +import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
    1.44 +import com.sun.xml.internal.ws.api.databinding.Databinding;
    1.45 +import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
    1.46 +import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
    1.47 +import com.sun.xml.internal.ws.api.message.Message;
    1.48 +import com.sun.xml.internal.ws.api.message.MessageContextFactory;
    1.49 +import com.sun.xml.internal.ws.api.message.Packet;
    1.50 +import com.sun.xml.internal.ws.api.model.MEP;
    1.51 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.52 +import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
    1.53 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.54 +import com.sun.xml.internal.ws.api.pipe.Codec;
    1.55 +import com.sun.xml.internal.ws.api.pipe.ContentType;
    1.56 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.57 +import com.sun.xml.internal.ws.client.sei.StubAsyncHandler;
    1.58 +import com.sun.xml.internal.ws.client.sei.StubHandler;
    1.59 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    1.60 +import com.sun.xml.internal.ws.model.JavaMethodImpl;
    1.61 +import com.sun.xml.internal.ws.model.RuntimeModeler;
    1.62 +import com.sun.xml.internal.ws.server.sei.TieHandler;
    1.63 +import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
    1.64 +import com.sun.xml.internal.ws.wsdl.DispatchException;
    1.65 +import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
    1.66 +
    1.67 +/**
    1.68 + * WsRuntimeImpl is the databinding processor built on SEIModel
    1.69 + *
    1.70 + * @author shih-chang.chen@oracle.com
    1.71 + */
    1.72 +public final class DatabindingImpl implements Databinding {
    1.73 +
    1.74 +    AbstractSEIModelImpl seiModel;
    1.75 +    Map<Method, StubHandler> stubHandlers;
    1.76 +//    QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
    1.77 +    Map<JavaMethodImpl, TieHandler> wsdlOpMap = new HashMap<JavaMethodImpl, TieHandler>();
    1.78 +    Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>();
    1.79 +    OperationDispatcher operationDispatcher;
    1.80 +    OperationDispatcher operationDispatcherNoWsdl;
    1.81 +    boolean clientConfig = false;
    1.82 +    Codec codec;
    1.83 +    MessageContextFactory packetFactory = null;
    1.84 +
    1.85 +    public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
    1.86 +        RuntimeModeler modeler = new RuntimeModeler(config);
    1.87 +        modeler.setClassLoader(config.getClassLoader());
    1.88 +        seiModel = modeler.buildRuntimeModel();
    1.89 +        WSDLPort wsdlport = config.getWsdlPort();
    1.90 +        packetFactory = new MessageContextFactory(seiModel.getWSBinding().getFeatures());
    1.91 +        clientConfig = isClientConfig(config);
    1.92 +        if (clientConfig) {
    1.93 +            initStubHandlers();
    1.94 +        }
    1.95 +        seiModel.setDatabinding(this);
    1.96 +        if (wsdlport != null) {
    1.97 +            freeze(wsdlport);
    1.98 +        }
    1.99 +        if (operationDispatcher == null) {
   1.100 +            operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
   1.101 +        }
   1.102 +//    if(!clientConfig) {
   1.103 +        for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
   1.104 +            if (!jm.isAsync()) {
   1.105 +                TieHandler th = new TieHandler(jm, seiModel.getWSBinding(), packetFactory);
   1.106 +                wsdlOpMap.put(jm, th);
   1.107 +                tieHandlers.put(th.getMethod(), th);
   1.108 +            }
   1.109 +        }
   1.110 +//    }
   1.111 +    }
   1.112 +
   1.113 +    //TODO isClientConfig
   1.114 +    private boolean isClientConfig(DatabindingConfig config) {
   1.115 +        if (config.getContractClass() == null) {
   1.116 +            return false;
   1.117 +        }
   1.118 +        if (!config.getContractClass().isInterface()) {
   1.119 +            return false;
   1.120 +        }
   1.121 +        return (config.getEndpointClass() == null || config.getEndpointClass().isInterface());
   1.122 +    }
   1.123 +    //TODO fix freeze
   1.124 +
   1.125 +    public void freeze(WSDLPort port) {
   1.126 +        if (clientConfig) {
   1.127 +            return;
   1.128 +        }
   1.129 +        synchronized(this) {
   1.130 +            if (operationDispatcher == null) {
   1.131 +                operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel);
   1.132 +            }
   1.133 +        }
   1.134 +    }
   1.135 +
   1.136 +    public SEIModel getModel() {
   1.137 +        return seiModel;
   1.138 +    }
   1.139 +//Refactored from SEIStub
   1.140 +
   1.141 +    private void initStubHandlers() {
   1.142 +        stubHandlers = new HashMap<Method, StubHandler>();
   1.143 +        Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
   1.144 +        // fill in methodHandlers.
   1.145 +        // first fill in sychronized versions
   1.146 +        for (JavaMethodImpl m : seiModel.getJavaMethods()) {
   1.147 +            if (!m.getMEP().isAsync) {
   1.148 +                StubHandler handler = new StubHandler(m, packetFactory);
   1.149 +                syncs.put(m.getOperationSignature(), m);
   1.150 +                stubHandlers.put(m.getMethod(), handler);
   1.151 +            }
   1.152 +        }
   1.153 +        for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
   1.154 +            JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
   1.155 +            if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
   1.156 +                Method m = jm.getMethod();
   1.157 +                StubAsyncHandler handler = new StubAsyncHandler(jm, sync, packetFactory);
   1.158 +                stubHandlers.put(m, handler);
   1.159 +            }
   1.160 +        }
   1.161 +    }
   1.162 +
   1.163 +    JavaMethodImpl resolveJavaMethod(Packet req) throws DispatchException {
   1.164 +        WSDLOperationMapping m = req.getWSDLOperationMapping();
   1.165 +        if (m == null) {
   1.166 +            synchronized (this) {
   1.167 +                m = (operationDispatcher != null)
   1.168 +                        ? operationDispatcher.getWSDLOperationMapping(req)
   1.169 +                        : operationDispatcherNoWsdl.getWSDLOperationMapping(req);
   1.170 +            }
   1.171 +        }
   1.172 +        return (JavaMethodImpl) m.getJavaMethod();
   1.173 +    }
   1.174 +
   1.175 +    public JavaCallInfo deserializeRequest(Packet req) {
   1.176 +        com.sun.xml.internal.ws.api.databinding.JavaCallInfo call = new com.sun.xml.internal.ws.api.databinding.JavaCallInfo();
   1.177 +        try {
   1.178 +            JavaMethodImpl wsdlOp = resolveJavaMethod(req);
   1.179 +            TieHandler tie = wsdlOpMap.get(wsdlOp);
   1.180 +            call.setMethod(tie.getMethod());
   1.181 +            Object[] args = tie.readRequest(req.getMessage());
   1.182 +            call.setParameters(args);
   1.183 +        } catch (DispatchException e) {
   1.184 +            call.setException(e);
   1.185 +        }
   1.186 +        return call;
   1.187 +    }
   1.188 +
   1.189 +    public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) {
   1.190 +        StubHandler stubHandler = stubHandlers.get(call.getMethod());
   1.191 +        try {
   1.192 +            return stubHandler.readResponse(res, call);
   1.193 +        } catch (Throwable e) {
   1.194 +            call.setException(e);
   1.195 +            return call;
   1.196 +        }
   1.197 +    }
   1.198 +
   1.199 +    public WebServiceFeature[] getFeatures() {
   1.200 +        // TODO Auto-generated method stub
   1.201 +        return null;
   1.202 +    }
   1.203 +
   1.204 +    @Override
   1.205 +    public Packet serializeRequest(JavaCallInfo call) {
   1.206 +        StubHandler stubHandler = stubHandlers.get(call.getMethod());
   1.207 +        Packet p = stubHandler.createRequestPacket(call);
   1.208 +        p.setState(Packet.State.ClientRequest);
   1.209 +        return p;
   1.210 +    }
   1.211 +
   1.212 +    @Override
   1.213 +    public Packet serializeResponse(JavaCallInfo call) {
   1.214 +        Method method = call.getMethod();
   1.215 +        Message message = null;
   1.216 +        if (method != null) {
   1.217 +            TieHandler th = tieHandlers.get(method);
   1.218 +            if (th != null) {
   1.219 +                return th.serializeResponse(call);
   1.220 +            }
   1.221 +        }
   1.222 +        if (call.getException() instanceof DispatchException) {
   1.223 +            message = ((DispatchException) call.getException()).fault;
   1.224 +        }
   1.225 +        Packet p = (Packet) packetFactory.createContext(message);
   1.226 +        p.setState(Packet.State.ServerResponse);
   1.227 +        return p;
   1.228 +    }
   1.229 +
   1.230 +    @Override
   1.231 +    public ClientCallBridge getClientBridge(Method method) {
   1.232 +        return stubHandlers.get(method);
   1.233 +    }
   1.234 +
   1.235 +    @Override
   1.236 +    public void generateWSDL(WSDLGenInfo info) {
   1.237 +        com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator(
   1.238 +                seiModel,
   1.239 +                info.getWsdlResolver(),
   1.240 +                seiModel.getWSBinding(),
   1.241 +                info.getContainer(), seiModel.getEndpointClass(),
   1.242 +                info.isInlineSchemas(),
   1.243 +                info.isSecureXmlProcessingDisabled(),
   1.244 +                info.getExtensions());
   1.245 +        wsdlGen.doGeneration();
   1.246 +    }
   1.247 +
   1.248 +    @Override
   1.249 +    public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
   1.250 +        JavaMethodImpl wsdlOp = resolveJavaMethod(req);
   1.251 +        return wsdlOpMap.get(wsdlOp);
   1.252 +    }
   1.253 +
   1.254 +    Codec getCodec() {
   1.255 +        if (codec == null) {
   1.256 +            codec = ((BindingImpl) seiModel.getWSBinding()).createCodec();
   1.257 +        }
   1.258 +        return codec;
   1.259 +    }
   1.260 +
   1.261 +    @Override
   1.262 +    public ContentType encode(Packet packet, OutputStream out) throws IOException {
   1.263 +        return getCodec().encode(packet, out);
   1.264 +    }
   1.265 +
   1.266 +    @Override
   1.267 +    public void decode(InputStream in, String ct, Packet p) throws IOException {
   1.268 +        getCodec().decode(in, ct, p);
   1.269 +    }
   1.270 +
   1.271 +    @Override
   1.272 +    public com.oracle.webservices.internal.api.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
   1.273 +        return new com.sun.xml.internal.ws.api.databinding.JavaCallInfo(method, args);
   1.274 +    }
   1.275 +
   1.276 +    @Override
   1.277 +    public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeResponse(
   1.278 +            MessageContext message, com.oracle.webservices.internal.api.databinding.JavaCallInfo call) {
   1.279 +        return deserializeResponse((Packet) message, (JavaCallInfo) call);
   1.280 +    }
   1.281 +
   1.282 +    @Override
   1.283 +    public com.oracle.webservices.internal.api.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
   1.284 +        return deserializeRequest((Packet) message);
   1.285 +    }
   1.286 +
   1.287 +    @Override
   1.288 +    public MessageContextFactory getMessageContextFactory() {
   1.289 +        return packetFactory;
   1.290 +    }
   1.291 +}

mercurial