List of usage examples for javax.xml.soap SOAPConnection call
public abstract SOAPMessage call(SOAPMessage request, Object to) throws SOAPException;
From source file:org.belio.service.gateway.SafcomGateway.java
private boolean sendMessage(QueueType queueType, Outbox outbox) { try {// w w w . j a v a 2 s . co m String now = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); MessageDigest md = MessageDigest.getInstance("MD5"); String serviceId = outbox.getServiceID(); String endpointDef = ""; // if (queueType.equals(QueueType.BULK)) { // endpointDef = networkproperties.getProperty("safcom_mt_endpoint"); // } else { endpointDef = networkproperties.getProperty("safcom_endpoint"); // } String code = outbox.getShortCode(); String spIdString = outbox.getSdpId(); String spPasswordString = createSpPass(spIdString, now, md); String recepient = "tel:" + outbox.getMsisdn(); String actualmessage = URLDecoder.decode(URLEncoder.encode(outbox.getText(), "UTF-8"), "UTF-8"); Launcher.LOG.info("T----------------------------------------J" + actualmessage); String gencorrelator = String.valueOf(outbox.getRefNo()); // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server SOAPMessage messageToSend = getSoapMessageFromString(getMessage(spIdString, spPasswordString, recepient, serviceId, now, actualmessage, code, gencorrelator, endpointDef)); Calendar start = Calendar.getInstance(); SOAPMessage soapResponse = soapConnection.call(messageToSend, networkproperties.getProperty("safcom_sms")); Launcher.LOG.info( recepient + " - took " + (Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis())); // SOAPMessage soapResponse = null; System.out.println("XXXXXXXXXXXXXXXXXXX====Sending Safaricom message"); // printSOAPResponse(soapResponse);//TODO log SOAPBody body = soapResponse.getSOAPBody(); if (body.hasFault()) { SOAPFault newFault = body.getFault(); // QName fcode = newFault.getFaultCodeAsQName(); // String string = newFault.getFaultString(); // String actor = newFault.getFaultActor(); // System.out.println(">>>>>>>>>>>>>"+fcode); System.out.println(">>>>>>>>>>>>>" + newFault.getFaultString()); soapConnection.close(); return false; } else { //TO DO log soapConnection.close(); return true; } } catch (Exception ex) { Launcher.LOG.info(ex.getMessage()); } return false; }
From source file:org.cerberus.service.soap.impl.SoapService.java
@Override public AnswerItem<SOAPExecution> callSOAP(String envelope, String servicePath, String method, String attachmentUrl) {//from w w w. j a v a 2s.c o m AnswerItem result = new AnswerItem(); SOAPExecution executionSOAP = new SOAPExecution(); ByteArrayOutputStream out = null; MessageEvent message = null; if (StringUtils.isNullOrEmpty(servicePath)) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_SERVICEPATHMISSING); result.setResultMessage(message); return result; } if (StringUtils.isNullOrEmpty(method)) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_METHODMISSING); result.setResultMessage(message); return result; } if (StringUtils.isNullOrEmpty(envelope)) { message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_ENVELOPEMISSING); result.setResultMessage(message); return result; } SOAPConnectionFactory soapConnectionFactory; SOAPConnection soapConnection = null; try { //Initialize SOAP Connection soapConnectionFactory = SOAPConnectionFactory.newInstance(); soapConnection = soapConnectionFactory.createConnection(); MyLogger.log(SoapService.class.getName(), Level.DEBUG, "Connection opened"); // Create SOAP Request MyLogger.log(SoapService.class.getName(), Level.DEBUG, "Create request"); SOAPMessage input = createSoapRequest(envelope, method); //Add attachment File if specified //TODO: this feature is not implemented yet therefore is always empty! if (!StringUtils.isNullOrEmpty(attachmentUrl)) { this.addAttachmentPart(input, attachmentUrl); } // Store the SOAP Call out = new ByteArrayOutputStream(); input.writeTo(out); MyLogger.log(SoapService.class.getName(), Level.DEBUG, "WS call : " + out.toString()); executionSOAP.setSOAPRequest(input); result.setItem(executionSOAP); // Call the WS MyLogger.log(SoapService.class.getName(), Level.DEBUG, "Calling WS"); SOAPMessage soapResponse = soapConnection.call(input, servicePath); MyLogger.log(SoapService.class.getName(), Level.DEBUG, "Called WS"); out = new ByteArrayOutputStream(); // Store the response soapResponse.writeTo(out); MyLogger.log(SoapService.class.getName(), Level.DEBUG, "WS response received"); MyLogger.log(SoapService.class.getName(), Level.DEBUG, "WS response : " + out.toString()); executionSOAP.setSOAPResponse(soapResponse); message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSOAP); message.setDescription( message.getDescription().replace("%SERVICEPATH%", servicePath).replace("%SOAPMETHOD%", method)); result.setItem(executionSOAP); } catch (SOAPException | UnsupportedOperationException | IOException | SAXException | ParserConfigurationException | CerberusException e) { MyLogger.log(SoapService.class.getName(), Level.ERROR, e.toString()); message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP); message.setDescription(message.getDescription().replace("%SERVICEPATH%", servicePath) .replace("%SOAPMETHOD%", method).replace("%DESCRIPTION%", e.getMessage())); result.setResultMessage(message); return result; } finally { try { if (soapConnection != null) { soapConnection.close(); } if (out != null) { out.close(); } } catch (SOAPException | IOException ex) { Logger.getLogger(SoapService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } finally { result.setResultMessage(message); } } return result; }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
private void getPVForecast() { try {//from w w w . ja v a2 s .co m SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Calendar cal = new GregorianCalendar(); if (cal.get(Calendar.HOUR_OF_DAY) < 11) cal.add(Calendar.DAY_OF_MONTH, -1); String date = format.format(cal.getTime()); // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server String url = "http://ws.i-em.eu/v4/iem.asmx"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(date), url); // Process the SOAP Response double[] val = getValuesFromSOAPResponse(soapResponse); if (val != null) { if (val.length > 0) forecast = new ArrayList<Double>(); for (int i = 0; i < val.length; i++) { if (Double.isNaN(val[i])) val[i] = 0; forecast.add(val[i]); } } forecast_debug += "---fsize: " + forecast.size(); soapConnection.close(); } catch (Exception e) { forecast_debug += "---EXCEPT: " + e.getMessage(); } }
From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java
/** * @see Transport#send(org.w3c.dom.Element, java.net.URL) *//*from w w w. j a v a 2s .co m*/ public Element send(Element request, URL endpointURL) throws RegistryException { String requestMessage = XMLUtils.toString(request); log.debug("Request message:" + requestMessage); Element response = null; try { SOAPMessage message = this.createSOAPMessage(request); //Make the SAAJ Call now SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = connection.call(message, endpointURL); SOAPBody soapBody = soapResponse.getSOAPBody(); boolean hasFault = soapBody.hasFault(); if (hasFault) { SOAPFault soapFault = soapBody.getFault(); String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString(); throw new RegistryException(faultStr); } response = getFirstChildElement(soapBody); } catch (Exception ex) { log.error("Exception::", ex); throw new RegistryException(ex); } log.debug("Response message:" + XMLUtils.getText(response)); return response; }
From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java
public Element send(Element request, URL endpointURL) throws RegistryException { log.debug("Request message:" + XMLUtils.toString(request)); if ("true".equalsIgnoreCase(debugProp)) System.out.println("Request Element:" + XMLUtils.toString(request)); Element response = null;/*from w w w . ja v a 2 s. c om*/ try { MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); message.getSOAPHeader().detachNode(); SOAPPart soapPart = message.getSOAPPart(); SOAPBody soapBody = soapPart.getEnvelope().getBody(); soapBody.addChildElement(getSOAPElement(soapBody, request)); //There seems to be a bug in the Saaj/Axis implementation that requires //message to be written to an output stream ByteArrayOutputStream by = new ByteArrayOutputStream(); message.writeTo(by); //Does not do anything by.close(); if ("true".equalsIgnoreCase(debugProp)) message.writeTo(System.out); //Make the SAAJ Call now SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = connection.call(message, endpointURL); if ("true".equalsIgnoreCase(debugProp)) { System.out.println("Response is:"); soapResponse.writeTo(System.out); } soapBody = soapResponse.getSOAPBody(); boolean hasFault = soapBody.hasFault(); if (hasFault) { SOAPFault soapFault = soapBody.getFault(); String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString(); throw new RegistryException(faultStr); } response = getFirstChildElement(soapBody); } catch (Exception ex) { ex.printStackTrace(); log.error(ex); throw new RegistryException(ex); } log.debug("Response message:" + XMLUtils.getText(response)); return response; }
From source file:org.libreplan.importers.TimSoapClient.java
/** * Sends the SOAP message request to the SOAP server * * @param url// ww w .j av a 2 s. co m * the endpoint of the web service * @param message * the SOAP message to be send * @return the response, SOAP message * @throws SOAPException * if unable to send request */ private static SOAPMessage sendRequest(String url, SOAPMessage message) throws SOAPException { SOAPConnection connection = null; SOAPMessage response = null; try { connection = createConnection(); response = connection.call(message, url); } finally { if (connection != null) { closeConnection(connection); } } return response; }
From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java
public static void getPalDetails(@NotNull String url, @NotNull String username, @NotNull String password, @NotNull String appId, String signature) throws Exception { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server SOAPMessage soapResponse;//w w w. j a v a2s.c o m try { soapResponse = soapConnection.call(createGetPalDetailsSOAPRequest(username, password, appId, signature), url); } catch (Exception e) { throw new org.mule.api.ConnectionException(ConnectionExceptionCode.UNKNOWN_HOST, "", "PayPal SOAP Endpoint not reachable.", e); } if (soapResponse.getSOAPBody().hasFault()) { Exception e = processException(soapResponse); throw e; } NodeList palList = soapResponse.getSOAPBody().getElementsByTagName("Pal"); if (palList == null || (palList != null && palList.getLength() == 0)) { Exception e = processException(soapResponse); throw e; } String pal = soapResponse.getSOAPBody().getElementsByTagName("Pal").item(0).getTextContent(); if (StringUtils.isEmpty(pal)) { Exception e = processException(soapResponse); throw e; } soapConnection.close(); }
From source file:org.openhie.test.xds.util.SoapMessageSender.java
public static void main(String args[]) throws Exception { SoapMessageSender test = new SoapMessageSender(); // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server String url = "http://iol.test.ohie.org:5001/xdsrepository"; SOAPMessage so = test.getSoapMessageFromString(); SOAPHeader header = so.getSOAPHeader(); log.info(soapConnection.call(test.getSoapMessageFromString(), url)); // print SOAP Response System.out.print("Response SOAP Message:"); //soapResponse.writeTo(System.out); soapConnection.close();/*from w w w. j a v a 2 s .co m*/ }
From source file:org.overlord.rtgov.tests.platforms.jbossas.activityserver.JBossASActivityServerServiceTest.java
@Test @OperateOnDeployment("orders-app") public void testQueryActivityServer() { try {/*from w w w .j av a 2 s.c om*/ SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance(); SOAPConnection con = factory.createConnection(); java.net.URL url = new java.net.URL(ORDER_SERVICE_URL); String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <soap:Body>" + " <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">" + " <order>" + " <orderId>1</orderId>" + " <itemId>BUTTER</itemId>" + " <quantity>100</quantity>" + " <customer>Fred</customer>" + " </order>" + " </orders:submitOrder>" + " </soap:Body>" + "</soap:Envelope>"; long startTime = System.currentTimeMillis(); java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes()); SOAPMessage request = MessageFactory.newInstance().createMessage(null, is); is.close(); SOAPMessage response = con.call(request, url); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); response.writeTo(baos); baos.close(); // Wait for events to propagate Thread.sleep(4000); java.util.List<ActivityType> acts = getActivityEvents(startTime, System.currentTimeMillis()); if (acts == null) { fail("Activity event list is null"); } System.out.println("LIST SIZE=" + acts.size()); System.out.println("LIST=" + acts); if (acts.size() != 12) { fail("Expecting 12 activity events: " + acts.size()); } // RTGOV-256 Check that first activity type has header value extracted as a property ActivityType at = acts.get(0); if (!at.getProperties().containsKey("contentType")) { fail("Property 'contentType' not found"); } if (!at.getProperties().get("contentType") .equals("{urn:switchyard-quickstart-demo:orders:1.0}submitOrder")) { fail("Incorrect content type, expecting '{urn:switchyard-quickstart-demo:orders:1.0}submitOrder' but got: " + at.getProperties().get("contentType")); } if (!at.getProperties().containsKey("gateway")) { fail("Property 'gateway' not found"); } if (!at.getProperties().get("gateway").equals("soap")) { fail("Incorrect gateway, expecting 'soap' but got: " + at.getProperties().get("gateway")); } } catch (Exception e) { e.printStackTrace(); fail("Failed to invoke service: " + e); } }
From source file:org.overlord.rtgov.tests.platforms.jbossas.activityserver.JBossASActivityServerServiceTest.java
@Test @OperateOnDeployment("orders-app") public void testQueryActivityServerFaultResponse() { try {/* w w w .jav a 2 s . co m*/ SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance(); SOAPConnection con = factory.createConnection(); long startTime = System.currentTimeMillis(); java.net.URL url = new java.net.URL(ORDER_SERVICE_URL); String mesg = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <soap:Body>" + " <orders:submitOrder xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">" + " <order>" + " <orderId>1</orderId>" + " <itemId>Laptop</itemId>" + " <quantity>100</quantity>" + " <customer>Fred</customer>" + " </order>" + " </orders:submitOrder>" + " </soap:Body>" + "</soap:Envelope>"; java.io.InputStream is = new java.io.ByteArrayInputStream(mesg.getBytes()); SOAPMessage request = MessageFactory.newInstance().createMessage(null, is); is.close(); SOAPMessage response = con.call(request, url); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); response.writeTo(baos); baos.close(); // Wait for events to propagate Thread.sleep(4000); java.util.List<ActivityType> acts = getActivityEvents(startTime, System.currentTimeMillis()); if (acts == null) { fail("Activity event list is null"); } System.out.println("LIST SIZE=" + acts.size()); System.out.println("LIST=" + acts); if (acts.size() != 7) { fail("Expecting 7 activity events: " + acts.size()); } ActivityType at1 = acts.get(4); if ((at1 instanceof ResponseSent) == false) { fail("Expecting a 'response sent' event"); } ResponseSent resp = (ResponseSent) at1; if (resp.getMessageType() == null) { fail("Message type should not be null"); } if (resp.getFault() == null) { fail("Fault should not be null"); } if (!resp.getFault().equals("ItemNotFound")) { fail("Fault should be 'ItemNotFound': " + resp.getFault()); } } catch (Exception e) { e.printStackTrace(); fail("Failed to invoke service: " + e); } }