Search in sources :

Example 1 with Endpoint

use of javax.xml.ws.Endpoint in project spring-framework by spring-projects.

the class AbstractJaxWsServiceExporter method publishEndpoints.

/**
	 * Publish all {@link javax.jws.WebService} annotated beans in the
	 * containing BeanFactory.
	 * @see #publishEndpoint
	 */
public void publishEndpoints() {
    Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
    beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
    if (this.beanFactory instanceof ConfigurableBeanFactory) {
        beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
    }
    for (String beanName : beanNames) {
        try {
            Class<?> type = this.beanFactory.getType(beanName);
            if (type != null && !type.isInterface()) {
                WebService wsAnnotation = type.getAnnotation(WebService.class);
                WebServiceProvider wsProviderAnnotation = type.getAnnotation(WebServiceProvider.class);
                if (wsAnnotation != null || wsProviderAnnotation != null) {
                    Endpoint endpoint = createEndpoint(this.beanFactory.getBean(beanName));
                    if (this.endpointProperties != null) {
                        endpoint.setProperties(this.endpointProperties);
                    }
                    if (this.executor != null) {
                        endpoint.setExecutor(this.executor);
                    }
                    if (wsAnnotation != null) {
                        publishEndpoint(endpoint, wsAnnotation);
                    } else {
                        publishEndpoint(endpoint, wsProviderAnnotation);
                    }
                    this.publishedEndpoints.add(endpoint);
                }
            }
        } catch (CannotLoadBeanClassException ex) {
        // ignore beans where the class is not resolvable
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) WebServiceProvider(javax.xml.ws.WebServiceProvider) Endpoint(javax.xml.ws.Endpoint) WebService(javax.jws.WebService) CannotLoadBeanClassException(org.springframework.beans.factory.CannotLoadBeanClassException)

Example 2 with Endpoint

use of javax.xml.ws.Endpoint 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 3 with Endpoint

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

the class WSTest method main.

public static void main(String[] args) throws Exception {
    // find a free port
    ServerSocket ss = new ServerSocket(0);
    int port = ss.getLocalPort();
    ss.close();
    Endpoint endPoint1 = null;
    Endpoint endPoint2 = null;
    try {
        endPoint1 = Endpoint.publish("http://0.0.0.0:" + port + "/method1", new Method1());
        endPoint2 = Endpoint.publish("http://0.0.0.0:" + port + "/method2", new Method2());
        System.out.println("Sleep 3 secs...");
        Thread.sleep(3000);
    } finally {
        stop(endPoint2);
        stop(endPoint1);
    }
}
Also used : Endpoint(javax.xml.ws.Endpoint) ServerSocket(java.net.ServerSocket) Endpoint(javax.xml.ws.Endpoint)

Example 4 with Endpoint

use of javax.xml.ws.Endpoint in project webservices-axiom by apache.

the class MTOMSample method test.

// END SNIPPET: retrieveContent
public void test() throws Exception {
    int port = PortAllocator.allocatePort();
    Endpoint endpoint = Endpoint.publish("http://localhost:" + port + "/mtom", new MTOMService());
    retrieveContent(new URL("http://localhost:" + port + "/mtom"), "G87ZX20047", System.out);
    endpoint.stop();
}
Also used : Endpoint(javax.xml.ws.Endpoint) Endpoint(javax.xml.ws.Endpoint) URL(java.net.URL)

Aggregations

Endpoint (javax.xml.ws.Endpoint)4 URL (java.net.URL)2 HttpContext (com.sun.net.httpserver.HttpContext)1 HttpServer (com.sun.net.httpserver.HttpServer)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Enumeration (java.util.Enumeration)1 LinkedHashSet (java.util.LinkedHashSet)1 JarFile (java.util.jar.JarFile)1 WebService (javax.jws.WebService)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 WebServiceProvider (javax.xml.ws.WebServiceProvider)1