Example usage for javax.xml.ws Service getPort

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

Introduction

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

Prototype

public <T> T getPort(Class<T> serviceEndpointInterface, WebServiceFeature... features) 

Source Link

Document

The getPort method returns a proxy.

Usage

From source file:org.openiam.provision.service.RemoteConnectorAdapter.java

private ConnectorService getService(ProvisionConnector connector) {
    try {//from   w ww  .  j a v a2s .  com

        QName SERVICE_NAME = new QName(connector.getServiceUrl());
        QName PORT_NAME = new QName(connector.getServiceNameSpace(), connector.getServicePort());

        Service service = Service.create(SERVICE_NAME);
        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, connector.getServiceUrl());

        ConnectorService port = service.getPort(
                new QName(connector.getServiceNameSpace(), connector.getServicePort()), ConnectorService.class);
        return port;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

From source file:org.opennaas.extensions.bod.autobahn.protocol.AutobahnProtocolSession.java

private <T> T createSoapService(String uri, QName serviceName, QName portName, Class<T> clazz)
        throws ProtocolException {
    /*/*  w w w .ja  v a  2s  .  c  o m*/
     * The JAXWS SPI uses the context class loader to locate an implementation. We therefore make sure the context class loader is set to our
     * class loader.
     */
    Thread thread = Thread.currentThread();
    ClassLoader oldLoader = thread.getContextClassLoader();
    try {
        thread.setContextClassLoader(getClass().getClassLoader());
        Service service = Service.create(serviceName);
        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, uri);
        return service.getPort(portName, clazz);
    } catch (WebServiceException e) {
        throw new ProtocolException("Failed to create Autobahn session: " + e.getMessage(), e);
    } finally {
        thread.setContextClassLoader(oldLoader);
    }
}

From source file:org.socraticgrid.docmgr.DocumentManagerJob.java

private void handleMirthMessage(String ticket, MirthMessage mirthMsg) {

    //Check that url was sent, otherwise skip
    if ((mirthMsg.getWsdl() == null) || mirthMsg.getWsdl().isEmpty()) {
        log.debug("Skipping mirth routing, ticket: " + ticket);
        return;//w ww . jav  a 2  s. c o  m
    }

    try { // This code block invokes the MirthOrders:acceptMessage operation on web service
        javax.xml.ws.Service myService = new ServiceUtil().createService("MirthOrders.wsdl",
                "http://components.mule.server.mirth.webreach.com", "_Proxy7Service");
        com.webreach.mirth.server.mule.components.Proxy7 port = myService.getPort(
                new javax.xml.namespace.QName("http://components.mule.server.mirth.webreach.com", "Orders"),
                com.webreach.mirth.server.mule.components.Proxy7.class);
        ((javax.xml.ws.BindingProvider) port).getRequestContext()
                .put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, mirthMsg.getWsdl());
        port.acceptMessage(mirthMsg.getBody());

        log.debug("Document sent to mirth, ticket: " + ticket);
    } catch (Exception e) {
        log.error("Error sending document to mirth, ticket: " + ticket, e);
    }

}

From source file:org.socraticgrid.docmgr.NHINQueryProcessor.java

public void handleQueryMessage(String ticket, NHINQueryMessage msg) {

    try { // Call Web Service Operation
        List<WebServiceFeature> wsfeatures = new ArrayList<WebServiceFeature>();
        wsfeatures.add(new MTOMFeature(0));
        WebServiceFeature[] wsfeaturearray = wsfeatures.toArray(new WebServiceFeature[0]);

        javax.xml.ws.Service myService = new ServiceUtil().createService("EntityDocQuery.wsdl",
                "urn:org:socraticgrid:entitydocquery", "EntityDocQuery");
        org.socraticgrid.entitydocquery.EntityDocQueryPortType port = myService.getPort(
                new javax.xml.namespace.QName("urn:gov:hhs:fha:nhinc:entitydocquery", "EntityDocQueryPortSoap"),
                org.socraticgrid.entitydocquery.EntityDocQueryPortType.class);
        ((javax.xml.ws.BindingProvider) port).getRequestContext().put(
                javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                PropertyAccessor.getProperty(DocumentManagerImpl.REPOSITORY_PROPERTY_FILE,
                        DocumentManagerImpl.NHINDOCQUERY_ENDPOINT_PROP));
        ((javax.xml.ws.BindingProvider) port).getRequestContext().put("com.sun.xml.ws.request.timeout",
                3 * 60 * 1000);/* w w  w .  j  a v a2  s  .  com*/
        ((javax.xml.ws.BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.request.timeout",
                3 * 60 * 1000);

        RespondingGatewayCrossGatewayQueryRequestType gatewayQueryRequest = new RespondingGatewayCrossGatewayQueryRequestType();
        AdhocQueryRequest adhocQueryRequest = createQuery(msg);
        AssertionType assertion = createAssertion(msg);
        gatewayQueryRequest.setAdhocQueryRequest(adhocQueryRequest);
        gatewayQueryRequest.setAssertion(assertion);

        AdhocQueryResponse result = port.respondingGatewayCrossGatewayQuery(gatewayQueryRequest);

        //Compare gateway results with local repository
        List<NewDocInfo> newDocs = findNewDocuments(result, adhocQueryRequest);

        //Start async retrieve of new documents
        for (NewDocInfo newDoc : newDocs) {
            startRetrieve(newDoc, assertion, msg.getPatientUnitNumber(), msg.getHomeCommunityId(),
                    PropertyAccessor.getProperty(DocumentManagerImpl.REPOSITORY_PROPERTY_FILE,
                            DocumentManagerImpl.INBOUND_DOCUMENT_REPOSITORY_ID_PROP),
                    new DocumentManagerImpl().generateUniqueId(null).getUniqueId(), msg.getCallbackURL());
        }

        //Notify caller of status
        doCallback(true, "Success", ticket, msg.getCallbackURL(), newDocs);
    } catch (Exception e) {
        //Handle custom exceptions here
        log.error("Error handling NHIN query message.", e);

        //Notify caller of status
        doCallback(false, e.getMessage(), ticket, msg.getCallbackURL(), new LinkedList<NewDocInfo>());
    }

}

From source file:org.socraticgrid.docmgr.NHINRetrieveProcessor.java

public void handleRetrieveMessage(String ticket, NHINRetrieveMessage msg) {

    log.debug("Handling retrieve document for ticket: " + ticket);

    try { // Call Web Service Operation
        XStream xstream = new XStream();
        xstream.alias("DocumentInfoType", DocumentInfoType.class);
        xstream.alias("ExtrinsicObjectType", ExtrinsicObjectType.class);
        xstream.alias("AssertionType", AssertionType.class);

        javax.xml.ws.Service myService = new ServiceUtil().createService("EntityDocRetrieve.wsdl",
                "urn:org:socraticgrid:entitydocretrieve", "EntityDocRetrieve");
        org.socraticgrid.entitydocretrieve.EntityDocRetrievePortType port = myService.getPort(
                new javax.xml.namespace.QName("urn:org:socraticgrid:entitydocretrieve",
                        "EntityDocRetrievePortSoap"),
                org.socraticgrid.entitydocretrieve.EntityDocRetrievePortType.class);
        ((javax.xml.ws.BindingProvider) port).getRequestContext().put(
                javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                PropertyAccessor.getProperty(DocumentManagerImpl.REPOSITORY_PROPERTY_FILE,
                        DocumentManagerImpl.NHINDOCRETRIEVE_ENDPOINT_PROP));

        RespondingGatewayCrossGatewayRetrieveRequestType gatewayRetrieveRequest = new RespondingGatewayCrossGatewayRetrieveRequestType();
        gatewayRetrieveRequest.setAssertion((AssertionType) xstream.fromXML(msg.getAssertionXML()));
        DocumentRequest docRequest = new DocumentRequest();
        docRequest.setHomeCommunityId(msg.getRemoteHomeCommunityId());
        docRequest.setRepositoryUniqueId(msg.getRemoteRepositoryId());
        docRequest.setDocumentUniqueId(msg.getRemoteDocumentUniqueId());
        RetrieveDocumentSetRequestType docRequestSet = new RetrieveDocumentSetRequestType();
        docRequestSet.getDocumentRequest().add(docRequest);
        gatewayRetrieveRequest.setRetrieveDocumentSetRequest(docRequestSet);

        log.info("Beginning retrieve request for document: " + docRequest.getDocumentUniqueId()
                + ", in repository: " + docRequest.getRepositoryUniqueId() + ", in home comm id: "
                + docRequest.getHomeCommunityId());
        RetrieveDocumentSetResponseType result = port
                .respondingGatewayCrossGatewayRetrieve(gatewayRetrieveRequest);

        //Store result in local repository
        storeDocument(msg.getLocalHomeCommunityId(), msg.getLocalRepositoryId(), msg.getLocalDocumentUniqueId(),
                msg.getLocalPatientId(), (ExtrinsicObjectType) xstream.fromXML(msg.getExtrinsicXML()), result);

        //Notify caller of status
        doCallback(true, "Success.", ticket, msg.getCallbackURL(),
                (DocumentInfoType) xstream.fromXML(msg.getDocumentInfoXML()));

    } catch (Exception e) {
        //Handle custom exceptions here
        log.error("Error handling NHIN task message.", e);

        //Notify caller of status
        doCallback(true, e.getMessage(), ticket, msg.getCallbackURL(), null);
    }/*w ww.  j a va 2  s .  c  om*/
}

From source file:org.webcurator.core.archive.dps.DPSArchive.java

private ProducerWebServices getProducerWebServices() {
    synchronized (this) {
        if (producerWsdlUrl == null) {
            if (this.depositServerBaseUrl != null && producerWsdlRelativePath != null) {
                producerWsdlUrl = this.depositServerBaseUrl + producerWsdlRelativePath;
            }//ww w  .j av a 2 s.c o m
        }
    }
    /*
     * Ideally, we should be using the following call:
     * return WebServiceLocator.getInstance().lookUp(ProducerWebServices.class, producerWsdlUrl);
     * which uses the DPS SDK class com.exlibris.digitool.locator.WebServiceLocator.
     * 
     * However, the WebServiceLocator class from DPS SDK seems to be caching the web service
     * handle and this handle, when not used for several hours, seems to become stale, throwing
     * up exceptions.
     * 
     * So instead of using the DPS SDK's WebServiceLocator class, we are forced to use the 
     * following low-level logic to bind to the Producer web service. The following code 
     * has been created by copying the required code segment from the
     * WebServiceLocator.lookUp() method by ExLibris.
     */
    String serviceEndpointInterfaceName = ProducerWebServices.class.getSimpleName();
    URL wsdlUrl = null;
    String wsdlUrlStr = producerWsdlUrl;
    try {
        wsdlUrl = new URL(wsdlUrlStr);
    } catch (Exception e) {
        log.error("Failed to build WSDL URL from " + wsdlUrlStr + " - Web service lookup of "
                + serviceEndpointInterfaceName + " will fail", e);
        e.printStackTrace();
    }
    QName serviceName = new QName("http://dps.exlibris.com/", serviceEndpointInterfaceName);
    Service service = Service.create(wsdlUrl, serviceName);
    QName portName = new QName("http://dps.exlibris.com/",
            (new StringBuilder()).append(serviceEndpointInterfaceName).append("Port").toString());
    return service.getPort(portName, ProducerWebServices.class);
}