Search in sources :

Example 76 with Service

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

the class ClientTest method createDispatchJAXB.

Dispatch createDispatchJAXB() {
    Service service = Service.create(new QName("urn:test", "Hello"));
    JAXBContext context = createJAXBContext(ObjectFactory.class);
    QName portQName = new QName("urn:test", "HelloPort");
    service.addPort(portQName, "http://schemas.xmlsoap.org/wsdl/soap/http", helloPortAddress);
    Dispatch dispatch = service.createDispatch(portQName, context, Service.Mode.PAYLOAD);
    return dispatch;
}
Also used : QName(javax.xml.namespace.QName) Service(jakarta.xml.ws.Service) Dispatch(jakarta.xml.ws.Dispatch) JAXBContext(jakarta.xml.bind.JAXBContext)

Example 77 with Service

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

the class SOAPAction1Test method testSOAPActionWithDispatch_WithUse_false.

// since use property is false, action property is ineffective
public void testSOAPActionWithDispatch_WithUse_false() throws JAXBException {
    TestEndpoint1 port = new TestEndpointService1().getTestEndpointPort1();
    String address = (String) ((BindingProvider) port).getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    Service s = Service.create(new QName("http://client.soapaction_use.server/", "TestEndpointService1"));
    s.addPort(new QName("http://client.soapaction_use.server/", "TestEndpointPort1"), SOAPBinding.SOAP11HTTP_BINDING, address);
    Dispatch<Object> d = s.createDispatch(new QName("http://client.soapaction_use.server/", "TestEndpointPort1"), JAXBContext.newInstance(ObjectFactory.class), Service.Mode.PAYLOAD);
    ((BindingProvider) d).getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://example/action");
    ((BindingProvider) d).getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, false);
    JAXBElement<String> r = (JAXBElement<String>) d.invoke(new ObjectFactory().createEchoSOAPAction("dummy"));
    assertEquals(empty_action, r.getValue());
}
Also used : QName(javax.xml.namespace.QName) Service(jakarta.xml.ws.Service) BindingProvider(jakarta.xml.ws.BindingProvider) JAXBElement(jakarta.xml.bind.JAXBElement)

Example 78 with Service

use of jakarta.xml.ws.Service 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 79 with Service

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

the class SubDomainTest method invoke.

private void invoke(String host, String address) {
    // access service
    QName portName = new QName("", "");
    QName serviceName = new QName("", "");
    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
    Dispatch<Source> d = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
    Map<String, Object> requestContext = d.getRequestContext();
    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
    // introduce() request
    String body = "<ns2:introduce xmlns:ns2='urn:test'><arg0>" + host + "</arg0></ns2:introduce>";
    Source request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
    d.invoke(request);
    // rememeberMe() request
    body = "<ns2:rememberMe xmlns:ns2='urn:test'/>";
    request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
    d.invoke(request);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Service(jakarta.xml.ws.Service) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 80 with Service

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

the class WhitespaceTest method invoke.

private Source invoke(String address) throws Exception {
    QName portName = new QName(NS, "RpcLitPort");
    QName serviceName = new QName(NS, "RpcLitEndpoint");
    Service service = Service.create(new URL(address + "?wsdl"), serviceName);
    Dispatch<Source> d = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
    String body = "<ns:add xmlns:ns='" + NS + "'>  <arg0> 10 </arg0> <arg1> 20 </arg1> </ns:add>";
    return d.invoke(new StreamSource(new StringReader(body)));
}
Also used : QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Service(jakarta.xml.ws.Service) WebService(jakarta.jws.WebService) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Aggregations

Service (jakarta.xml.ws.Service)81 QName (javax.xml.namespace.QName)45 Source (javax.xml.transform.Source)23 StreamSource (javax.xml.transform.stream.StreamSource)21 BindingProvider (jakarta.xml.ws.BindingProvider)17 Dispatch (jakarta.xml.ws.Dispatch)16 URL (java.net.URL)13 StringReader (java.io.StringReader)11 WebService (jakarta.jws.WebService)10 DataSource (jakarta.activation.DataSource)8 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)7 JAXBElement (jakarta.xml.bind.JAXBElement)7 Handler (jakarta.xml.ws.handler.Handler)7 WSBindingProvider (com.sun.xml.ws.developer.WSBindingProvider)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 JAXBContext (jakarta.xml.bind.JAXBContext)5 Binding (jakarta.xml.ws.Binding)5 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)5 SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)5