Search in sources :

Example 81 with Endpoint

use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.

the class HttpContextTest method testAuthentication.

public void testAuthentication() throws Exception {
    int port = PortAllocator.getFreePort();
    String address = "http://localhost:" + port + "/hello";
    HttpServer server = HttpServer.create(new InetSocketAddress(port), 5);
    ExecutorService threads = Executors.newFixedThreadPool(5);
    server.setExecutor(threads);
    server.start();
    Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
    HttpContext context = server.createContext("/hello");
    final String realm = "localhost.realm.com";
    context.setAuthenticator(new BasicAuthenticator(realm) {

        public boolean checkCredentials(String username, String password) {
            System.out.println("Authenticator is called");
            if (username.equals("auth-user") && password.equals("auth-pass")) {
                return true;
            }
            return false;
        }
    });
    endpoint.publish(context);
    /*

        Works but the next request hangs
 
        // Gets WSDL from the published endpoint
        int code = getHttpStatusCode(address);
        assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, code);
 */
    // access service
    QName portName = new QName("http://echo.org/", "RpcLitPort");
    QName serviceName = new QName("http://echo.org/", "RpcLitEndpoint");
    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
    Dispatch<Source> d = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
    d.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "auth-user");
    d.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "auth-pass");
    String body = "<ns0:echoInteger xmlns:ns0=\"http://echo.abstract.org/\"><arg0>2</arg0></ns0:echoInteger>";
    Source request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
    Source response = d.invoke(request);
    request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
    response = d.invoke(request);
    endpoint.stop();
    server.stop(1);
    threads.shutdown();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) HttpContext(com.sun.net.httpserver.HttpContext) ExecutorService(java.util.concurrent.ExecutorService) Service(jakarta.xml.ws.Service) Endpoint(jakarta.xml.ws.Endpoint) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Endpoint(jakarta.xml.ws.Endpoint) BasicAuthenticator(com.sun.net.httpserver.BasicAuthenticator) HttpServer(com.sun.net.httpserver.HttpServer) ExecutorService(java.util.concurrent.ExecutorService)

Example 82 with Endpoint

use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.

the class HttpContextTest method testContext.

public void testContext() throws Exception {
    int port = PortAllocator.getFreePort();
    String address = "http://localhost:" + port + "/hello";
    HttpServer server = HttpServer.create(new InetSocketAddress(port), 5);
    ExecutorService threads = Executors.newFixedThreadPool(5);
    server.setExecutor(threads);
    server.start();
    Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
    HttpContext context = server.createContext("/hello");
    endpoint.publish(context);
    // Gets WSDL from the published endpoint
    int code = getHttpStatusCode(address);
    assertEquals(HttpURLConnection.HTTP_OK, code);
    endpoint.stop();
    server.stop(1);
    threads.shutdown();
}
Also used : Endpoint(jakarta.xml.ws.Endpoint) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) ExecutorService(java.util.concurrent.ExecutorService) HttpContext(com.sun.net.httpserver.HttpContext) Endpoint(jakarta.xml.ws.Endpoint)

Example 83 with Endpoint

use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.

the class HttpStatusCodes method testUnsupportedMediaType.

public void testUnsupportedMediaType() throws Exception {
    int port = PortAllocator.getFreePort();
    String address = "http://localhost:" + port + "/hello";
    Endpoint endpoint = Endpoint.publish(address, new RpcLitEndpoint());
    // Send a request with "a/b" as Content-Type
    String message = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body/></soapenv:Envelope>";
    HTTPResponseInfo rInfo = ClientServerTestUtil.sendPOSTRequest(address, message, "a/b");
    int code = rInfo.getResponseCode();
    assertEquals(HttpURLConnection.HTTP_UNSUPPORTED_TYPE, code);
    endpoint.stop();
}
Also used : Endpoint(jakarta.xml.ws.Endpoint) HTTPResponseInfo(testutil.HTTPResponseInfo) Endpoint(jakarta.xml.ws.Endpoint)

Example 84 with Endpoint

use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTest method testMSEPR.

public void testMSEPR() throws Exception {
    int port = PortAllocator.getFreePort();
    String address = "http://localhost:" + port + "/hello";
    Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
    List<Source> metadata = new ArrayList<Source>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    String[] docs = { "RpcLitEndpoint.wsdl", "RpcLitAbstract.wsdl", "RpcLitEndpoint.xsd" };
    for (String doc : docs) {
        URL url = cl.getResource(doc);
        metadata.add(new StreamSource(url.openStream(), url.toExternalForm()));
    }
    endpoint.setMetadata(metadata);
    endpoint.publish(address);
    MemberSubmissionEndpointReference epr = endpoint.getEndpointReference(MemberSubmissionEndpointReference.class);
    endpoint.stop();
    EprUtil.validateEPR(epr, address, serviceName, portName, portTypeName, Boolean.TRUE);
    printEPR(epr);
}
Also used : Endpoint(jakarta.xml.ws.Endpoint) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) Endpoint(jakarta.xml.ws.Endpoint) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL)

Example 85 with Endpoint

use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.

the class EndpointEPRTest method testW3CEPR.

public void testW3CEPR() throws Exception {
    int port = PortAllocator.getFreePort();
    String address = "http://localhost:" + port + "/hello";
    Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
    List<Source> metadata = new ArrayList<Source>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    String[] docs = { "RpcLitEndpoint.wsdl", "RpcLitAbstract.wsdl", "RpcLitEndpoint.xsd" };
    for (String doc : docs) {
        URL url = cl.getResource(doc);
        metadata.add(new StreamSource(url.openStream(), url.toExternalForm()));
    }
    endpoint.setMetadata(metadata);
    endpoint.publish(address);
    W3CEndpointReference epr = endpoint.getEndpointReference(W3CEndpointReference.class);
    endpoint.stop();
    EprUtil.validateEPR(epr, address, null, /*serviceName*/
    null, /*portName*/
    null, /*portTypeName*/
    Boolean.FALSE);
    printEPR(epr);
}
Also used : Endpoint(jakarta.xml.ws.Endpoint) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) Endpoint(jakarta.xml.ws.Endpoint) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL)

Aggregations

Endpoint (jakarta.xml.ws.Endpoint)90 URL (java.net.URL)25 Source (javax.xml.transform.Source)22 StreamSource (javax.xml.transform.stream.StreamSource)22 ArrayList (java.util.ArrayList)16 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)10 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)10 QName (javax.xml.namespace.QName)7 HttpContext (com.sun.net.httpserver.HttpContext)6 HttpServer (com.sun.net.httpserver.HttpServer)5 InetSocketAddress (java.net.InetSocketAddress)5 HashMap (java.util.HashMap)5 ExecutorService (java.util.concurrent.ExecutorService)5 HTTPResponseInfo (testutil.HTTPResponseInfo)5 EndpointImpl (com.sun.xml.ws.transport.http.server.EndpointImpl)4 EndpointReference (jakarta.xml.ws.EndpointReference)4 Transformer (javax.xml.transform.Transformer)4 TransformerFactory (javax.xml.transform.TransformerFactory)4 StreamResult (javax.xml.transform.stream.StreamResult)4 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)3