Example usage for javax.xml.ws Service addPort

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

Introduction

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

Prototype

public void addPort(QName portName, String bindingId, String endpointAddress) 

Source Link

Document

Creates a new port for the service.

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;//from w w  w  .  j  a v a2s . c  om
}

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   ww w  .  j av  a  2 s.c  om
}

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  ww w. ja v a  2 s. c o 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.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());
        }/*  w w  w.j ava 2 s  .c om*/
        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: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: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;
}

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

/**
 * Creates a JAX-WS dispatcher./* w w w  .  ja va  2  s.  c om*/
 * 
 * @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: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  w w  . ja  v a  2 s .c  om*/
}

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 ww  . j av  a  2  s.  c o m

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

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

From source file:org.atricore.idbus.capabilities.sso.main.binding.SamlR2SoapBinding.java

@Override
public Object sendMessage(MediationMessage message) throws IdentityMediationException {

    if (logger.isTraceEnabled())
        logger.trace("Sending new SAML 2.0 message using SOAP Binding");

    EndpointDescriptor endpoint = message.getDestination();

    String soapEndpoint = endpoint.getLocation();

    // ---------------------------------------------------------
    // Setup CXF Client
    // ---------------------------------------------------------
    Service service = Service.create(SAMLR2MessagingConstants.SERVICE_NAME);
    service.addPort(SAMLR2MessagingConstants.PORT_NAME, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,
            endpoint.getLocation());/*from  w  ww.jav a  2 s .  c o  m*/

    Object content = message.getContent();

    if (!(content instanceof RequestAbstractType)) {
        throw new IdentityMediationException("Unsupported content " + content);
    }

    String soapMethodName = content.getClass().getSimpleName();
    soapMethodName = "saml" + soapMethodName.substring(0, soapMethodName.length() - 4); // Remove Type

    if (logger.isTraceEnabled())
        logger.trace("Using soap method [" + soapMethodName + "]");

    SAMLRequestPortType port = service.getPort(SAMLR2MessagingConstants.PORT_NAME, SAMLRequestPortType.class);

    if (logger.isTraceEnabled())
        logger.trace("Sending SSO SOAP Request: " + content);

    try {
        Method soapMethod = port.getClass().getMethod(soapMethodName, content.getClass());

        Object o = soapMethod.invoke(port, content);

        if (logger.isTraceEnabled())
            logger.trace("Received SSO SOAP Response: " + o);

        return o;

    } catch (NoSuchMethodException e) {
        throw new IdentityMediationException(
                "SOAP Method not impelmented " + soapMethodName + ": " + e.getMessage(), e);

    } catch (Exception e) {
        throw new IdentityMediationException("SOAP error: " + e.getMessage(), e);
    }

}