private void validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) { if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); Detail d = fault.getDetail(); try { validateFaultDetail(d, schema, bop); } catch (Exception e) { throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver()); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } }
public void handleMessage(SoapMessage message) throws Fault { MessageContentsList list = (MessageContentsList)message.getContent(List.class); Object o = list.remove(0); SOAPMessage soapMessage = null; soapMessage = (SOAPMessage)o; if (soapMessage.countAttachments() > 0) { message.put("write.attachments", Boolean.TRUE); SOAPPart part = soapMessage.getSOAPPart(); if (o instanceof Source) { StaxUtils.copy((Source)o, new SAAJStreamWriter(part)); message.getVersion().getSender()); BindingOperationInfo bop = message.getExchange().getBindingOperationInfo(); DocumentFragment frag = soapMessage.getSOAPPart().createDocumentFragment(); try { message.getExchange().put(BindingOperationInfo.class, bop);
if (soapVersion != null && soapVersion.getVersion() != 1.1) { if (f instanceof SoapFault) { for (Iterator<QName> it = CastUtils.cast(sf.getFault().getFaultSubcodes()); it.hasNext();) { throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC", BUNDLE), e); } catch (IllegalAccessException | IllegalArgumentException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e); Service service = message.getExchange().getService(); message.getExchange().getBus()); writer.setSchema(schema); OperationInfo op = message.getExchange().getBindingOperationInfo().getOperationInfo(); QName faultName = getFaultName(fault, cause.getClass(), op); MessagePartInfo part = getFaultMessagePart(faultName, op); } else { writer.write(faultInfo, part, new W3CDOMStreamWriter(f.getOrCreateDetail())); if (!f.getDetail().hasChildNodes()) { f.setDetail(null);
org.apache.cxf.binding.soap.SoapMessage cxfSoapMessage = (org.apache.cxf.binding.soap.SoapMessage)message; String cxfNamespace = cxfSoapMessage.getVersion().getNamespace(); SOAPHeader soapHeader = soapMessage.getSOAPHeader(); String namespace = soapHeader == null ? null : soapHeader.getNamespaceURI(); if (namespace != null && cxfNamespace != null && !namespace.equals(cxfNamespace) && Soap12.SOAP_NAMESPACE.equals(namespace)) { cxfSoapMessage.setVersion(Soap12.getInstance()); cxfSoapMessage.put(Message.CONTENT_TYPE, cxfSoapMessage.getVersion().getContentType());
HeadersProcessor(SoapVersion version) { this.header = version.getHeader().getLocalPart(); this.ns = version.getEnvelope().getNamespaceURI(); this.envelope = version.getEnvelope().getLocalPart(); this.body = version.getBody().getLocalPart(); }
public void writeAttribute(String uri, String local, String value) throws XMLStreamException { if (soapVersion.getNamespace().equals(uri) && (local.equals(soapVersion.getAttrNameMustUnderstand()) || local.equals(soapVersion.getAttrNameRole()))) { return; } super.writeAttribute(uri, local, value); }
xmlReader = StaxUtils.createXMLStreamReader(in); closeNeeded = true; throw new SoapFault(new Message("INVALID_11_VERSION", LOG), version.getVersionMismatch()); .getBody()); QName header = soapVersion.getHeader(); List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, header.getNamespaceURI(), header.getLocalPart()); for (Element elem : elemList) { Element hel = DOMUtils.getFirstElement(elem); SoapHeader shead = new SoapHeader(new QName(hel.getNamespaceURI(), hel.getLocalName()), obj, dataBinding); String mu = hel.getAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand()); String act = hel.getAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole()); throw new SoapFault(new Message("XML_STREAM_EXC", LOG, e.getMessage()), e, message.getVersion().getSender()); } finally { if (closeNeeded) { message.getVersion().getSender());
SoapVersion soapVersion = ((SoapMessage)message).getVersion(); if (element != null) { Element bodyElement = (Element)element.getElementsByTagNameNS( element.getNamespaceURI(), soapVersion.getBody() .getLocalPart()).item(0); if (bodyElement != null) { element = (Element)bodyElement.getFirstChild(); QName opeName = new QName(element.getNamespaceURI(), element.getLocalName()); SoapBindingInfo binding = (SoapBindingInfo)soapBindingServer.getEndpoint().getEndpointInfo() .getBinding(); if (op.getName().getLocalPart().equals(opeName.getLocalPart())) { return new QName(getPojoService().getNamespaceURI(), opeName.getLocalPart());
public void handleMessage(SoapMessage message) { if (message.getContent(Exception.class) != null) { return; SoapVersion soapVersion = message.getVersion(); if (useSOAPEnvelope) { Element soapEnv = DomUtil.createElement(document, new QName( soapVersion.getEnvelope().getNamespaceURI(), soapVersion .getEnvelope().getLocalPart(), "soap")); Element soapBody = DomUtil.createElement(soapEnv, new QName( soapVersion.getBody().getNamespaceURI(), soapVersion .getBody().getLocalPart(), "soap")); setExtraPrefix(message, soapEnv); soapEnv.appendChild(soapBody); Element body = getBodyElement(message); soapBody.appendChild(soapBody.getOwnerDocument().importNode(body, true)); message.setContent(Source.class, new DOMSource(document)); } else { try {
private void addPartialResponseHeader(SoapMessage message) { try { // add piggybacked wsa:From header to partial response List<Header> header = message.getHeaders(); Document doc = DOMUtils.getEmptyDocument(); SoapVersion ver = message.getVersion(); Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(), ver.getHeader().getLocalPart()); hdr.setPrefix(ver.getHeader().getPrefix()); marshallFrom("urn:piggyback_responder", hdr, getMarshaller()); Element elem = DOMUtils.getFirstElement(hdr); while (elem != null) { Header holder = new Header( new QName(elem.getNamespaceURI(), elem.getLocalName()), elem, null); header.add(holder); elem = DOMUtils.getNextElement(elem); } } catch (Exception e) { verificationCache.put("SOAP header addition failed: " + e); e.printStackTrace(); } }
Element soapEnv = DomUtil.createElement(document, new QName( soapVersion.getEnvelope().getNamespaceURI(), soapVersion .getEnvelope().getLocalPart(), "soap")); Element soapBody = DomUtil.createElement(soapEnv, new QName( soapVersion.getBody().getNamespaceURI(), soapVersion .getBody().getLocalPart(), "soap")); soapEnv.appendChild(soapBody); Element faultBody = DomUtil.createElement(soapBody, new QName( soapVersion.getEnvelope().getNamespaceURI(), "Fault", "soap")); faultCode.setTextContent("soap:Client"); soapVersion.getBody().getNamespaceURI(), "Detail", "soap")); soapVersion.getBody().getNamespaceURI(), "detail")); soapVersion.getEnvelope().getNamespaceURI(), "Fault", "soap")); Element faultCode = DomUtil.createElement(faultBody, soapVersion.getBody().getNamespaceURI(), "Detail", "soap")); } else {
Bus b = message.getExchange() == null ? null : message.getExchange().getBus(); HeaderProcessor p = null; if (b != null && b.getExtension(HeaderManager.class) != null) { p = b.getExtension(HeaderManager.class).getHeaderProcessor(elem.getNamespaceURI()); obj = p.getDataBinding().createReader(Node.class).read(elem); SoapHeader shead = new SoapHeader(new QName(elem.getNamespaceURI(), elem.getLocalName()), obj, dataBinding); shead.setDirection(SoapHeader.Direction.DIRECTION_IN); String mu = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameMustUnderstand()); String act = elem.getAttributeNS(message.getVersion().getNamespace(), message.getVersion().getAttrNameRole()); Header oldHdr = message.getHeader( new QName(elem.getNamespaceURI(), elem.getLocalName())); if (oldHdr != null) { message.getHeaders().remove(oldHdr);
private void writeSoapEnvelopeStart(final SoapMessage message) { final SoapVersion soapVersion = message.getVersion(); try { XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class); String soapPrefix = xtw.getPrefix(soapVersion.getNamespace()); if (StringUtils.isEmpty(soapPrefix)) { soapPrefix = "soap"; if (soapVersion.getNamespace().equals(entry.getValue())) { soapPrefix = entry.getKey(); xtw.setPrefix(soapPrefix, soapVersion.getNamespace()); xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace()); xtw.writeNamespace(soapPrefix, soapVersion.getNamespace()); for (Map.Entry<String, String> entry : nsMap.entrySet()) { if (!soapVersion.getNamespace().equals(entry.getValue())) { xtw.writeNamespace(entry.getKey(), entry.getValue()); xtw.setPrefix(soapPrefix, soapVersion.getNamespace()); xtw.writeStartElement(soapPrefix, soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace()); String s2 = xtw.getPrefix(soapVersion.getNamespace()); if (StringUtils.isEmpty(s2) || soapPrefix.equals(s2)) { xtw.writeNamespace(soapPrefix, soapVersion.getNamespace()); } else { soapPrefix = s2;
public Element getHeader(SoapVersion soapversion) { Document doc = DOMUtils.getEmptyDocument(); return doc.createElementNS(soapversion.getHeader().getNamespaceURI(), soapversion.getHeader().getLocalPart()); } };
.getContent(XMLStreamWriter.class); SoapVersion soapVersion = message.getVersion(); if (element != null) { bodyElement = (Element) element.getElementsByTagNameNS( element.getNamespaceURI(), soapVersion.getBody().getLocalPart()).item(0); StaxUtils.writeElement(DomUtil.getFirstChildElement(bodyElement), xmlWriter, true); } else { StaxUtils.writeElement(element, xmlWriter, true); .getNamespaceURI()) || !JbiConstants.WSDL11_WRAPPER_MESSAGE_LOCALNAME .equals(element.getLocalName())) { + JbiConstants.WSDL11_WRAPPER_NAMESPACE + "}message'")); BindingOperationInfo bop = message.getExchange().get( BindingOperationInfo.class); if (bop == null) { for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); StaxUtils.writeNode(n, xmlWriter, true);
String soapNamespace = message.getVersion().getNamespace(); if (detail == null) { Document doc = DOMUtils.getEmptyDocument(); Element stackTrace = doc.createElementNS( Fault.STACKTRACE_NAMESPACE, Fault.STACKTRACE); stackTrace.setTextContent(sb.toString()); detail = doc.createElementNS( soapNamespace, "detail"); fault.setDetail(detail); detail.appendChild(stackTrace); } else { Element stackTrace = detail.getOwnerDocument().createElementNS(Fault.STACKTRACE_NAMESPACE, Fault.STACKTRACE); stackTrace.setTextContent(sb.toString());
FragmentDialectConstants.FRAGMENT_2011_03_IRI.equals(node.getNamespaceURI()) && FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME.equals(node.getLocalName())) { String attrName = ((Element)node).getAttributeNS( FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR); String attrValue = node.getTextContent(); if (attrName == null) { throw new SoapFault("wsf:AttributeNode@name is not present.", getSoapVersion().getSender()); if (((Element) parent).hasAttribute(attrName)) { throw new InvalidRepresentation(); ((Element) parent).setAttribute(attrName, attrValue); } else {
private void readHeaders(XMLStreamReader xmlReader, SoapMessage message) throws XMLStreamException { SoapVersion version = message.getVersion(); XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, version.getBody()); Node nd = message.getContent(Node.class); W3CDOMStreamWriter writer = message.get(W3CDOMStreamWriter.class); Document doc = null; if (writer != null) { StaxUtils.copy(filteredReader, writer); doc = writer.getDocument(); } else if (nd instanceof Document) { doc = (Document)nd; StaxUtils.readDocElements(doc, doc, filteredReader, false, false); } else { doc = StaxUtils.read(filteredReader); message.setContent(Node.class, doc); QName header = version.getHeader(); List<Element> elemList = DOMUtils.findAllElementsByTagNameNS(element, header.getNamespaceURI(), header.getLocalPart()); for (Element elem : elemList) {
if (f.getFaultCode().getNamespaceURI().equals(Fault.FAULT_CODE_CLIENT.getNamespaceURI())) { QName fc = f.getFaultCode(); if (Fault.FAULT_CODE_CLIENT.equals(fc)) { fc = v.getSender(); } else if (Fault.FAULT_CODE_SERVER.equals(fc)) { fc = v.getReceiver(); if (Fault.FAULT_CODE_CLIENT.equals(fc)) { fc = v.getSender(); } else if (Fault.FAULT_CODE_SERVER.equals(fc)) { fc = v.getReceiver(); SoapFault soapFault = new SoapFault(new Message(f.getMessage(), (ResourceBundle)null), f.getCause(), fc);
private static void updateSoap12FaultCodes(SoapFault f) { //per Soap 1.2 spec, the fault code MUST be one of the 5 values specified in the spec. //Soap 1.1 allows the soap fault code to be arbitrary (recommends the 4 values in the spec, but //explicitely mentions that it can be extended to include additional codes). Soap 1.2 however //requires the use of one of the 5 defined codes. Additional detail or more specific information //can be transferred via the SubCodes. QName fc = f.getFaultCode(); SoapVersion v = Soap12.getInstance(); if (fc.getNamespaceURI().equals(Soap12.SOAP_NAMESPACE) && (fc.equals(v.getReceiver()) || fc.equals(v.getSender()) || fc.equals(v.getMustUnderstand()) || fc.equals(v.getDateEncodingUnknown()) || fc.equals(v.getVersionMismatch()))) { //valid fault codes, don't change anything return; } f.setFaultCode(Soap12.getInstance().getReceiver()); if (f.getSubCodes() == null) { f.setRootSubCode(fc); } else if (!f.getSubCodes().contains(fc)) { f.getSubCodes().add(fc); } } public static SoapFault createFault(Fault f, SoapVersion v) {