Search in sources :

Example 6 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)

Example 7 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 8 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 9 with Service

use of javax.xml.ws.Service in project ats-framework by Axway.

the class AgentServicePool method createServicePort.

private AgentService createServicePort(String host) throws AgentException {
    try {
        String protocol = AgentConfigurator.getConnectionProtocol(host);
        if (protocol == null) {
            protocol = "http";
        } else {
            SslUtils.trustAllHttpsCertificates();
            SslUtils.trustAllHostnames();
        }
        URL url = this.getClass().getResource("/META-INF/wsdl/" + AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME + ".wsdl");
        Service agentService = Service.create(url, new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME));
        AgentService agentServicePort = agentService.getPort(new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_PORT_NAME), AgentService.class);
        Map<String, Object> ctxt = ((BindingProvider) agentServicePort).getRequestContext();
        // setting ENDPOINT ADDRESS, which defines the web service URL for SOAP communication
        // NOTE: if we specify WSDL URL (...<endpoint_address>?wsdl), the JBoss server returns the WSDL on a SOAP call,
        // but we are expecting a SOAP message response and an exception is thrown.
        // The Jetty server (in ATS agents) is working in both cases.
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, protocol + "://" + host + AgentWsDefinitions.AGENT_SERVICE_ENDPOINT_ADDRESS);
        // setting timeouts
        // timeout in milliseconds
        ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        // check if new unique id must be generated each time
        if (!useNewUuId) {
            // create temp file containing caller working directory and the unique id
            String userWorkingDirectory = AtsSystemProperties.SYSTEM_USER_HOME_DIR;
            String uuiFileLocation = AtsSystemProperties.SYSTEM_USER_TEMP_DIR + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "\\ats_uid.txt";
            File uuiFile = new File(uuiFileLocation);
            // otherwise add it to the file 
            if (uuiFile.exists()) {
                String uuiFileContent = IoUtils.streamToString(IoUtils.readFile(uuiFileLocation));
                if (uuiFileContent.contains(userWorkingDirectory)) {
                    for (String line : uuiFileContent.split("\n")) {
                        if (line.contains(userWorkingDirectory)) {
                            uniqueId = line.substring(userWorkingDirectory.length()).trim();
                        }
                    }
                } else {
                    generateNewUUID();
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            } else {
                generateNewUUID();
                try {
                    uuiFile.createNewFile();
                } catch (IOException e) {
                    log.warn("Unable to create file '" + uuiFile.getAbsolutePath() + "'");
                }
                if (uuiFile.exists()) {
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            }
        } else {
            generateNewUUID();
        }
        // add header with unique session ID
        Map<String, List<String>> requestHeaders = new HashMap<>();
        requestHeaders.put(ApplicationContext.ATS_UID_SESSION_TOKEN, Arrays.asList(uniqueId));
        ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
        return agentServicePort;
    } catch (Exception e) {
        throw new AgentException("Cannot connect to Agent application on host '" + host + "' check your configuration", e);
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AgentException(com.axway.ats.agent.core.exceptions.AgentException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) IOException(java.io.IOException) URL(java.net.URL) AgentException(com.axway.ats.agent.core.exceptions.AgentException) IOException(java.io.IOException) List(java.util.List) File(java.io.File)

Example 10 with Service

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

the class XercesUsageInWebServiceTestCase method testXercesUsageInWebService.

/**
     * Test that the webservice invocation works fine
     *
     * @throws Exception
     */
@OperateOnDeployment("webservice-app-with-xerces")
@Test
public void testXercesUsageInWebService() throws Exception {
    final QName serviceName = new QName("org.jboss.as.test.integration.xerces.ws", "XercesUsageWebService");
    final URL wsdlURL = new URL(url.toExternalForm() + "XercesUsageWebService?wsdl");
    final Service service = Service.create(wsdlURL, serviceName);
    final XercesUsageWSEndpoint port = service.getPort(XercesUsageWSEndpoint.class);
    final String xml = "dummy.xml";
    final String result = port.parseUsingXerces(xml);
    Assert.assertEquals("Unexpected return message from webservice", XercesUsageWebService.SUCCESS_MESSAGE, result);
}
Also used : QName(javax.xml.namespace.QName) XercesUsageWebService(org.jboss.as.test.integration.xerces.ws.XercesUsageWebService) Service(javax.xml.ws.Service) XercesUsageWSEndpoint(org.jboss.as.test.integration.xerces.ws.XercesUsageWSEndpoint) URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

Service (javax.xml.ws.Service)138 URL (java.net.URL)125 QName (javax.xml.namespace.QName)91 Test (org.junit.Test)84 BindingProvider (javax.xml.ws.BindingProvider)39 WebServiceException (javax.xml.ws.WebServiceException)18 IOException (java.io.IOException)12 Bus (org.apache.cxf.Bus)12 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)11 InsuranceService (com.salaboy.jbpm5.dev.guide.webservice.InsuranceService)10 HashMap (java.util.HashMap)10 ServiceIface (org.jboss.as.test.integration.ws.wsse.ServiceIface)10 UseNewBusFeature (org.jboss.wsf.stack.cxf.client.UseNewBusFeature)10 MalformedURLException (java.net.MalformedURLException)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 File (java.io.File)8 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)8 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)7 Client (org.apache.cxf.endpoint.Client)7