Search in sources :

Example 1 with Service

use of javax.xml.ws.Service in project jdk8u_jdk by JetBrains.

the class TestWsImport method main.

public static void main(String[] args) throws IOException {
    String javaHome = System.getProperty("java.home");
    if (javaHome.endsWith("jre")) {
        javaHome = new File(javaHome).getParent();
    }
    String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";
    if (System.getProperty("os.name").startsWith("Windows")) {
        wsimport = wsimport.concat(".exe");
    }
    Endpoint endpoint = Endpoint.create(new TestService());
    HttpServer httpServer = null;
    try {
        // Manually create HttpServer here using ephemeral address for port
        // so as to not end up with attempt to bind to an in-use port
        httpServer = HttpServer.create(new InetSocketAddress(0), 0);
        HttpContext httpContext = httpServer.createContext("/hello");
        int port = httpServer.getAddress().getPort();
        System.out.println("port = " + port);
        httpServer.start();
        endpoint.publish(httpContext);
        String address = "http://localhost:" + port + "/hello";
        Service service = Service.create(new URL(address + "?wsdl"), new QName("http://test/jaxws/sample/", "TestService"));
        String[] wsargs = { wsimport, "-p", "wstest", "-J-Djavax.xml.accessExternalSchema=all", "-J-Dcom.sun.tools.internal.ws.Invoker.noSystemProxies=true", address + "?wsdl", "-clientjar", "wsjar.jar" };
        ProcessBuilder pb = new ProcessBuilder(wsargs);
        pb.redirectErrorStream(true);
        Process p = pb.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String s = r.readLine();
        while (s != null) {
            System.out.println(s.trim());
            s = r.readLine();
        }
        p.waitFor();
        p.destroy();
        try (JarFile jarFile = new JarFile("wsjar.jar")) {
            for (Enumeration em = jarFile.entries(); em.hasMoreElements(); ) {
                String fileName = em.nextElement().toString();
                if (fileName.contains("\\")) {
                    throw new RuntimeException("\"\\\" character detected in jar file: " + fileName);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    } finally {
        endpoint.stop();
        if (httpServer != null) {
            httpServer.stop(0);
        }
        Path p = Paths.get("wsjar.jar");
        Files.deleteIfExists(p);
        p = Paths.get("wstest");
        if (Files.exists(p)) {
            try {
                Files.walkFileTree(p, new SimpleFileVisitor<Path>() {

                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        Files.delete(file);
                        return CONTINUE;
                    }

                    @Override
                    public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                        if (exc == null) {
                            Files.delete(dir);
                            return CONTINUE;
                        } else {
                            throw exc;
                        }
                    }
                });
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) HttpServer(com.sun.net.httpserver.HttpServer) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Path(java.nio.file.Path) Enumeration(java.util.Enumeration) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) HttpContext(com.sun.net.httpserver.HttpContext) Service(javax.xml.ws.Service) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Endpoint(javax.xml.ws.Endpoint) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 2 with Service

use of javax.xml.ws.Service in project jdk8u_jdk by JetBrains.

the class Test method main.

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();
    }
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Service(javax.xml.ws.Service) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 3 with Service

use of javax.xml.ws.Service in project wildfly by wildfly.

the class Usecase1TestCase method testDeclaredEndpoint.

@Test
public void testDeclaredEndpoint() throws Exception {
    final QName serviceName = new QName("org.jboss.as.test.integration.ws.anonymousPojos", "POJOImplService");
    final URL wsdlURL = new URL(baseUrl, "/anonymous-pojo-usecase1/POJOService?wsdl");
    final Service service = Service.create(wsdlURL, serviceName);
    final POJOIface port = service.getPort(POJOIface.class);
    final String result = port.echo("hello");
    Assert.assertEquals("hello from POJO", result);
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Service

use of javax.xml.ws.Service in project wildfly by wildfly.

the class Usecase2TestCase method testAnonymousEndpoint.

@Test
public void testAnonymousEndpoint() throws Exception {
    final QName serviceName = new QName("org.jboss.as.test.integration.ws.anonymousPojos", "AnonymousPOJOService");
    final URL wsdlURL = new URL(baseUrl, "/anonymous-pojo-usecase2/AnonymousPOJOService?wsdl");
    final Service service = Service.create(wsdlURL, serviceName);
    final POJOIface port = service.getPort(POJOIface.class);
    final String result = port.echo("hello");
    Assert.assertEquals("hello from anonymous POJO", result);
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Service

use of javax.xml.ws.Service in project camel by apache.

the class CxfConsumerWSRMTest method testInvokeGreeter.

@Test
public void testInvokeGreeter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    Bus clientBus = context.getRegistry().lookupByNameAndType("client-bus", Bus.class);
    assertNotNull(clientBus);
    BusFactory.setThreadDefaultBus(clientBus);
    try {
        Service service = Service.create(SERVICE_NAME);
        service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + CXFTestSupport.getPort1() + "/CxfConsumerWSRMTest/router");
        Greeter greeter = service.getPort(PORT_NAME, Greeter.class);
        greeter.greetMeOneWay("test");
    } finally {
        BusFactory.setThreadDefaultBus(null);
    }
    assertMockEndpointsSatisfied();
}
Also used : Bus(org.apache.cxf.Bus) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) Test(org.junit.Test)

Aggregations

Service (javax.xml.ws.Service)1172 URL (java.net.URL)1073 QName (javax.xml.namespace.QName)1052 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)461 Bus (org.apache.cxf.Bus)445 Test (org.junit.Test)427 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)384 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)254 JBossWSTest (org.jboss.wsf.test.JBossWSTest)239 BindingProvider (javax.xml.ws.BindingProvider)118 Client (org.apache.cxf.endpoint.Client)106 HashMap (java.util.HashMap)48 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)43 WrapThreadContextClassLoader (org.jboss.wsf.test.WrapThreadContextClassLoader)39 SamlCallbackHandler (org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler)32 WebService (javax.jws.WebService)30 STSClient (org.apache.cxf.ws.security.trust.STSClient)30 Source (javax.xml.transform.Source)29 WebServiceException (javax.xml.ws.WebServiceException)28 Handler (javax.xml.ws.handler.Handler)28