List of usage examples for javax.xml.soap SOAPConnection call
public abstract SOAPMessage call(SOAPMessage request, Object to) throws SOAPException;
From source file:com.polivoto.networking.SoapClient.java
public String start() throws SOAPException, IOException { String resp = "NaN"; // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server String url = "http://" + host + "/FistVotingServiceBank/services/ServAvailableVoteProcesses.ServAvailableVoteProcessesHttpSoap11Endpoint/"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); SOAPBody body = soapResponse.getSOAPBody(); java.util.Iterator updates = body.getChildElements(); // El siguiente ciclo funciona slo porque el cuerpo contiene // un elemento y ste a suvez nicamente contiene un elemento. while (updates.hasNext()) { System.out.println();//from ww w .j a va2 s . c o m // The listing and its ID SOAPElement update = (SOAPElement) updates.next(); java.util.Iterator i = update.getChildElements(); while (i.hasNext()) { SOAPElement e = (SOAPElement) i.next(); String name = e.getLocalName(); String value = e.getValue(); resp = value; // Am I getting last response? System.out.println(name + ": " + value); } } soapConnection.close(); return resp; }
From source file:SendSOAPMessage.java
/** * send a simple soap message with JAXM API. *//*from w w w .ja va2 s.com*/ public void sendMessage(String url) { try { /** * Construct a default SOAP message factory. */ MessageFactory mf = MessageFactory.newInstance(); /** * Create a SOAP message object. */ SOAPMessage soapMessage = mf.createMessage(); /** * Get SOAP part. */ SOAPPart soapPart = soapMessage.getSOAPPart(); /** * Get SOAP envelope. */ SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); /** * Get SOAP body. */ SOAPBody soapBody = soapEnvelope.getBody(); /** * Add child element with the specified name. */ SOAPElement element = soapBody.addChildElement("HelloWorld"); /** * Add text message */ element.addTextNode("Welcome to SunOne Web Services!"); soapMessage.saveChanges(); /** * Construct a default SOAP connection factory. */ SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance(); /** * Get SOAP connection. */ SOAPConnection soapConnection = connectionFactory.createConnection(); /** * Construct endpoint object. */ URLEndpoint endpoint = new URLEndpoint(url); /** * Send SOAP message. */ SOAPMessage resp = soapConnection.call(soapMessage, endpoint); /** * Print response to the std output. */ resp.writeTo(System.out); /** * close the connection */ soapConnection.close(); } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (SOAPException soape) { soape.printStackTrace(); } }
From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java
/** * Executes SOAP message//from w w w . ja v a2s. c o m * * @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:org.soapfromhttp.service.CallSOAP.java
/** * Calcule d'une proprit depuis une requte SOAP. * * @param envelope/* ww w.j av a2s. c o m*/ * @param servicePath * @param method * @thorw CerberusException * @return String */ public String calculatePropertyFromSOAPResponse(final String envelope, final String servicePath, final String method) { String result = null; ByteArrayOutputStream out = null; // Test des inputs ncessaires. if (envelope != null && servicePath != null && method != null) { SOAPConnectionFactory soapConnectionFactory; SOAPConnection soapConnection = null; try { soapConnectionFactory = SOAPConnectionFactory.newInstance(); soapConnection = soapConnectionFactory.createConnection(); MyLogger.log(CallSOAP.class.getName(), Level.INFO, "Connection opened"); // Cration de la requete SOAP MyLogger.log(CallSOAP.class.getName(), Level.INFO, "Create request"); SOAPMessage input = createSOAPRequest(envelope, method); // Appel du WS MyLogger.log(CallSOAP.class.getName(), Level.INFO, "Calling WS"); MyLogger.log(CallSOAP.class.getName(), Level.INFO, "Input :" + input); SOAPMessage soapResponse = soapConnection.call(input, servicePath); out = new ByteArrayOutputStream(); soapResponse.writeTo(out); MyLogger.log(CallSOAP.class.getName(), Level.INFO, "WS response received"); MyLogger.log(CallSOAP.class.getName(), Level.DEBUG, "WS response : " + out.toString()); result = out.toString(); } catch (SOAPException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } catch (IOException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } catch (ParserConfigurationException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } catch (SAXException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } finally { try { if (soapConnection != null) { soapConnection.close(); } if (out != null) { out.close(); } MyLogger.log(CallSOAP.class.getName(), Level.INFO, "Connection and ByteArray closed"); } catch (SOAPException ex) { Logger.getLogger(CallSOAP.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CallSOAP.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } } } return result; }
From source file:ee.sk.hwcrypto.demo.controller.SigningController.java
private SOAPMessage SOAPQuery(String req) { try {/* ww w . j av a 2 s. co 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: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// www . j a v a 2 s.c o m 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; }
From source file:cl.nic.dte.net.ConexionSii.java
@SuppressWarnings("unchecked") private String getSemilla() throws UnsupportedOperationException, SOAPException, IOException, XmlException, ConexionSiiException { 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();//from w w w. j av a2s . c o m String urlSolicitud = Utilities.netLabels.getString("URL_SOLICITUD_SEMILLA"); Name bodyName = envelope.createName("getSeed", "m", urlSolicitud); message.getMimeHeaders().addHeader("SOAPAction", ""); body.addBodyElement(bodyName); URL endpoint = new URL(urlSolicitud); SOAPMessage responseSII = con.call(message, endpoint); SOAPPart sp = responseSII.getSOAPPart(); SOAPBody b = sp.getEnvelope().getBody(); cl.sii.xmlSchema.RESPUESTADocument resp = null; for (Iterator<SOAPBodyElement> res = b.getChildElements( sp.getEnvelope().createName("getSeedResponse", "ns1", urlSolicitud)); res.hasNext();) { for (Iterator<SOAPBodyElement> ret = res.next().getChildElements( sp.getEnvelope().createName("getSeedReturn", "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); resp = RESPUESTADocument.Factory.parse(ret.next().getValue(), opts); } } if (resp != null && resp.getRESPUESTA().getRESPHDR().getESTADO() == 0) { return resp.getRESPUESTA().getRESPBODY().getSEMILLA(); } else { throw new ConexionSiiException( "No obtuvo Semilla: Codigo: " + resp.getRESPUESTA().getRESPHDR().getESTADO() + "; Glosa: " + resp.getRESPUESTA().getRESPHDR().getGLOSA()); } }
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 v a2 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:com.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPharmaXml(String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {//w ww. j a v a2s . co m // 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. ja 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(); } }