Example usage for javax.xml.ws Dispatch invoke

List of usage examples for javax.xml.ws Dispatch invoke

Introduction

In this page you can find the example usage for javax.xml.ws Dispatch invoke.

Prototype

public T invoke(T msg);

Source Link

Document

Invoke a service operation synchronously.

Usage

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

@SuppressWarnings("unchecked")
private static <T extends Object> T getResponse(QName serviceQName, QName portQName, String endpointAddress,
        HTTPRequestMethod method, T postSource, BindingProperties bindingProperties, Class<T> type,
        Map<String, Object> headerParams) throws WebServiceException {

    Service service = Service.create(serviceQName);
    URI endpointURI;/*from  w  w w.  jav  a 2 s  .co m*/
    try {
        if (bindingProperties != null) {
            // if BindingProperties had endpointAddress defined, then use
            // it instead of the endpointAddress passed in from arguments.
            String endAddress = bindingProperties.getEndpointAddress();
            if (endAddress != null) {
                endpointAddress = endAddress;
            }
        }
        endpointURI = new URI(endpointAddress);
    } catch (URISyntaxException e) {
        throw new WebServiceException(e);
    }

    String endpointPath = null;
    String endpointQueryString = null;
    if (endpointURI != null) {
        endpointPath = endpointURI.getRawPath();
        endpointQueryString = endpointURI.getRawQuery();
    }

    service.addPort(portQName, HTTPBinding.HTTP_BINDING, endpointAddress);

    Dispatch<T> d = service.createDispatch(portQName, type, Service.Mode.MESSAGE);

    Map<String, Object> requestContext = d.getRequestContext();
    requestContext.put(MessageContext.HTTP_REQUEST_METHOD, method.toString());
    requestContext.put(MessageContext.QUERY_STRING, endpointQueryString);
    requestContext.put(MessageContext.PATH_INFO, endpointPath);

    Map<String, List<String>> reqHeaders = null;
    if (bindingProperties != null) {
        String httpBasicAuthUsername = bindingProperties.getHttpBasicAuthUsername();
        if (httpBasicAuthUsername != null) {
            requestContext.put(BindingProvider.USERNAME_PROPERTY, httpBasicAuthUsername);
            String httpBasicAuthPassword = bindingProperties.getHttpBasicAuthPassword();
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, httpBasicAuthPassword);
        }

        int connectionTimeout = bindingProperties.getConnectionTimeout();
        requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, Integer.valueOf(connectionTimeout));

        int requestTimeout = bindingProperties.getRequestTimeout();
        requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, Integer.valueOf(requestTimeout));

        Map<String, List<String>> httpHeaders = bindingProperties.getHttpHeaders();
        if (httpHeaders != null && !httpHeaders.isEmpty()) {
            reqHeaders = (Map<String, List<String>>) requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
            if (reqHeaders == null) {
                reqHeaders = new HashMap<String, List<String>>();
                requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
            }
            for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
                reqHeaders.put(entry.getKey(), entry.getValue());
            }
        }
    }

    // Parameters to pass in http header
    if (headerParams != null && headerParams.size() > 0) {
        if (null == reqHeaders) {
            reqHeaders = new HashMap<String, List<String>>();
        }
        Set<Entry<String, Object>> entries = headerParams.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            List<String> valList = new ArrayList<String>();
            valList.add((String) entry.getValue());
            reqHeaders.put(entry.getKey(), valList);
            requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
        }
    }

    logger.info("Invoking HTTP '" + method + "' request with URL: " + endpointAddress);

    T result = d.invoke(postSource);
    return result;
}

From source file:org.apache.hise.engine.jaxws.HISEJaxWSClient.java

@Transactional
public Node invoke(Node message, Node epr) {
    try {//ww w.  j  a va  2s.  co m

        Dispatch<SOAPMessage> dispatch = destinationService.createDispatch(destinationPort, SOAPMessage.class,
                Service.Mode.MESSAGE);

        String address = getAddressFromEpr(epr);
        if (!address.equals("")) {
            __log.debug("sending to address " + address);
            dispatch.getRequestContext().put(Dispatch.ENDPOINT_ADDRESS_PROPERTY, address);
        }

        SOAPMessage m;
        m = messageFactory.createMessage();
        Document doc = m.getSOAPBody().getOwnerDocument();
        m.getSOAPBody().appendChild(doc.importNode(message, true));
        return dispatch.invoke(m).getSOAPBody();
    } catch (SOAPException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.ebayopensource.turmeric.runtime.tests.common.sif.tester.ServicePayloadExecutor.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private void invokeAsyncSync(ExecutionScope scope, Service svc, List<Object> outParams) throws Exception {
    Object[] inParams = null;/* w ww  . ja  v  a  2  s  . c  o  m*/
    if (useInParams) {
        inParams = new Object[] { message };
    }

    Dispatch dispatch = null;
    Object obj = null;
    try {
        dispatch = svc.createDispatch(operationName);
        obj = dispatch.invoke(inParams);
        outParams.add(obj);
        assertNotExpectingException();
        if (assertPayload != null) {
            byte payload[] = (byte[]) dispatch.getResponseContext().get("PAYLOAD");
            assertPayload.assertPayload(scope, svc, payload);
        }
        if (assertResponse != null) {
            assertResponse.assertResponse(scope, svc, new DispatchAssertableResponse(dispatch));
        }
    } finally {

    }
}

From source file:org.fireflow.pdl.fpdl.test.service.callback.TheCallbackServiceProcessTest1.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from  w w  w. j a  va  2s  .  c  o m*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {
                ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0);
                ((ProcessDescriptorImpl) descriptor).setPublishState(true);
                stmt.updateProcessDescriptor(descriptor);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    //TODO WorkflowServer?webservice

    /*
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
       callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
    }
    */

    //3???      
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //??
            try {

                ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null);

                if (processInstance != null) {
                    processInstanceId = processInstance.getId();
                }

            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (WorkflowProcessNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //JaxwsWebservice      
    Environment env = fireflowRuntimeContext.getEngineModule(Environment.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;
        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">"
            + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");

    Assert.assertEquals(responseResult, response2);

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl.test.service.callback.WebserviceStartProcessTest.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??//from w ww  . j a  v  a2  s .co m
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0);
                ((ProcessDescriptorImpl) descriptor).setPublishState(true);
                stmt.updateProcessDescriptor(descriptor);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    //TODO WorkflowServer?webservice

    //      WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    //      try {
    //         callbackManager.publishAllCallbackServices();
    //      } catch (WebservicePublishException e1) {
    //         // TODO Auto-generated catch block
    //         e1.printStackTrace();
    //      }

    //JaxwsWebservice      
    Environment env = fireflowRuntimeContext.getEngineModule(Environment.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;

        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId
            + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");
    String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1");
    Assert.assertEquals(responseResult, response2);

    Assert.assertNotNull(response1);

    this.processInstanceId = response1;

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl20.test.service.callback.TheCallbackServiceProcessTest1.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??//  w ww . java2s. c o m
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //3???      
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //??
            try {

                ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null);

                if (processInstance != null) {
                    processInstanceId = processInstance.getId();
                }

            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (WorkflowProcessNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;
        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">"
            + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");

    Assert.assertEquals(responseResult, response2);

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl20.test.service.callback.WebserviceStartProcessTest.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from   w  w w .  jav  a  2  s .  co m*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;

        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId
            + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");
    String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1");
    Assert.assertEquals(responseResult, response2);

    Assert.assertNotNull(response1);

    this.processInstanceId = response1;

    this.assertResult(session);
}

From source file:org.wso2.carbon.connector.rm.ReliableMessage.java

/**
 * This method used to invoke backend reliable message service.
 *
 * @param messageContext ESB messageContext.
 * @throws ConnectException//from   w  w w  .ja va2  s  . com
 */
private void invokeBackendRMService(MessageContext messageContext) throws ConnectException {
    log.debug("Backend service invoking");
    if (messageContext.getProperty(RMConstants.RM_PARAMS) == null
            || messageContext.getProperty(RMConstants.SPRING_BUS) == null) {
        String message = "Connector configuration not found";
        log.error(message);
        throw new ConnectException(message);
    }

    RMParameters inputParams = (RMParameters) messageContext.getProperty(RMConstants.RM_PARAMS);
    Bus springBus = (Bus) messageContext.getProperty(RMConstants.SPRING_BUS);
    Dispatch<Source> sourceDispatch = createDispatch(inputParams, messageContext);
    Source source = new StreamSource(
            ReliableMessageUtil.getSOAPEnvelopAsStreamSource(messageContext.getEnvelope()));
    Source response = sourceDispatch.invoke(source);
    setResponse(messageContext, response);
    // shutdown bus
    springBus.shutdown(true);
}