List of usage examples for javax.xml.soap SOAPMessage getSOAPPart
public abstract SOAPPart getSOAPPart();
From source file:eu.domibus.ebms3.receiver.MSHWebservice.java
@Override @Transactional/*from w ww . jav a 2s. co m*/ public SOAPMessage invoke(final SOAPMessage request) { SOAPMessage responseMessage = null; String pmodeKey = null; try { //FIXME: use a consistent way of property exchange between JAXWS and CXF message model. This: PropertyExchangeInterceptor pmodeKey = (String) request.getProperty(MSHDispatcher.PMODE_KEY_CONTEXT_PROPERTY); } catch (SOAPException e) { //this error should never occur because pmode handling is done inside the in-interceptorchain LOG.error("Cannot find PModeKey property for incoming Message"); assert false; } LegConfiguration legConfiguration = pModeProvider.getLegConfiguration(pmodeKey); String messageId = ""; try (StringWriter sw = new StringWriter()) { if (MSHWebservice.LOG.isDebugEnabled()) { this.transformerFactory.newTransformer().transform(new DOMSource(request.getSOAPPart()), new StreamResult(sw)); MSHWebservice.LOG.debug(sw.toString()); MSHWebservice.LOG.debug("received attachments:"); Iterator i = request.getAttachments(); while (i.hasNext()) { MSHWebservice.LOG.debug(i.next()); } } Messaging messaging = this.getMessaging(request); checkCharset(messaging); boolean messageExists = legConfiguration.getReceptionAwareness().getDuplicateDetection() && this.checkDuplicate(messaging); if (!messageExists && !(eu.domibus.common.configuration.model.Service.PING_SERVICE .equals(legConfiguration.getService().getValue()) && Action.PING_ACTION.equals(legConfiguration.getAction().getValue()))) { // ping messages are not stored/delivered messageId = this.persistReceivedMessage(request, legConfiguration, pmodeKey, messaging); } responseMessage = this.generateReceipt(request, legConfiguration, messageExists); if (!messageExists) { this.notifyBackends(messageId, legConfiguration); } } catch (TransformerException | SOAPException | JAXBException | IOException e) { throw new RuntimeException(e); } catch (EbMS3Exception e) { throw new WebServiceException(e); } return responseMessage; }
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 ww w .ja va 2 s . c o 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 downRefdataPartnerXml(String file_refdata_partner_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {/*from w w w .j a v a 2 s. co 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: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 av a 2 s. c o 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.centurylink.mdw.hub.servlet.SoapServlet.java
/** * Allow version specific factory passed in to support SOAP 1.1 and 1.2 * <b>Important</b> Faults are treated differently for 1.1 and 1.2 For 1.2 * you can't use the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html * * @param factory/*from ww w . j av a2 s.c o m*/ * @param code * @param message * @return Xml fault string * @throws SOAPException * @throws TransformerException */ protected String createSoapFaultResponse(String soapVersion, String code, String message) throws SOAPException, TransformerException { SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); /** * Faults are treated differently for 1.1 and 1.2 For 1.2 you can't use * the elementName otherwise it throws an exception * * @see http://docs.oracle.com/cd/E19159-01/819-3669/bnbip/index.html */ SOAPFault fault = null; if (soapVersion.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) { // existing 1.1 functionality fault = soapBody.addFault(soapMessage.getSOAPHeader().getElementName(), message); if (code != null) fault.setFaultCode(code); } else if (soapVersion.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) { /** * For 1.2 there are only a set number of allowed codes, so we can't * just use any one like what we did in 1.1. The recommended one to * use is SOAPConstants.SOAP_RECEIVER_FAULT */ fault = soapBody.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, code == null ? message : code + " : " + message); } return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement()); }
From source file:edu.unc.lib.dl.util.TripleStoreQueryServiceMulgaraImpl.java
private String sendTQL(String query) { log.debug(query);/*from w w w. j a va 2 s .co 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:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
public Object buildOutputData(Context context, Object convertigoResponse) throws Exception { Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response..."); SOAPMessage responseMessage = null; String sResponseMessage = ""; String encodingCharSet = "UTF-8"; if (context.requestedObject != null) encodingCharSet = context.requestedObject.getEncodingCharSet(); if (convertigoResponse instanceof Document) { Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document."); Document document = Engine.theApp.schemaManager.makeResponse((Document) convertigoResponse); //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); MessageFactory messageFactory = MessageFactory.newInstance(); responseMessage = messageFactory.createMessage(); responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet); SOAPPart sp = responseMessage.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPBody sb = se.getBody(); sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); //se.addNamespaceDeclaration(prefix, targetNameSpace); se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"); se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); // Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail se.getHeader().detachNode();/* w w w. ja va 2 s . com*/ addSoapElement(context, se, sb, document.getDocumentElement()); sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet); // Correct missing "xmlns" (Bug AXA POC client .NET) //sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\""); } else { Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document."); sResponseMessage = convertigoResponse.toString(); } if (Engine.logBeans.isDebugEnabled()) { Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage); } return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage; }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
public Object __buildOutputData(Context context, Object convertigoResponse) throws Exception { Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response..."); SOAPMessage responseMessage = null; String sResponseMessage = ""; String encodingCharSet = "UTF-8"; if (context.requestedObject != null) encodingCharSet = context.requestedObject.getEncodingCharSet(); if (convertigoResponse instanceof Document) { Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document."); Document document = (Document) convertigoResponse; //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); MessageFactory messageFactory = MessageFactory.newInstance(); responseMessage = messageFactory.createMessage(); responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet); SOAPPart sp = responseMessage.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPBody sb = se.getBody(); sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); String targetNamespace = context.project.getTargetNamespace(); String prefix = getPrefix(context.projectName, targetNamespace); //se.addNamespaceDeclaration(prefix, targetNameSpace); se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/"); se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); // Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail se.getHeader().detachNode();//from w w w . j a v a 2s. c om // Add the method response element SOAPElement soapMethodResponseElement = null; String soapElementName = context.sequenceName != null ? context.sequenceName : context.connectorName + "__" + context.transactionName; soapElementName += "Response"; soapMethodResponseElement = sb.addChildElement(se.createName(soapElementName, prefix, targetNamespace)); if (XsdForm.qualified == context.project.getSchemaElementForm()) { soapMethodResponseElement.addAttribute(se.createName("xmlns"), targetNamespace); } // Add a 'response' root child element or not SOAPElement soapResponseElement; if (context.sequenceName != null) { Sequence sequence = (Sequence) context.requestedObject; if (sequence.isIncludeResponseElement()) { soapResponseElement = soapMethodResponseElement.addChildElement("response"); } else { soapResponseElement = soapMethodResponseElement; } } else { soapResponseElement = soapMethodResponseElement.addChildElement("response"); } if (soapResponseElement.getLocalName().equals("response")) { if (document.getDocumentElement().hasAttributes()) { addAttributes(responseMessage, se, context, document.getDocumentElement().getAttributes(), soapResponseElement); } } NodeList childNodes = document.getDocumentElement().getChildNodes(); int len = childNodes.getLength(); org.w3c.dom.Node node; for (int i = 0; i < len; i++) { node = childNodes.item(i); if (node instanceof Element) { addElement(responseMessage, se, context, (Element) node, soapResponseElement); } } sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet); // Correct missing "xmlns" (Bug AXA POC client .NET) //sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\""); } else { Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document."); sResponseMessage = convertigoResponse.toString(); } if (Engine.logBeans.isDebugEnabled()) { Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage); } return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage; }