Example usage for javax.xml.ws Service create

List of usage examples for javax.xml.ws Service create

Introduction

In this page you can find the example usage for javax.xml.ws Service create.

Prototype

public static Service create(QName serviceName) 

Source Link

Document

Creates a Service instance.

Usage

From source file:org.semispace.ws.client.SemiSpaceProxy.java

protected static WsSpace readSpaceServiceAsStandardPort(String endpointAddress) {
    QName SERVICE_NAME = new QName("http://ws.semispace.org/", "WsSpace");
    QName PORT_NAME = new QName("http://ws.semispace.org/", "WsSpacePort");

    Service service = Service.create(SERVICE_NAME);

    // Add a port to the Service
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);

    WsSpace hw = service.getPort(WsSpace.class);
    return hw;//  ww  w  .  j a v  a  2 s .  co  m
}

From source file:org.semispace.ws.client.SemiSpaceTokenProxy.java

protected static TokenWsSpace readSpaceServiceAsStandardPort(String endpointAddress) {
    QName SERVICE_NAME = new QName("http://ws.semispace.org/", "TokenWsSpace");
    QName PORT_NAME = new QName("http://ws.semispace.org/", "TokenWsSpacePort");

    Service service = Service.create(SERVICE_NAME);

    // Add a port to the Service
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);

    TokenWsSpace hw = service.getPort(TokenWsSpace.class);
    return hw;//from  w  w w  .j av a 2s.  c  o m
}

From source file:test.integ.be.fedict.hsm.ws.WSS4JTest.java

@Test
public void testSecurity() throws Exception {
    QName serviceName = new QName("http://www.example.com/test", "TestService");
    Service service = Service.create(serviceName);
    QName portName = new QName("http://www.example.com/test", "TestPort");
    String endpointAddress = this.baseURL + "test";
    LOG.debug("endpoint address: " + endpointAddress);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    BindingProvider bindingProvider = (BindingProvider) dispatch;
    SOAPBinding soapBinding = (SOAPBinding) bindingProvider.getBinding();
    List handlerChain = soapBinding.getHandlerChain();
    handlerChain.add(new WSS4JTestSOAPHandler());
    soapBinding.setHandlerChain(handlerChain);
    MessageFactory messageFactory = soapBinding.getMessageFactory();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    QName payloadName = new QName("http://www.example.com/test", "Payload", "prefix");
    SOAPBodyElement soapBodyElement = soapBody.addBodyElement(payloadName);
    soapBodyElement.addTextNode("hello world");

    SOAPMessage replyMessage = dispatch.invoke(soapMessage);
}

From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java

@SuppressWarnings("unchecked")
private static <T extends Object> T getResponse(QName serviceQName, QName portQName, String endpointAddress,
        HTTPRequestMethod method, T postSource, BindingProperties bindingProperties, Class<T> type,
        Map<String, Object> headerParams) throws WebServiceException {

    Service service = Service.create(serviceQName);
    URI endpointURI;/*from   w  ww .  j  a  v a 2 s. co m*/
    try {
        if (bindingProperties != null) {
            // if BindingProperties had endpointAddress defined, then use
            // it instead of the endpointAddress passed in from arguments.
            String endAddress = bindingProperties.getEndpointAddress();
            if (endAddress != null) {
                endpointAddress = endAddress;
            }
        }
        endpointURI = new URI(endpointAddress);
    } catch (URISyntaxException e) {
        throw new WebServiceException(e);
    }

    String endpointPath = null;
    String endpointQueryString = null;
    if (endpointURI != null) {
        endpointPath = endpointURI.getRawPath();
        endpointQueryString = endpointURI.getRawQuery();
    }

    service.addPort(portQName, HTTPBinding.HTTP_BINDING, endpointAddress);

    Dispatch<T> d = service.createDispatch(portQName, type, Service.Mode.MESSAGE);

    Map<String, Object> requestContext = d.getRequestContext();
    requestContext.put(MessageContext.HTTP_REQUEST_METHOD, method.toString());
    requestContext.put(MessageContext.QUERY_STRING, endpointQueryString);
    requestContext.put(MessageContext.PATH_INFO, endpointPath);

    Map<String, List<String>> reqHeaders = null;
    if (bindingProperties != null) {
        String httpBasicAuthUsername = bindingProperties.getHttpBasicAuthUsername();
        if (httpBasicAuthUsername != null) {
            requestContext.put(BindingProvider.USERNAME_PROPERTY, httpBasicAuthUsername);
            String httpBasicAuthPassword = bindingProperties.getHttpBasicAuthPassword();
            requestContext.put(BindingProvider.PASSWORD_PROPERTY, httpBasicAuthPassword);
        }

        int connectionTimeout = bindingProperties.getConnectionTimeout();
        requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, Integer.valueOf(connectionTimeout));

        int requestTimeout = bindingProperties.getRequestTimeout();
        requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, Integer.valueOf(requestTimeout));

        Map<String, List<String>> httpHeaders = bindingProperties.getHttpHeaders();
        if (httpHeaders != null && !httpHeaders.isEmpty()) {
            reqHeaders = (Map<String, List<String>>) requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
            if (reqHeaders == null) {
                reqHeaders = new HashMap<String, List<String>>();
                requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
            }
            for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
                reqHeaders.put(entry.getKey(), entry.getValue());
            }
        }
    }

    // Parameters to pass in http header
    if (headerParams != null && headerParams.size() > 0) {
        if (null == reqHeaders) {
            reqHeaders = new HashMap<String, List<String>>();
        }
        Set<Entry<String, Object>> entries = headerParams.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            List<String> valList = new ArrayList<String>();
            valList.add((String) entry.getValue());
            reqHeaders.put(entry.getKey(), valList);
            requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders);
        }
    }

    logger.info("Invoking HTTP '" + method + "' request with URL: " + endpointAddress);

    T result = d.invoke(postSource);
    return result;
}

From source file:org.apache.cxf.systest.jaxrs.JAXRSSoapBookTest.java

@Test
public void testHelloSoap() throws Exception {
    final QName serviceName = new QName("http://hello.com", "HelloWorld");
    final QName portName = new QName("http://hello.com", "HelloWorldPort");
    final String address = "http://localhost:" + PORT + "/test/services/hello-soap";

    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);

    HelloWorld hw = service.getPort(HelloWorld.class);

    useHelloService(hw);/*  w  ww .  jav a  2 s  .  c  o  m*/
}

From source file:org.apache.cxf.systest.jaxrs.JAXRSSoapBookTest.java

private void doTestHelloSoapCustomDataBinding(String address) throws Exception {
    final QName serviceName = new QName("http://hello.com", "HelloWorld");
    final QName portName = new QName("http://hello.com", "HelloWorldPort");

    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);

    HelloWorld hw = service.getPort(HelloWorld.class);

    Client cl = ClientProxy.getClient(hw);

    HTTPConduit http = (HTTPConduit) cl.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);

    http.setClient(httpClientPolicy);//  w w w . j  av a  2s  . c o  m

    User user = new UserImpl("Barry");
    User user2 = hw.echoUser(user);

    assertNotSame(user, user2);
    assertEquals("Barry", user2.getName());
}

From source file:io.hummer.util.ws.WebServiceClient.java

private void setRelevantAttributes(EndpointReference epr) {
    try {//  w w  w  . j a v  a2s  .  c om
        this.eprParamsAndProps.addAll(epr.getAllReferenceParameters());
        this.eprParamsAndProps.addAll(epr.getAllReferenceProperties());
        if (this.eprParamsAndProps.size() > 0) {
            if (logger.isDebugEnabled())
                logger.trace("Reference Params/Props: " + this.eprParamsAndProps);
        }

        this.endpointURL = epr.getAddress();
        String binding = SOAPBinding.SOAP11HTTP_BINDING;
        try {
            this.serviceName = epr.getServiceName().getServiceName();
            this.portName = new QName(epr.getPortName());
            service = Service.create(this.serviceName);
            service.addPort(portName, binding, this.endpointURL);
        } catch (Exception e) {
            if (endpointURL.contains("wsdl") || endpointURL.contains("WSDL")) {
                // assume that the given URL is a WSDL URL
                String wsdlURL = endpointURL;
                javax.wsdl.Service wsdlService = getSingleWSDLService(wsdlURL);
                this.serviceName = wsdlService.getQName();
                javax.wsdl.Port port = getDefaultWSDLPort(wsdlService);
                if (port instanceof SOAP12Binding)
                    binding = SOAPBinding.SOAP12HTTP_BINDING;
                this.portName = new QName(serviceName.getNamespaceURI(), port.getName());
                this.endpointURL = getAddressFromWSDLPort(port);
                service = Service.create(new URL(wsdlURL), this.serviceName);
            }
        }
    } catch (WSDLException e) {
        throw new RuntimeException("Unable to create Web service client from WSDL.", e);
    } catch (ConnectException e) {
        throw new RuntimeException("Unable to create Web service client.", e);
    } catch (Exception e) {
        // swallow
        logger.info("Error initializing Web service client.", e);
    }
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

public static synchronized Dispatch<Document> getDispatch() {
    if (dispatch == null) {
        Service service = Service.create(new QName(SOAPNS, "Service"));
        service.addPort(new QName(SOAPNS, "Port"), SOAPBinding.SOAP11HTTP_BINDING,
                ROOT + RPC_ROOT + apiVersion);

        dispatch = service.createDispatch(new QName(SOAPNS, "Port"), Document.class, Service.Mode.PAYLOAD);
        if (debug) {
            ((org.apache.cxf.jaxws.DispatchImpl<?>) dispatch).getClient().getEndpoint().getInInterceptors()
                    .add(new LoggingInInterceptor());
            ((org.apache.cxf.jaxws.DispatchImpl<?>) dispatch).getClient().getEndpoint().getOutInterceptors()
                    .add(new LoggingOutInterceptor());
        }/*from   www.  j  a  va2  s  .  c  o m*/
        HTTPConduit c = (HTTPConduit) ((org.apache.cxf.jaxws.DispatchImpl<?>) dispatch).getClient()
                .getConduit();
        HTTPClientPolicy clientPol = c.getClient();
        if (clientPol == null) {
            clientPol = new HTTPClientPolicy();
        }
        //CAMEL has a couple of HUGE HUGE pages that take a long time to render
        clientPol.setReceiveTimeout(5 * 60 * 1000);
        c.setClient(clientPol);

    }
    return dispatch;
}

From source file:com.legstar.proxy.invoke.jaxws.WebServiceInvoker.java

/**
 * Creates a JAX-WS dispatcher./*from w  w  w. ja va  2s .co  m*/
 * 
 * @return an instance of jaxws dynamic client invoker.
 * @throws WebServiceInvokerException if attempt to instantiate dispatcher
 *             fails
 */
public Dispatch<Object> createDispatcher() throws WebServiceInvokerException {
    QName serviceQname = new QName(getWsdlTargetNamespace(), getWsdlServiceName());
    QName portQname = new QName(getWsdlTargetNamespace(), getWsdlPortName());
    Service service = Service.create(serviceQname);
    service.addPort(portQname, SOAPBinding.SOAP11HTTP_BINDING, getWsdlUrl());
    Dispatch<Object> dispatcher = service.createDispatch(portQname, createJAXBContext(), Service.Mode.PAYLOAD);

    if (_log.isDebugEnabled()) {
        _log.debug("New javax.xml.ws.Dispatch created for " + getWsdlServiceName());
    }
    return dispatcher;
}

From source file:edu.duke.cabig.c3pr.webservice.integration.StudyImportExportWebServiceTest.java

private Service getService() {
    Service service = Service.create(SERVICE_NAME);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointURL.toString());
    SOAPUtils.installSecurityHandler(service);
    return service;
}