List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:org.apache.ws.scout.transport.SaajTransport.java
public Element send(Element request, URI endpointURL) throws TransportException { if (log.isDebugEnabled()) { String requestMessage = XMLUtils.convertNodeToXMLString(request); log.debug("Request message: %s\n%s" + endpointURL + ":" + requestMessage); }/* ww w . j ava 2 s. c o m*/ 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.toURL()); 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.getMessage(), ex); throw new TransportException(ex); } if (log.isDebugEnabled()) { String responseMessage = XMLUtils.convertNodeToXMLString(response); log.debug("Response message: %s" + responseMessage); } return response; }
From source file:org.belio.service.gateway.SafcomGateway.java
private boolean sendMessage(QueueType queueType, Outbox outbox) { try {/* w ww . ja v a2s .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.drools.jax.soap.PreCxfSoapProcessor.java
public void process(Exchange exchange) throws Exception { exchange.setPattern(ExchangePattern.InOut); BindingOperationInfo boi = (BindingOperationInfo) exchange .getProperty(BindingOperationInfo.class.toString()); if (boi != null) { LOG.info("boi.isUnwrapped" + boi.isUnwrapped()); }/*from w w w . j a v a 2 s.c o m*/ SOAPMessage soapMessage = (SOAPMessage) exchange.getIn().getBody(); exchange.getOut().setBody(soapMessage.getSOAPBody().getTextContent()); }
From source file:org.eevolution.LMX.engine.vendor.LMXFoliosDigitalesService.java
public String getXMLSealed(final String respxml) throws AdempiereException, IOException, SOAPException { String[] respuesta = null;// w w w . j av a2 s .co m MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(respxml.getBytes(Charset.forName("UTF-8")))); SOAPBody body = message.getSOAPBody(); NodeList returnList = body.getElementsByTagName("TimbrarPruebaCFDIResult"); NodeList innerRes = returnList.item(0).getChildNodes(); boolean failed = false; respuesta = new String[innerRes.getLength()]; String messageError = null; for (int i = 0; i < innerRes.getLength(); i++) { respuesta[i] = innerRes.item(i).getTextContent(); if (i < 3 && !respuesta[i].equals("")) { failed = true; messageError = respuesta[i]; //System.out.println(messageError); } } if (failed) throw new AdempiereException(messageError); respuesta[3] = StringEscapeUtils.unescapeXml(respuesta[3]); return respuesta[3]; }
From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java
/** * @see Transport#send(org.w3c.dom.Element, java.net.URL) *///from w ww .j a va 2s . c o 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 .j a 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.jbpm.bpel.integration.server.SoapHandler.java
private Operation determineOperation(SOAPMessage soapMessage) throws SOAPException { Binding binding = formatter.getBinding(); SOAPBinding soapBinding = (SOAPBinding) WsdlUtil.getExtension(binding.getExtensibilityElements(), com.ibm.wsdl.extensions.soap.SOAPConstants.Q_ELEM_SOAP_BINDING); String style = soapBinding.getStyle(); if (style == null) { // wsdlsoap:binding does not specify any style, assume 'document' style = SoapBindConstants.DOCUMENT_STYLE; }//from w ww .j ava 2s. c o m PortType portType = binding.getPortType(); SOAPElement bodyElement = SoapUtil.getElement(soapMessage.getSOAPBody()); if (style.equals(SoapBindConstants.RPC_STYLE)) { String operationName = bodyElement.getLocalName(); return portType.getOperation(operationName, null, null); } List operations = portType.getOperations(); for (int i = 0, n = operations.size(); i < n; i++) { Operation operation = (Operation) operations.get(i); Message inputMessage = operation.getInput().getMessage(); QName docLitElementName = WsdlUtil.getDocLitElementName(inputMessage); if (XmlUtil.nodeNameEquals(bodyElement, docLitElementName)) return operation; } return null; }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveAttributes_soap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch"); // remove the attributes SoapUtil.removeAttributes(element);// ww w.j av a 2 s.c o m // verify remotion with the dom & saaj apis assertFalse(element.hasAttribute("time")); assertFalse(element.hasAttributeNS("urn:example:produce", "lettuce")); assertFalse(element.hasAttributeNS("urn:example:fish", "fillet")); // namespaces should still be there // prefixed declaration assertEquals("produce", SoapUtil.getPrefix("urn:example:produce", element)); // parent prefixed declaration assertEquals("fish", SoapUtil.getPrefix("urn:example:fish", element)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveChildNodes_soap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <meal:lunch xmlns:produce='urn:example:produce'" + " xmlns:meal='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " </meal:lunch>" + " </soap:Body>" + "</soap:Envelope>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); // remove the child nodes element.removeContents();//from w w w. j a v a 2 s. c om // verify remotion assertFalse(element.getChildElements().hasNext()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testRemoveNamespaces_soap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>"; ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes()); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream); SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch"); // remove namespaces SoapUtil.removeNamespaces(element);//from www. j av a2 s . c o m // verify remotion assertFalse(element.getNamespacePrefixes().hasNext()); // attributes should still be there // qualified attributes assertEquals("0.1lb", element.getAttributeNS("urn:example:produce", "lettuce")); assertEquals("0.25lb", element.getAttributeNS("urn:example:fish", "fillet")); // local attribute assertEquals("1200", element.getAttribute("time")); }