public void writeTo(SOAPMessage saaj) throws SOAPException { try { SOAPHeader header = saaj.getSOAPHeader(); if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); infoset.writeTo(header); } catch (XMLStreamBufferException e) { throw new SOAPException(e); } }
public void appendToSOAPElement(String[] federatedCatalogIDs, SOAPElement parent) throws SAXException { if (federatedCatalogIDs == null) { return; } try { for (String federatedCatalogID : federatedCatalogIDs) { SOAPElement federatedCatalogIDsElement = parent.addChildElement(Constants.ELEMENT_FEDERATEDCS); federatedCatalogIDsElement.addTextNode(federatedCatalogID); } } catch (SOAPException e) { LOG.error(e.getMessage(), e); throw new SAXException("Error transforming to SOAP header", e); } }
SOAPBody body = originalMsg.getSOAPPart().getEnvelope().getBody(); body.removeContents(); soapFault.setFaultString(sf.getFault().getFaultString()); SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName()); soapFault.setFaultActor(sf.getFault().getFaultActor()); if (sf.getFault().hasDetail()) { Node nd = originalMsg.getSOAPPart().importNode( sf.getFault().getDetail() .getFirstChild(), true); soapFault.addDetail().appendChild(nd); if (sf.hasDetails()) { soapFault.addDetail(); Node nd = originalMsg.getSOAPPart().importNode(sf.getDetail(), true); nd = nd.getFirstChild(); while (nd != null) { soapFault.getDetail().appendChild(nd); nd = nd.getNextSibling(); soapFault.setFaultString(exception.getMessage()); SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandleFault")); e.printStackTrace();
public SOAPElement setElementQName(QName newName) throws SOAPException { String localName = this.target.getLocalName(); if (org.apache.axiom.soap.SOAPConstants.BODY_LOCAL_NAME.equals(localName) || org.apache.axiom.soap.SOAPConstants.HEADER_LOCAL_NAME.equals(localName) || org.apache.axiom.soap.SOAPConstants.SOAPENVELOPE_LOCAL_NAME .equals(localName)) { throw new SOAPException("changing this element name is not allowed"); } OMNamespace omNamespace = omTarget.getOMFactory().createOMNamespace(newName.getNamespaceURI(), newName.getPrefix()); this.omTarget.setNamespace(omNamespace); this.omTarget.setLocalName(newName.getLocalPart()); return this; }
n = ((Document)n).getDocumentElement(); if (n.getLocalName().equals(sayHi.getLocalPart())) { response.setNode(sayHiResponse); } else if (n.getLocalName().equals(greetMe.getLocalPart())) { Element el = DOMUtils.getFirstElement(n); String s = DOMUtils.getContent(el); if ("throwFault".equals(s.trim())) { try { SOAPFactory f = SOAPFactory.newInstance(); SOAPFault soapFault = f.createFault(); soapFault.setFaultString("Test Fault String ****"); Detail detail = soapFault.addDetail(); detail = soapFault.getDetail(); QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns"); DetailEntry de = detail.addDetailEntry(qName); qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns"); SOAPElement errorElement = de.addChildElement(qName); errorElement.setTextContent("errorcode"); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { e.printStackTrace();
if (isServerSideHandler()) { if (outbound) { QName qname = new QName("http://cxf.apache.org/mu", "MU"); SOAPPart soapPart = msg.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); = header.addHeaderElement(envelope.createName("MU", "ns1", qname.getNamespaceURI())); Name name = SOAPFactory.newInstance() .createName("mustUnderstand", "soap", "http://schemas.xmlsoap.org/soap/envelope/"); headerElement.addAttribute(name, "1"); } else { e.printStackTrace();
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) { try { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1"); SOAPBodyElement payload = body.addBodyElement(payloadName); SOAPElement message = payload.addChildElement("responseType"); message.addTextNode(responseMessage + " Request was " + requestMessage); return soapMessage; } catch (SOAPException e) { e.printStackTrace(); throw new RuntimeException(e); } }
private static void addHeader(String ticketId) { try { SOAPFactory sf = SOAPFactory.newInstance(); SOAPElement userIdHeaderElement = sf.createElement(new QName("http://www.stats.com/", "UserIdHeader")); SOAPElement ticketIdElement = sf.createElement(new QName(null, "TicketId")); ticketIdElement.addTextNode(ticketId); userIdHeaderElement.addChildElement(ticketIdElement); List<Header> headers = new ArrayList<Header>(); Header dummyHeader = new Header(new QName("http://www.stats.com/"), userIdHeaderElement); headers.add(dummyHeader); BindingProvider.class.cast(service).getRequestContext().put(Header.HEADER_LIST, headers); } catch (SOAPException e) { e.printStackTrace(); } }
/** * Creates a QName whose namespace URI is the one associated with the parameter, prefix, in the context of this SOAPElement. * The remaining elements of the new QName are taken directly from the parameters, localName and prefix. * @param localName a String containing the local part of the name. * @param prefix a String containing the prefix for the name. * @return a QName with the specified localName and prefix, and with a namespace that is associated with the prefix in the context of this SOAPElement. * This namespace will be the same as the one that would be returned by getNamespaceURI(String) if it were given prefix as it's parameter. * @throws SOAPException if the QName cannot be created. * @since SAAJ 1.3 */ public QName createQName(String localName, String prefix) throws SOAPException { String nsURI = getNamespaceURI(prefix); if (nsURI == null) throw new SOAPException(BundleUtils.getMessage(bundle, "CANNOT_OBTAIN_NAMESPACE_URI", prefix)); return new QName(nsURI, localName, prefix); }
public SOAPHeaderElement addHeaderElement(QName qname) throws SOAPException { if (qname == null || qname.getNamespaceURI().length() == 0 || qname.getPrefix().length() == 0) throw new SOAPException(BundleUtils.getMessage(bundle, "INVALID_SOAPHEADERELEMENT_NAME", qname)); SOAPHeaderElementImpl headerElement = new SOAPHeaderElementImpl(qname); addChildElement(headerElement); return headerElement; }
/** Add a SOAPHeaderElement as a child of this SOAPHeader instance. */ public SOAPElement addChildElement(SOAPElement child) throws SOAPException { QName qname = child.getElementQName(); if (qname == null || qname.getNamespaceURI().length() == 0) throw new SOAPException(BundleUtils.getMessage(bundle, "INVALID_SOAPHEADERELEMENT_NAME", qname)); // Check that we get a SOAPHeaderElement if ((child instanceof SOAPHeaderElement) == false) child = convertToHeaderElement(child); return super.addChildElement(child); }
public void appendFaultSubcode(QName subcode) throws SOAPException { if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI())) throw new UnsupportedOperationException(BundleUtils.getMessage(bundle, "NOT_SUPPORT_SUBCODE")); String nsURI = subcode.getNamespaceURI(); if (nsURI.length() == 0) throw new SOAPException(BundleUtils.getMessage(bundle, "SUBCODE_MUST_BE_NAMESPACE_QUALIFIED", subcode)); if (faultcode == null) findCodeElement(); // find innermost subcode element SOAPElement baseCodeElement = faultcode; for (SOAPElement subcodeElement = getChildSubcodeElement(baseCodeElement); subcodeElement != null; subcodeElement = getChildSubcodeElement(baseCodeElement)) baseCodeElement = subcodeElement; SOAPElement subcodeElement = baseCodeElement.addChildElement("Subcode", baseCodeElement.getPrefix(), baseCodeElement.getNamespaceURI()); SOAPElement valueElement = addChildValueElement(subcodeElement); setCode(valueElement, subcode); }
SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_1()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2()); throw new SOAPFaultException(soapFault); SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME); soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2()); throw new SOAPFaultException(soapFault); se.printStackTrace(System.err); throw new ProtocolException(se);
private void alterSoapEnvelope(SaajSoapMessage soapResponse) { try { SOAPMessage soapMessage = soapResponse.getSaajMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPHeader header = soapMessage.getSOAPHeader(); SOAPBody body = soapMessage.getSOAPBody(); SOAPFault fault = body.getFault(); envelope.removeNamespaceDeclaration(envelope.getPrefix()); envelope.addNamespaceDeclaration(PREFERRED_PREFIX, SOAP_ENV_NAMESPACE); envelope.setPrefix(PREFERRED_PREFIX); header.setPrefix(PREFERRED_PREFIX); body.setPrefix(PREFERRED_PREFIX); if (fault != null) { fault.setPrefix(PREFERRED_PREFIX); } } catch (SOAPException e) { e.printStackTrace(); } }
try { SOAPMessage saajMessage = saajSoapMessage.getSaajMessage(); saajMessage.getSOAPPart().getEnvelope().removeNamespaceDeclaration("SOAP-ENV"); saajMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("ims", "http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p"); saajMessage.getSOAPPart().getEnvelope().setPrefix("soapenv"); saajMessage.getSOAPHeader().setPrefix("soapenv"); saajMessage.getSOAPBody().setPrefix("soapenv"); saajMessage.saveChanges(); } catch (SOAPException e) { e.printStackTrace(); }
@Override public void handleMessage(SoapMessage message) { saajIn.handleMessage(message); SOAPMessage soapMessage = message.getContent(SOAPMessage.class); try { if (soapMessage == null) { throw new SOAPException(); } SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); validateRequestBody(body); } catch (SOAPException e) { throwFault(messageSource.getMessage("validation.error.message.invalidRequest", null, null)); } }
protected final void handleIncoming(final SOAPMessageContext context) { final SOAPMessage msg = context.getMessage(); final TraceeBackend backend = getTraceeBackend(); if (msg != null && backend.getConfiguration().shouldProcessContext(OutgoingRequest)) { try { final SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); // get soap header final SOAPHeader header = env.getHeader(); if (header != null) { parseSoapHeaderToBackend(header); } } catch (final SOAPException e) { e.printStackTrace(); traceeLogger.error( "TraceeClientHandler : Exception occurred during processing of inbound message.", e); } } }
@Override public DOMSource invoke(DOMSource request) { try { return invokeAllowingFaults(request); } catch (FaultMessage faultMessage) { try { SOAPFactory factory = SOAPFactory.newInstance(); SOAPFault soapFault = factory.createFault(); soapFault.setFaultCode(SOAP11_FAULTCODE_SERVER); // todo here is a constant until we have a mechanism to determine the correct value (client / server) soapFault.setFaultString(faultMessage.getMessage()); Detail detail = soapFault.addDetail(); serializeFaultMessage(detail, faultMessage); // fault actor? // stack trace of the outer exception (FaultMessage) is unimportant, because it is always created at one place // todo consider providing stack trace of the inner exception //Detail detail = soapFault.addDetail(); //detail.setTextContent(getStackTraceAsString(faultMessage)); throw new SOAPFaultException(soapFault); } catch (SOAPException e) { throw new RuntimeException("SOAP Exception: " + e.getMessage(), e); } } }
public SOAPBody getSOAPBody() throws SOAPException { SOAPPart soapPart = getSOAPPart(); if (soapPart != null) { SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); if (soapEnvelope != null) { SOAPBody soapBody = soapEnvelope.getBody(); return soapBody; } } throw new SOAPException(BundleUtils.getMessage(bundle, "CANNOT_OBTAIN_SOAPBODY")); }
public static SOAPFactory newInstance() throws SOAPException { try { SOAPFactory factory = $FactoryFinder.find(SOAPFactory.class, DEFAULT_SOAP_FACTORY, false); if (factory != null) { return factory; } return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); } catch (Exception ex) { throw new SOAPException("Unable to create SOAP Factory: " + ex.getMessage(), ex); } }