Example usage for javax.xml.soap SOAPConnectionFactory newInstance

List of usage examples for javax.xml.soap SOAPConnectionFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.soap SOAPConnectionFactory newInstance.

Prototype

public static SOAPConnectionFactory newInstance() throws SOAPException, UnsupportedOperationException 

Source Link

Document

Creates an instance of the default SOAPConnectionFactory object.

Usage

From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java

public HttpResponseBean makeCougarSOAPCall(SOAPMessage message, String serviceName, String version,
        HttpCallBean httpBean) {/* ww w . j a v  a 2s  . co m*/
    try {

        //Debugging code
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        message.writeTo(outStream);
        SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = connectionFactory.createConnection();

        // this can either be a SOAPException or SOAPMessage
        HttpResponseBean responseBean = new HttpResponseBean();
        Object response;

        String host = httpBean.getHost();
        String port = httpBean.getPort();

        String endPoint = "http://" + host + ":" + port + "/" + serviceName + "Service/" + version;

        try {

            response = connection.call(message, endPoint);

        } catch (SOAPException e) {
            response = e;
        } finally {
            connection.close();
        }

        responseBean.setResponseObject(handleResponse(response, responseBean));

        return responseBean;

    } catch (SOAPException | IOException | ParserConfigurationException | TransformerException e) {
        throw new RuntimeException(SOAP_CALL_TEXT + e, e);
    }

}

From source file:com.wandrell.example.swss.test.util.test.integration.endpoint.AbstractITEndpoint.java

/**
 * Calls the web service being tested and returns the response.
 *
 * @param request/*  w  w  w. j  av  a  2s.c  o  m*/
 *            request to the web service
 * @return the web service response
 * @throws SOAPException
 *             never, this is a required declaration
 */
protected final SOAPMessage callWebService(final SOAPMessage request) throws SOAPException {
    final SOAPConnectionFactory soapConnectionFactory; // Connection factory
    final MimeHeaders headers; // Message headers

    soapConnectionFactory = SOAPConnectionFactory.newInstance();

    // Sets the SOAP action
    headers = request.getMimeHeaders();
    headers.addHeader("SOAPAction", soapAction);
    request.saveChanges();

    return soapConnectionFactory.createConnection().call(request, wsURL);
}

From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java

/**
 * Executes SOAP message//  w  ww. ja v a 2s  .c om
 * 
 * @param endpointUrl SOAP endpoint
 * @param message SOAP request
 * @return SOAP response message
 * @throws SOAPException in case of a SOAP issue
 * @throws IOException in case of an IO issue
 */
private final SOAPMessage execute(final String endpointUrl, final SOAPMessage message) throws Exception {
    SOAPConnection conn = null;
    try {

        /* Create new SOAP connection */
        conn = SOAPConnectionFactory.newInstance().createConnection();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, going to execute SOAP message : "
                    + message.getSOAPBody().getTextContent());
        }

        /* Call SOAP service */
        final SOAPMessage response = conn.call(message, endpointUrl);

        /* Get SOAP response body */
        final SOAPBody body = response.getSOAPBody();

        if (logger.isDebugEnabled()) {
            logger.debug("----Inside execute, has fault? :  " + body.hasFault());
        }

        if (body.hasFault() && body.getFault() != null) {

            logger.error("----Inside execute, fault :  " + body.getFault().getTextContent()
                    + ", fault reason : " + body.getFault().getFaultString());

            /* Throw error */
            throw new SOAPException(body.getFault().getTextContent());
        }
        return response;
    } catch (final Exception e) {

        logger.error("----Inside execute, error recieved :  " + e.getMessage() + ", error : " + e);

        /* Throw user error */
        throw new SOAPException(e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:ee.sk.hwcrypto.demo.controller.SigningController.java

private SOAPMessage SOAPQuery(String req) {
    try {//from  w w w . j  ava2 s  .  c o m
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        String url = "http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl";

        MessageFactory messageFactory = MessageFactory.newInstance();
        InputStream is = new ByteArrayInputStream(req.getBytes());
        SOAPMessage soapMessage = messageFactory.createMessage(null, is);
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "https://www.openxades.org:8443/DigiDocService/";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("", url);
        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", "");
        soapMessage.saveChanges();

        SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);

        return soapResponse;
    } catch (Exception e) {
        log.error("SOAP Exception " + e);
    }
    return null;
}

From source file:com.maxl.java.aips2sqlite.AllDown.java

public void downSwissindexXml(String language, String file_refdata_pharma_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {/*from   w  ww.j a  va 2 s  .co m*/
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Swissindex (" + language + ") file... ");
        else {
            pb.init("- Downloading Swissindex (" + language + ") file... ");
            pb.start();
        }

        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();

        // Setting SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101/DownloadAll");

        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("pharmacode");
        soapBodyElement1.addNamespaceDeclaration("",
                "http://swissindex.e-mediat.net/SwissindexPharma_out_V101");
        soapBodyElement1.addTextNode("DownloadAll");
        SOAPElement soapBodyElement2 = soapBody.addChildElement("lang");
        soapBodyElement2.addNamespaceDeclaration("",
                "http://swissindex.e-mediat.net/SwissindexPharma_out_V101");
        if (language.equals("DE"))
            soapBodyElement2.addTextNode("DE");
        else if (language.equals("FR"))
            soapBodyElement2.addTextNode("FR");
        else {
            System.err.println("down_swissindex_xml: wrong language!");
            return;
        }
        soapRequest.saveChanges();

        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        String wsURL = "https://swissindex.refdata.ch/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);

        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless! 
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");
        long len = writeToFile(xmlBody, file_refdata_pharma_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Swissindex (" + language + ") file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downSwissindexXml'");
        e.printStackTrace();
    }
}

From source file:cl.nic.dte.net.ConexionSii.java

@SuppressWarnings("unchecked")
private RESPUESTADocument getEstadoDTE(String rutConsultante, Documento dte, String token, String urlSolicitud)
        throws UnsupportedOperationException, SOAPException, MalformedURLException, XmlException {

    String rutEmisor = dte.getEncabezado().getEmisor().getRUTEmisor();
    String rutReceptor = dte.getEncabezado().getReceptor().getRUTRecep();
    Integer tipoDTE = dte.getEncabezado().getIdDoc().getTipoDTE().intValue();
    long folioDTE = dte.getEncabezado().getIdDoc().getFolio();
    String fechaEmision = Utilities.fechaEstadoDte
            .format(dte.getEncabezado().getIdDoc().getFchEmis().getTime());
    long montoTotal = dte.getEncabezado().getTotales().getMntTotal();

    SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection con = scFactory.createConnection();
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();
    header.detachNode();/* w w  w . j  av a 2 s . c o  m*/

    Name bodyName = envelope.createName("getEstDte", "m", urlSolicitud);
    SOAPBodyElement gltp = body.addBodyElement(bodyName);

    Name toKname = envelope.createName("RutConsultante");
    SOAPElement toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutConsultante.substring(0, rutConsultante.length() - 2));

    toKname = envelope.createName("DvConsultante");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutConsultante.substring(rutConsultante.length() - 1, rutConsultante.length()));

    toKname = envelope.createName("RutCompania");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutEmisor.substring(0, rutEmisor.length() - 2));

    toKname = envelope.createName("DvCompania");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutEmisor.substring(rutEmisor.length() - 1, rutEmisor.length()));

    toKname = envelope.createName("RutReceptor");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutReceptor.substring(0, rutReceptor.length() - 2));

    toKname = envelope.createName("DvReceptor");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(rutReceptor.substring(rutReceptor.length() - 1, rutReceptor.length()));

    toKname = envelope.createName("TipoDte");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(Integer.toString(tipoDTE));

    toKname = envelope.createName("FolioDte");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(Long.toString(folioDTE));

    toKname = envelope.createName("FechaEmisionDte");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(fechaEmision);

    toKname = envelope.createName("MontoDte");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(Long.toString(montoTotal));

    toKname = envelope.createName("Token");
    toKsymbol = gltp.addChildElement(toKname);
    toKsymbol.addTextNode(token);

    message.getMimeHeaders().addHeader("SOAPAction", "");

    URL endpoint = new URL(urlSolicitud);

    SOAPMessage responseSII = con.call(message, endpoint);

    SOAPPart sp = responseSII.getSOAPPart();
    SOAPBody b = sp.getEnvelope().getBody();

    for (Iterator<SOAPBodyElement> res = b.getChildElements(
            sp.getEnvelope().createName("getEstDteResponse", "ns1", urlSolicitud)); res.hasNext();) {
        for (Iterator<SOAPBodyElement> ret = res.next().getChildElements(
                sp.getEnvelope().createName("getEstDteReturn", "ns1", urlSolicitud)); ret.hasNext();) {

            HashMap<String, String> namespaces = new HashMap<String, String>();
            namespaces.put("", "http://www.sii.cl/XMLSchema");
            XmlOptions opts = new XmlOptions();
            opts.setLoadSubstituteNamespaces(namespaces);

            return RESPUESTADocument.Factory.parse(ret.next().getValue(), opts);
        }
    }

    return null;

}

From source file:com.maxl.java.aips2sqlite.AllDown.java

public void downRefdataPharmaXml(String file_refdata_pharma_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {//  w w w  .  j a  va  2s .  com
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Refdatabase pharma file... ");
        else {
            pb.init("- Downloading Refdatabase pharma file... ");
            pb.start();
        }

        // Create soaprequest
        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();
        // Set SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Pharma/Download");
        // Set SOAP main request part
        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadArticleInput");
        soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/");
        SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("ATYPE");
        soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Article_in");
        soapBodyElement2.addTextNode("ALL");
        soapRequest.saveChanges();
        // If needed print out soapRequest in a pretty format
        // System.out.println(prettyFormatSoapXml(soapRequest));
        // Create connection to SOAP server
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        // wsURL contains service end point
        String wsURL = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);
        // Extract response
        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless!          
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");

        long len = writeToFile(xmlBody, file_refdata_pharma_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Refdata pharma file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downRefdataPharmaXml'");
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected SOAPConnection createSOAPConnection() {
    try {/*from ww w.  j ava 2 s . co m*/
        SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = scf.createConnection();
        return soapConnection;
    } catch (UnsupportedOperationException e) {
        log.error(e);
        throw new JRRuntimeException(e);
    } catch (SOAPException e) {
        log.error(e);
        throw new JRRuntimeException(e);
    }
}

From source file:com.maxl.java.aips2sqlite.AllDown.java

public void downRefdataPartnerXml(String file_refdata_partner_xml) {
    boolean disp = false;
    ProgressBar pb = new ProgressBar();

    try {//from  w  ww. j a  va  2  s.  c  o m
        // Start timer 
        long startTime = System.currentTimeMillis();
        if (disp)
            System.out.print("- Downloading Refdata partner file... ");
        else {
            pb.init("- Downloading Refdata partner file... ");
            pb.start();
        }

        // Create soaprequest
        SOAPMessage soapRequest = MessageFactory.newInstance().createMessage();
        // Set SOAPAction header line
        MimeHeaders headers = soapRequest.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Download");
        // Set SOAP main request part
        SOAPPart soapPart = soapRequest.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody soapBody = envelope.getBody();
        // Construct SOAP request message
        SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadPartnerInput");
        soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/");
        SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("PTYPE");
        soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Partner_in");
        soapBodyElement2.addTextNode("ALL");
        soapRequest.saveChanges();
        // If needed print out soapRequest in a pretty format
        // System.out.println(prettyFormatSoapXml(soapRequest));
        // Create connection to SOAP server
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        // wsURL contains service end point
        String wsURL = "http://refdatabase.refdata.ch/Service/Partner.asmx?WSDL";
        SOAPMessage soapResponse = connection.call(soapRequest, wsURL);
        // Extract response
        Document doc = soapResponse.getSOAPBody().extractContentAsDocument();
        String strBody = getStringFromDoc(doc);
        String xmlBody = prettyFormat(strBody);
        // Note: parsing the Document tree and using the removeAttribute function is hopeless!          
        xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", "");

        long len = writeToFile(xmlBody, file_refdata_partner_xml);

        if (!disp)
            pb.stopp();
        long stopTime = System.currentTimeMillis();
        System.out.println("\r- Downloading Refdata partner file... " + len / 1024 + " kB in "
                + (stopTime - startTime) / 1000.0f + " sec");

        connection.close();

    } catch (Exception e) {
        if (!disp)
            pb.stopp();
        System.err.println(" Exception: in 'downRefdataPartnerXml'");
        e.printStackTrace();
    }
}

From source file:it.cnr.icar.eric.common.SOAPMessenger.java

SOAPMessage send(SOAPMessage msg) throws SOAPException {

    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = scf.createConnection();

    dumpMessage("Request=", msg);

    long t1 = System.currentTimeMillis();

    // if the sessionId exists, set it as a Mime header
    // This header will be used by the server to track authenticated
    // sessions/*from w w w. j  a  va  2  s.com*/
    if (credentialInfo != null) {
        if (credentialInfo.sessionId != null) {
            msg.getMimeHeaders().addHeader("Cookie", credentialInfo.sessionId);
        }
    }

    SOAPMessage reply = connection.call(msg, endpoint);

    // if the credentialInfo.sessionId is not null, cache the sessionId
    if (credentialInfo != null) {
        cacheSessionId(reply);
    }

    long t2 = System.currentTimeMillis();

    dumpMessage("Response=", reply);

    double secs = ((double) t2 - t1) / 1000;
    log.debug("Call elapsed time in seconds: " + secs);

    return reply;
}