List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:edu.unc.lib.dl.services.TripleStoreManagerMulgaraImpl.java
private String sendTQL(String query) { log.info(query);//from w w w.j av a2s . c o m String result = null; try { // First create the connection SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnFactory.createConnection(); // 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(); SOAPMessage 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.jdom.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument()); log.info(new XMLOutputter().outputString(jdomDoc)); } } else { NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*", "executeQueryToStringReturn"); if (nl.getLength() > 0) { result = nl.item(0).getTextContent(); } log.debug(result); } } catch (SOAPException e) { throw new Error("Cannot query triple store at " + this.getItqlEndpointURL(), e); } return result; }
From source file:ee.ria.xroad.common.message.SoapParserImpl.java
protected Soap createMessage(byte[] rawXml, SoapHeader header, SOAPMessage soap, String charset, String originalContentType) throws Exception { if (header == null) { throw new CodedException(X_MISSING_HEADER, "Malformed SOAP message: header missing"); }//ww w . j a v a 2 s.c o m String serviceName = getServiceName(soap.getSOAPBody()); ServiceId service = header.getService() != null ? header.getService() : header.getCentralService(); if (service == null) { throw new CodedException(X_MISSING_HEADER_FIELD, "Message header must contain either service id" + " or central service id"); } validateServiceName(service.getServiceCode(), serviceName); return new SoapMessageImpl(rawXml, charset, header, soap, serviceName, isRpcMessage(soap), originalContentType); }
From source file:eu.domibus.ebms3.sender.EbMS3MessageBuilder.java
public SOAPMessage buildSOAPFaultMessage(Error ebMS3error) throws EbMS3Exception { SignalMessage signalMessage = new SignalMessage(); signalMessage.getError().add(ebMS3error); SOAPMessage soapMessage = this.buildSOAPMessage(signalMessage, null); try {//from w ww . j a v a 2s .co m // An ebMS signal does not require any SOAP Body: if the SOAP Body is not empty, it MUST be ignored by the MSH, as far as interpretation of the signal is concerned. //TODO: locale is static soapMessage.getSOAPBody().addFault(SOAPConstants.SOAP_RECEIVER_FAULT, "An error occurred while processing your request. Please check the message header for more details.", Locale.ENGLISH); } catch (SOAPException e) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, "An error occurred while processing your request. Please check the message header for more details.", e, MSHRole.RECEIVING); } return soapMessage; }
From source file:org.soapfromhttp.service.CallSOAP.java
/** * Contruction dynamique de la requte SOAP * * @param pBody//from w ww. ja v a 2 s .c o m * @param method * @return SOAPMessage * @throws SOAPException * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ private SOAPMessage createSOAPRequest(final String pBody, final String method) throws SOAPException, IOException, SAXException, ParserConfigurationException { // Prcise la version du protocole SOAP utiliser (ncessaire pour les appels de WS Externe) MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage soapMessage = messageFactory.createMessage(); MimeHeaders headers = soapMessage.getMimeHeaders(); // Prcise la mthode du WSDL interroger headers.addHeader("SOAPAction", method); // Encodage UTF-8 headers.addHeader("Content-Type", "text/xml;charset=UTF-8"); final SOAPBody soapBody = soapMessage.getSOAPBody(); // convert String into InputStream - traitement des caracres escaps > < ... (contraintes de l'affichage IHM) //InputStream is = new ByteArrayInputStream(HtmlUtils.htmlUnescape(pBody).getBytes()); InputStream is = new ByteArrayInputStream(pBody.getBytes()); DocumentBuilder builder = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); // Important laisser sinon KO builderFactory.setNamespaceAware(true); try { builder = builderFactory.newDocumentBuilder(); Document document = builder.parse(is); soapBody.addDocument(document); } catch (ParserConfigurationException e) { MyLogger.log(CallSOAP.class.getName(), Level.ERROR, e.toString()); } finally { is.close(); if (builder != null) { builder.reset(); } } soapMessage.saveChanges(); return soapMessage; }
From source file:edu.xtec.colex.client.beans.ColexIndexBean.java
/** * Returns a Vector containing the guest collections (Collection,Guest) * stored into SOAPMessage/*from w w w.ja va2s .c o m*/ * * @param sm the SOAPMessage * @throws javax.xml.soap.SOAPException when a SOAPException error occurs * @return the Vector */ protected Vector getListGuestCollections(SOAPMessage sm) throws SOAPException { Vector vRes = new Vector(); SOAPBody sb = sm.getSOAPBody(); Iterator it = sb.getChildElements(); Iterator it2 = null; SOAPElement se = (SOAPElement) it.next(); it = se.getChildElements(sf.createName("guestCollections")); se = (SOAPElement) it.next(); it = se.getChildElements(sf.createName("guestCollection")); while (it.hasNext()) { se = (SOAPElement) it.next(); it2 = se.getChildElements(sf.createName("collection")); Collection c = new Collection((SOAPElement) it2.next()); vRes.add(c); it2 = se.getChildElements(sf.createName("guest")); Guest g = new Guest((SOAPElement) it2.next()); vRes.add(g); } return vRes; }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
protected String createOldStyleSoapResponse(String soapVersion, String xml) throws SOAPException { try {//from www. ja va 2s . com SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); soapBody.addDocument(DomHelper.toDomDocument(xml)); return DomHelper.toXmlNoWhiteSpace(soapMessage.getSOAPPart()); } catch (Exception ex) { throw new SOAPException(ex.getMessage(), ex); } }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
/** * Allow version specific factory passed in TODO: allow specifying response * headers/*from www . j a v a2 s. c om*/ */ protected String createSoapResponse(String soapVersion, String xml) throws SOAPException { try { SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage(); SOAPBody soapBody = soapMessage.getSOAPBody(); soapBody.addDocument(DomHelper.toDomDocument(xml)); return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement()); } catch (Exception ex) { throw new SOAPException(ex.getMessage(), ex); } }
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 w w w. j a va 2s . 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:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private byte[] createRequestXml(String action, ImmutablePair<String, String>... params) { try {/*from w w w. j a v a 2 s .c o m*/ MessageFactory factory = MessageFactory.newInstance(); SOAPMessage soapMessage = factory.createMessage(); SOAPBodyElement actionElement = soapMessage.getSOAPBody().addBodyElement(new QName(null, action, "m")); actionElement.addNamespaceDeclaration("m", serviceType); for (Pair<String, String> param : params) { SOAPElement paramElement = actionElement.addChildElement(QName.valueOf(param.getKey())); paramElement.setValue(param.getValue()); } soapMessage.getSOAPPart().setXmlStandalone(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(baos)); return baos.toByteArray(); } catch (IllegalArgumentException | SOAPException | TransformerException | DOMException e) { throw new IllegalStateException(e); // should never happen } }
From source file:edu.xtec.colex.client.beans.ColexIndexBean.java
/** * Calls the web service operation <I>deleteCollection(User,Collection) : * void</I>//from ww w.ja v a 2s . c o m * * @param sCollection the String name of the Collection to delete * @throws javax.xml.soap.SOAPException when a SOAPException error occurs */ private void deleteCollection(String sCollection) throws SOAPException { User uRequest = new User(getUserId()); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "deleteCollection"); addParam(sbeRequest, uRequest); addParam(sbeRequest, new Collection(sCollection)); smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.collection")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "delete"); } else { } } catch (SOAPException se) { throw se; } }