List of usage examples for javax.xml.soap SOAPConnectionFactory createConnection
public abstract SOAPConnection createConnection() throws SOAPException;
From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java
protected SOAPConnection createSOAPConnection() { try {/*from w ww . j a va2s. c om*/ SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); return scf.createConnection(); } catch (UnsupportedOperationException e) { throw new JRRuntimeException(e); } catch (SOAPException e) { throw new JRRuntimeException(e); } }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java
protected SOAPConnection createSOAPConnection() { try {/*from w w w.j a v a 2 s. c o 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.betfair.testing.utils.cougar.helpers.CougarHelpers.java
public HttpResponseBean makeCougarSOAPCall(SOAPMessage message, String serviceName, String version, HttpCallBean httpBean) {/* w w w .j a v a2s. c o 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.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPharmaXml(String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {/*from www.ja v a2s . c om*/ // 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.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPartnerXml(String file_refdata_partner_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {// w w w . j a v a 2 s .c om // 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: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 w w.j a va 2 s.com*/ // 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:edu.unc.lib.dl.util.TripleStoreQueryServiceMulgaraImpl.java
private String sendTQL(String query) { log.debug(query);//from www . j a va2 s. c o m String result = null; SOAPMessage reply = null; SOAPConnection connection = null; try { // Next, create the actual message MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); message.getMimeHeaders().setHeader("SOAPAction", "itqlbean:executeQueryToString"); SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody(); soapBody.addNamespaceDeclaration("xsd", JDOMNamespaceUtil.XSD_NS.getURI()); soapBody.addNamespaceDeclaration("xsi", JDOMNamespaceUtil.XSI_NS.getURI()); soapBody.addNamespaceDeclaration("itqlbean", this.getItqlEndpointURL()); SOAPElement eqts = soapBody.addChildElement("executeQueryToString", "itqlbean"); SOAPElement queryStr = eqts.addChildElement("queryString", "itqlbean"); queryStr.setAttributeNS(JDOMNamespaceUtil.XSI_NS.getURI(), "xsi:type", "xsd:string"); CDATASection queryCDATA = message.getSOAPPart().createCDATASection(query); queryStr.appendChild(queryCDATA); message.saveChanges(); // First create the connection SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance(); connection = soapConnFactory.createConnection(); reply = connection.call(message, this.getItqlEndpointURL()); if (reply.getSOAPBody().hasFault()) { reportSOAPFault(reply); if (log.isDebugEnabled()) { // log the full soap body response DOMBuilder builder = new DOMBuilder(); org.jdom2.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument()); log.debug(new XMLOutputter().outputString(jdomDoc)); } } else { NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*", "executeQueryToStringReturn"); if (nl.getLength() > 0) { result = nl.item(0).getFirstChild().getNodeValue(); } log.debug(result); } } catch (SOAPException e) { log.error("Failed to prepare or send iTQL via SOAP", e); throw new RuntimeException("Cannot query triple store at " + this.getItqlEndpointURL(), e); } finally { try { connection.close(); } catch (SOAPException e) { log.error("Failed to close SOAP connection", e); throw new RuntimeException( "Failed to close SOAP connection for triple store at " + this.getItqlEndpointURL(), e); } } return result; }
From source file:org.apache.axis2.saaj.SOAPConnectionTest.java
public void testCloseTwice() { SOAPConnectionFactory soapConnectionFactory = null; try {// www. j a v a2s .c om soapConnectionFactory = SOAPConnectionFactory.newInstance(); } catch (SOAPException e) { fail("Unexpected Exception " + e); } SOAPConnection sCon = null; try { sCon = soapConnectionFactory.createConnection(); sCon.close(); } catch (SOAPException e) { fail("Unexpected Exception " + e); } try { sCon.close(); fail("Expected Exception did not occur"); } catch (SOAPException e) { assertTrue(true); } }
From source file:org.apache.axis2.saaj.SOAPConnectionTest.java
public void testCallOnCloseConnection() { SOAPConnectionFactory soapConnectionFactory = null; try {//from w ww .j ava 2 s . c o m soapConnectionFactory = SOAPConnectionFactory.newInstance(); } catch (SOAPException e) { fail("Unexpected Exception " + e); } SOAPConnection sCon = null; try { sCon = soapConnectionFactory.createConnection(); sCon.close(); } catch (SOAPException e) { fail("Unexpected Exception " + e); } try { sCon.call(null, new Object()); fail("Expected Exception did not occur"); } catch (SOAPException e) { assertTrue(true); } }
From source file:org.apache.axis2.saaj.SOAPConnectionTest.java
public void testGet() { if (isNetworkedResourceAvailable("http://java.sun.com/index.html")) { try {// w w w . ja va 2s .c o m SOAPConnectionFactory sf = new SOAPConnectionFactoryImpl(); SOAPConnection con = sf.createConnection(); //Create a valid non webservice endpoint for invoking HTTP-GET URL urlEndpoint = new URL("http", "java.sun.com", 80, "/index.html"); //invoking HTTP-GET with a valid non webservice endpoint should throw a SOAPException SOAPMessage reply = con.get(urlEndpoint); } catch (Exception e) { assertTrue(e instanceof SOAPException); } } else { //If resource is not available online, do a mock test assertTrue(true); } }