Java Code Examples for javax.xml.ws.Service#createDispatch()

The following examples show how to use javax.xml.ws.Service#createDispatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MeetingPlannerTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
public void bookDispatch() throws Exception {
    final Service service = Service.create(
            new URL("http://127.0.0.1:" + JAX_WS_PORT + "/demo/meeting-planner?wsdl"),
            new QName("http://jaxws.example.superbiz.org/", "MeetingPlannerImplService"));
    final Dispatch<Source> dispatch = service.createDispatch(new QName("http://jaxws.example.superbiz.org/", "MeetingPlannerImplPort"), Source.class, Service.Mode.PAYLOAD);

    Date currentDate = new Date();
    LocalDateTime nowPlusTwoDays = LocalDateTime.from(currentDate.toInstant().atZone(ZoneId.systemDefault())).plusDays(2);
    String dateArgument = nowPlusTwoDays.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

    String request = "<ns1:book xmlns:ns1=\"http://jaxws.example.superbiz.org/\"><arg0>"+ dateArgument +"</arg0></ns1:book>";
    Source invoke = dispatch.invoke(new StreamSource(new StringReader(request)));
    String result = sourceToXMLString(invoke);

    assertTrue(result.contains("<return>true</return>"));
}
 
Example 2
Source File: DispatchXMLClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamSourceMESSAGE() throws Exception {
    /*URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService(wsdl, serviceName);
    assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat",
                    "http://localhost:"
                    + port
                    + "/XMLService/XMLDispatchPort");

    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    StreamSource reqMsg = new StreamSource(is);
    assertNotNull(reqMsg);

    Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
    Source source = disp.invoke(reqMsg);
    assertNotNull(source);

    String streamString = StaxUtils.toString(source);
    Document doc = StaxUtils.read(new StringReader(streamString));
    assertEquals("greetMeResponse", doc.getFirstChild().getLocalName());
    assertEquals("Hello tli", doc.getFirstChild().getTextContent());
}
 
Example 3
Source File: WSEndpointReference.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 4
Source File: WSEndpointReference.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example 5
Source File: SecureWSConnector.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void execute(ExecutionContext executionContext) throws Exception {
    final QName serviceQName = new QName(serviceNS, serviceName);
    final QName portQName = new QName(serviceNS, portName);
    final Service service = Service.create(serviceQName);
    service.addPort(portQName, binding, endPointAddress);
    final Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
    
    if (SOAPAction != null) {
      dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
      dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, SOAPAction);
    }
    
    this.response = dispatch.invoke(new StreamSource(new StringReader(request)));

}
 
Example 6
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 7
Source File: WSEndpointReference.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 8
Source File: WSEndpointReference.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example 9
Source File: Test.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 10
Source File: WSEndpointReference.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example 11
Source File: WSEndpointReference.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 12
Source File: WSEndpointReference.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example 13
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 14
Source File: WebServiceCall.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
public void execute(ConnectorExecutionContext executionContext) throws Exception {
	if (StringUtil.isEmpty(namespaceURI)) {
		throw new FoxBPMConnectorException("连接器(执行一个Web服务)命名空间表达式为空!");
	}
	if (StringUtil.isEmpty(portName)) {
		throw new FoxBPMConnectorException("连接器(执行一个Web服务)端口名表达式为空!");
	}
	if (StringUtil.isEmpty(serviceName)) {
		throw new FoxBPMConnectorException("连接器(执行一个Web服务)服务名表达式为空!");
	}
	
	if (StringUtil.isEmpty(endpointAddress)) {
		throw new FoxBPMConnectorException("连接器(执行一个Web服务)端点地址表达式为空!");
	}
	if (StringUtil.isEmpty(request)) {
		throw new FoxBPMConnectorException("连接器(执行一个Web服务)请求内容表达式为空!");
	}
	
	QName portQName = new QName(namespaceURI, portName);
	Service service = Service.create(new QName(namespaceURI, serviceName));
	service.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
	StreamSource xmlSource = new StreamSource(new StringReader(request));
	Dispatch<Source> dispatchSource = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
	Source source = dispatchSource.invoke(xmlSource);
	StreamResult result = new StreamResult(new ByteArrayOutputStream());
	Transformer trans = TransformerFactory.newInstance().newTransformer();
	trans.transform(source, result);
	ByteArrayOutputStream baos = (ByteArrayOutputStream) result.getOutputStream();
	response = new String(baos.toByteArray());
}
 
Example 15
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStAXSourcePAYLOAD() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    Service service = Service.create(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<StAXSource> disp = service.createDispatch(PORT_NAME, StAXSource.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");
    QName opQName = new QName("http://apache.org/hello_world_soap_http", "greetMe");
    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);

    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    StAXSource staxSourceReq = new StAXSource(StaxUtils.createXMLStreamReader(is));
    assertNotNull(staxSourceReq);
    Source resp = disp.invoke(staxSourceReq);
    assertNotNull(resp);
    assertTrue(resp instanceof StAXSource);
    String expected = "Hello TestSOAPInputMessage";
    String actual = StaxUtils.toString(StaxUtils.read(resp));
    assertTrue("Expected: " + expected, actual.contains(expected));
}
 
Example 16
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 17
Source File: WSEndpointReference.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 18
Source File: SecureWSConnector.java    From fixflow with Apache License 2.0 5 votes vote down vote up
public void execute(ExecutionContext executionContext) throws Exception {
	 final QName serviceQName = new QName(serviceNS, serviceName);
	    final QName portQName = new QName(serviceNS, portName);
	    final Service service = Service.create(serviceQName);
	    service.addPort(portQName, binding, endPointAddress);
	    final Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
	    
	    if (SOAPAction != null) {
	      dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
	      dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, SOAPAction);
	    }
	    
	    this.response = dispatch.invoke(new StreamSource(new StringReader(request)));
}
 
Example 19
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 20
Source File: X509TokenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAsymmetricIssuerSerialDispatch() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509TokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricIssuerSerialOperationPort");

    Dispatch<Source> disp = service.createDispatch(portQName, Source.class, Mode.PAYLOAD);
    updateAddressPort(disp, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(disp);
    }

    // We need to set the wsdl operation name here, or otherwise the policy layer won't pick
    // up the security policy attached at the operation level
    QName wsdlOperationQName = new QName(NAMESPACE, "DoubleIt");
    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, wsdlOperationQName);

    String req = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">"
        + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    Source source = new StreamSource(new StringReader(req));
    source = disp.invoke(source);

    Node nd = StaxUtils.read(source);
    if (nd instanceof Document) {
        nd = ((Document)nd).getDocumentElement();
    }
    Map<String, String> ns = new HashMap<>();
    ns.put("ns2", "http://www.example.org/schema/DoubleIt");
    XPathUtils xp = new XPathUtils(ns);
    Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", nd, XPathConstants.STRING);
    assertEquals(StaxUtils.toString(nd), "50", o);

    bus.shutdown(true);
}