Search in sources :

Example 1 with SOAPService

use of org.apache.axis.handlers.soap.SOAPService in project Lucee by lucee.

the class ComponentHandler method setupService.

/**
 * handle all the work necessary set
 * up the "proxy" RPC service surrounding it as the MessageContext's
 * active service.
 */
protected void setupService(MessageContext msgContext) throws Exception {
    RefBoolean isnew = new RefBooleanImpl(false);
    Component cfc = (Component) msgContext.getProperty(Constants.COMPONENT);
    Class clazz = cfc.getJavaAccessClass(ThreadLocalPageContext.get(), isnew, false, true, true, true);
    String clazzName = clazz.getName();
    ClassLoader classLoader = clazz.getClassLoader();
    Pair pair;
    SOAPService rpc = null;
    if (!isnew.toBooleanValue() && (pair = (Pair) soapServices.get(clazzName)) != null) {
        if (classLoader == pair.classloader)
            rpc = pair.rpc;
    }
    // else classLoader = clazz.getClassLoader();
    // print.out("cl:"+classLoader);
    msgContext.setClassLoader(classLoader);
    if (rpc == null) {
        rpc = new SOAPService(new RPCProvider());
        rpc.setName(clazzName);
        rpc.setOption(JavaProvider.OPTION_CLASSNAME, clazzName);
        rpc.setEngine(msgContext.getAxisEngine());
        rpc.setOption(JavaProvider.OPTION_ALLOWEDMETHODS, "*");
        rpc.setOption(JavaProvider.OPTION_SCOPE, Scope.REQUEST.getName());
        rpc.getInitializedServiceDesc(msgContext);
        soapServices.put(clazzName, new Pair(classLoader, rpc));
    }
    rpc.setEngine(msgContext.getAxisEngine());
    // ??
    rpc.init();
    msgContext.setService(rpc);
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) RefBoolean(lucee.commons.lang.types.RefBoolean) RPCProvider(org.apache.axis.providers.java.RPCProvider) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Component(lucee.runtime.Component)

Example 2 with SOAPService

use of org.apache.axis.handlers.soap.SOAPService in project tomee by apache.

the class AxisWsContainer method doService.

protected void doService(final HttpRequest req, final HttpResponse res) throws Exception {
    final org.apache.axis.MessageContext messageContext = new org.apache.axis.MessageContext(null);
    req.setAttribute(WsConstants.MESSAGE_CONTEXT, messageContext);
    messageContext.setClassLoader(classLoader);
    Message responseMessage;
    String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
    final String contentLocation = req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
    final InputStream inputStream = req.getInputStream();
    final Message requestMessage = new Message(inputStream, false, contentType, contentLocation);
    messageContext.setRequestMessage(requestMessage);
    messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, req.getURI().getPath());
    messageContext.setProperty(org.apache.axis.MessageContext.TRANS_URL, req.getURI().toString());
    messageContext.setService(service);
    messageContext.setProperty(REQUEST, req);
    messageContext.setProperty(RESPONSE, res);
    messageContext.setProperty(AxisEngine.PROP_DISABLE_PRETTY_XML, Boolean.TRUE);
    final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        try {
            final String characterEncoding = (String) requestMessage.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
            if (characterEncoding != null) {
                messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, characterEncoding);
            } else {
                messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
            }
            final String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
            if (soapAction != null) {
                messageContext.setUseSOAPAction(true);
                messageContext.setSOAPActionURI(soapAction);
            }
            final SOAPEnvelope env = requestMessage.getSOAPEnvelope();
            if (env != null && env.getSOAPConstants() != null) {
                messageContext.setSOAPConstants(env.getSOAPConstants());
            }
            final SOAPService service = messageContext.getService();
            Thread.currentThread().setContextClassLoader(classLoader);
            service.invoke(messageContext);
            responseMessage = messageContext.getResponseMessage();
        } catch (final AxisFault fault) {
            if (req.getMethod().equals(HttpRequest.Method.GET.name()) && req.getParameters().isEmpty()) {
                String serviceName = req.getURI().getRawPath();
                serviceName = serviceName.substring(serviceName.lastIndexOf("/") + 1);
                printServiceInfo(res, serviceName);
                return;
            } else {
                responseMessage = handleFault(fault, res, messageContext);
            }
        } catch (final Exception e) {
            responseMessage = handleException(messageContext, res, e);
        }
        // TODO investigate and fix operation == null!
        if (messageContext.getOperation() != null) {
            if (messageContext.getOperation().getMep() == OperationType.ONE_WAY) {
                // No content, so just indicate accepted
                res.setStatus(HttpServletResponse.SC_ACCEPTED);
                return;
            } else if (responseMessage == null) {
                responseMessage = handleException(messageContext, null, new ServerRuntimeException("No response for non-one-way operation"));
            }
        } else if (responseMessage == null) {
            res.setStatus(HttpServletResponse.SC_ACCEPTED);
            return;
        }
        try {
            final SOAPConstants soapConstants = messageContext.getSOAPConstants();
            final String contentType1 = responseMessage.getContentType(soapConstants);
            res.setContentType(contentType1);
            // Transfer MIME headers to HTTP headers for response message.
            final MimeHeaders responseMimeHeaders = responseMessage.getMimeHeaders();
            for (final Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
                final MimeHeader responseMimeHeader = (MimeHeader) i.next();
                res.setHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
            }
            // TODO discuss this with dims.
            // // synchronize the character encoding of request and response
            // String responseEncoding = (String) messageContext.getProperty(
            // SOAPMessage.CHARACTER_SET_ENCODING);
            // if (responseEncoding != null) {
            // try {
            // responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
            // responseEncoding);
            // } catch (SOAPException e) {
            // log.info(Messages.getMessage("exception00"), e);
            // }
            // }
            // determine content type from message response
            contentType = responseMessage.getContentType(messageContext.getSOAPConstants());
            responseMessage.writeTo(res.getOutputStream());
        } catch (final Exception e) {
            LOGGER.warning(Messages.getMessage("exception00"), e);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) AxisFault(org.apache.axis.AxisFault) Message(org.apache.axis.Message) SOAPMessage(javax.xml.soap.SOAPMessage) InputStream(java.io.InputStream) SOAPEnvelope(org.apache.axis.message.SOAPEnvelope) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) IOException(java.io.IOException) MimeHeaders(javax.xml.soap.MimeHeaders) MimeHeader(javax.xml.soap.MimeHeader) Iterator(java.util.Iterator) MessageContext(org.apache.axis.MessageContext) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SOAPConstants(org.apache.axis.soap.SOAPConstants) MessageContext(org.apache.axis.MessageContext)

Example 3 with SOAPService

use of org.apache.axis.handlers.soap.SOAPService in project tomee by apache.

the class AxisService method createEjbWsContainer.

@Override
protected HttpListener createEjbWsContainer(URL url, PortData port, BeanContext beanContext, ServiceConfiguration serviceInfos) throws Exception {
    ClassLoader classLoader = beanContext.getClassLoader();
    // todo build JaxRpcServiceInfo in assembler
    JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
    // Build java service descriptor
    JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(serviceInfo, classLoader);
    JavaServiceDesc serviceDesc = javaServiceDescBuilder.createServiceDesc();
    // Create service
    RPCProvider provider = new EjbRpcProvider(beanContext, createHandlerInfos(port.getHandlerChains()));
    SOAPService service = new SOAPService(null, provider, null);
    service.setServiceDescription(serviceDesc);
    // Set class name
    service.setOption("className", beanContext.getServiceEndpointInterface().getName());
    serviceDesc.setImplClass(beanContext.getServiceEndpointInterface());
    // Create container
    AxisWsContainer container = new AxisWsContainer(port.getWsdlUrl(), service, null, classLoader);
    wsContainers.put(beanContext.getDeploymentID().toString(), container);
    return container;
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) JaxRpcServiceInfo(org.apache.openejb.server.axis.assembler.JaxRpcServiceInfo) JavaServiceDesc(org.apache.axis.description.JavaServiceDesc) RPCProvider(org.apache.axis.providers.java.RPCProvider)

Example 4 with SOAPService

use of org.apache.axis.handlers.soap.SOAPService in project tomee by apache.

the class AxisService method createPojoWsContainer.

@Override
protected HttpListener createPojoWsContainer(ClassLoader loader, URL moduleBaseUrl, PortData port, String serviceId, Class target, Context context, String contextRoot, Map<String, Object> bdgs, ServiceConfiguration serviceInfos) throws Exception {
    ClassLoader classLoader = target.getClassLoader();
    // todo build JaxRpcServiceInfo in assembler
    JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
    // Build java service descriptor
    JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(serviceInfo, classLoader);
    JavaServiceDesc serviceDesc = javaServiceDescBuilder.createServiceDesc();
    // Create service
    RPCProvider provider = new PojoProvider();
    SOAPService service = new SOAPService(null, provider, null);
    service.setServiceDescription(serviceDesc);
    // Set class name
    service.setOption("className", target.getName());
    // Add Handler Chain
    List<HandlerInfo> handlerInfos = createHandlerInfos(port.getHandlerChains());
    HandlerInfoChainFactory handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
    service.setOption(org.apache.axis.Constants.ATTR_HANDLERINFOCHAIN, handlerInfoChainFactory);
    // Create container
    AxisWsContainer container = new AxisWsContainer(port.getWsdlUrl(), service, null, classLoader);
    wsContainers.put(serviceId, container);
    return container;
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) JaxRpcServiceInfo(org.apache.openejb.server.axis.assembler.JaxRpcServiceInfo) HandlerInfoChainFactory(org.apache.axis.handlers.HandlerInfoChainFactory) JavaServiceDesc(org.apache.axis.description.JavaServiceDesc) RPCProvider(org.apache.axis.providers.java.RPCProvider) HandlerInfo(javax.xml.rpc.handler.HandlerInfo)

Example 5 with SOAPService

use of org.apache.axis.handlers.soap.SOAPService in project tomee by apache.

the class AxisWsContainerTest method testInvokeSOAP.

public void testInvokeSOAP() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    JavaServiceDesc serviceDesc = new JavaServiceDesc();
    serviceDesc.setEndpointURL("http://127.0.0.1:8080/axis/services/echo");
    // serviceDesc.setWSDLFile(portInfo.getWsdlURL().toExternalForm());
    serviceDesc.setStyle(Style.RPC);
    serviceDesc.setUse(Use.ENCODED);
    TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
    tmr.doRegisterFromVersion("1.3");
    TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc.getUse().getEncoding());
    serviceDesc.setTypeMappingRegistry(tmr);
    serviceDesc.setTypeMapping(typeMapping);
    OperationDesc op = new OperationDesc();
    op.setName("echoString");
    op.setStyle(Style.RPC);
    op.setUse(Use.ENCODED);
    Class beanClass = EchoBean.class;
    op.setMethod(beanClass.getMethod("echoString", String.class));
    ParameterDesc parameter = new ParameterDesc(new QName("http://ws.apache.org/echosample", "in0"), ParameterDesc.IN, typeMapping.getTypeQName(String.class), String.class, false, false);
    op.addParameter(parameter);
    serviceDesc.addOperationDesc(op);
    serviceDesc.getOperations();
    ReadOnlyServiceDesc sd = new ReadOnlyServiceDesc(serviceDesc);
    Class pojoClass = cl.loadClass("org.apache.openejb.server.axis.EchoBean");
    RPCProvider provider = new PojoProvider();
    SOAPService service = new SOAPService(null, provider, null);
    service.setServiceDescription(sd);
    service.setOption("className", "org.apache.openejb.server.axis.EchoBean");
    URL wsdlURL = new URL("http://fake/echo.wsdl");
    URI location = new URI(serviceDesc.getEndpointURL());
    Map wsdlMap = new HashMap();
    AxisWsContainer container = new AxisWsContainer(wsdlURL, service, wsdlMap, cl);
    InputStream in = cl.getResourceAsStream("echoString-req.txt");
    try {
        AxisRequest req = new AxisRequest(504, "text/xml; charset=utf-8", new ServletIntputStreamAdapter(in), HttpRequest.Method.GET, new HashMap<String, String>(), location, new HashMap<String, String>(), "127.0.0.1");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        AxisResponse res = new AxisResponse("text/xml; charset=utf-8", "127.0.0.1", null, null, 8080, new ServletOutputStreamAdapter(out));
        req.setAttribute(WsConstants.POJO_INSTANCE, pojoClass.newInstance());
        container.onMessage(req, res);
        out.flush();
    // log.debug(new String(out.toByteArray()));
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignore) {
            // ignore
            }
        }
    }
}
Also used : ParameterDesc(org.apache.axis.description.ParameterDesc) HashMap(java.util.HashMap) TypeMappingRegistryImpl(org.apache.axis.encoding.TypeMappingRegistryImpl) RPCProvider(org.apache.axis.providers.java.RPCProvider) URI(java.net.URI) URL(java.net.URL) ServletIntputStreamAdapter(org.apache.openejb.server.httpd.ServletIntputStreamAdapter) JavaServiceDesc(org.apache.axis.description.JavaServiceDesc) SOAPService(org.apache.axis.handlers.soap.SOAPService) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) OperationDesc(org.apache.axis.description.OperationDesc) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ServletOutputStreamAdapter(org.apache.openejb.server.httpd.ServletOutputStreamAdapter) TypeMapping(org.apache.axis.encoding.TypeMapping) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SOAPService (org.apache.axis.handlers.soap.SOAPService)5 RPCProvider (org.apache.axis.providers.java.RPCProvider)4 JavaServiceDesc (org.apache.axis.description.JavaServiceDesc)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 JaxRpcServiceInfo (org.apache.openejb.server.axis.assembler.JaxRpcServiceInfo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 HandlerInfo (javax.xml.rpc.handler.HandlerInfo)1 MimeHeader (javax.xml.soap.MimeHeader)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 RefBoolean (lucee.commons.lang.types.RefBoolean)1 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)1 Component (lucee.runtime.Component)1