/** Set the initial understood/not understood state of the headers in this * object */ private void initHeaderUnderstanding() { SOAPHeader soapHeader = ensureSOAPHeader(); if (soapHeader == null) { return; } Iterator allHeaders = soapHeader.examineAllHeaderElements(); while(allHeaders.hasNext()) { SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next(); if (nextHdrElem == null) { continue; } if (nextHdrElem.getMustUnderstand()) { notUnderstood(nextHdrElem.getElementQName()); } //only headers explicitly marked as understood should be //in the understoodHeaders set, so don't add anything to //that set at the beginning } }
@Override public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException { SOAPElement newHeaderElement = ElementFactory.createNamedElement( ((SOAPDocument) getOwnerDocument()).getDocument(), name.getLocalName(), name.getPrefix(), name.getURI()); if (newHeaderElement == null || !(newHeaderElement instanceof SOAPHeaderElement)) { newHeaderElement = createHeaderElement(name); } // header elements must be namespace qualified // check that URI is not empty, ensuring that the element is NS qualified. String uri = newHeaderElement.getElementQName().getNamespaceURI(); if ((uri == null) || ("").equals(uri)) { log.severe("SAAJ0131.impl.header.elems.ns.qualified"); throw new SOAPExceptionImpl("HeaderElements must be namespace qualified"); } addNode(newHeaderElement); return (SOAPHeaderElement) newHeaderElement; }
@Override public SOAPHeaderElement addHeaderElement(QName name) throws SOAPException { SOAPElement newHeaderElement = ElementFactory.createNamedElement( ((SOAPDocument) getOwnerDocument()).getDocument(), name.getLocalPart(), name.getPrefix(), name.getNamespaceURI()); if (newHeaderElement == null || !(newHeaderElement instanceof SOAPHeaderElement)) { newHeaderElement = createHeaderElement(name); } // header elements must be namespace qualified // check that URI is not empty, ensuring that the element is NS qualified. String uri = newHeaderElement.getElementQName().getNamespaceURI(); if ((uri == null) || ("").equals(uri)) { log.severe("SAAJ0131.impl.header.elems.ns.qualified"); throw new SOAPExceptionImpl("HeaderElements must be namespace qualified"); } addNode(newHeaderElement); return (SOAPHeaderElement) newHeaderElement; }
@Override protected SOAPElement convertToSoapElement(Element element) { final org.w3c.dom.Node soapNode = getSoapDocument().findIfPresent(element); if (soapNode instanceof SOAPHeaderElement) { return (SOAPElement) soapNode; } else { SOAPHeaderElement headerElement; try { headerElement = createHeaderElement(NameImpl.copyElementName(element)); } catch (SOAPException e) { throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage()); } return replaceElementWithSOAPElement( element, (ElementImpl) headerElement); } }
public ACATransmitterManifestReqDtl getObject(File file) { ACATransmitterManifestReqDtl dtl = null; try { String fileContents = FileUtils.readFileToString(file, "UTF-8"); SOAPMessage message = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(fileContents.getBytes())); Unmarshaller unmarshaller = JAXBContext.newInstance(ACATransmitterManifestReqDtl.class) .createUnmarshaller(); Iterator iterator = message.getSOAPHeader().examineAllHeaderElements(); while (iterator.hasNext()) { SOAPHeaderElement element = (SOAPHeaderElement) iterator.next(); QName name = new QName("urn:us:gov:treasury:irs:ext:aca:air:7.0", "ACATransmitterManifestReqDtl", "urn"); if (element.getElementQName().equals(name)) { dtl = (ACATransmitterManifestReqDtl) unmarshaller.unmarshal(processElement(element)); } } } catch (Exception e) { LOG.error("Error", e); } return dtl; }
private Document processElement(SOAPHeaderElement element) throws TransformerException, ParserConfigurationException, SAXException, IOException, SOAPException { NamedNodeMap attrs = element.getAttributes(); element.setPrefix(""); while (attrs.getLength() > 0) { attrs.removeNamedItem(attrs.item(0).getNodeName()); } String xmlString = ""; Iterator list = element.getChildElements(); while (list.hasNext()) { Node node = (Node) list.next(); xmlString += nodeToString(node); } xmlString = xmlString.replace(URN, URN1); xmlString = xmlString.replace(EIN, REQUIRED_EIN_TAG); xmlString = xmlString.replace("xmlns:urn1=\"urn1:us:gov:treasury:irs:ext:aca:air:7.0\"", ""); xmlString = xmlString.replace(ACA_END_TAG, URN + ":" + ACA_END_TAG); xmlString = ("<" + ACA_TAG + ">" + xmlString + "</" + ACA_END_TAG + ">"); return stringParser(xmlString); }
protected Map<String,String> addSoapMetaInfo(Map<String, String> metaInfo, SOAPMessage soapMessage) throws SOAPException { SOAPHeader soapHeader = soapMessage.getSOAPHeader(); if (soapHeader == null) { return metaInfo; } else { Map<String, String> newMetaInfo = new HashMap<String, String>(); newMetaInfo.putAll(metaInfo); Iterator<?> iter = soapHeader.examineAllHeaderElements(); while (iter.hasNext()) { SOAPHeaderElement headerElem = (SOAPHeaderElement) iter.next(); if (!Listener.AUTHENTICATED_USER_HEADER.equals(headerElem.getNodeName())) newMetaInfo.put(headerElem.getNodeName(), headerElem.getTextContent()); } return newMetaInfo; } }
/** * Adds an "Access" element to the SOAP header */ public boolean handleRequest(MessageContext msgct) { if (msgct instanceof SOAPMessageContext) { SOAPMessageContext smsgct = (SOAPMessageContext) msgct; try { SOAPMessage msg = smsgct.getMessage(); SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope(); SOAPHeader header = msg.getSOAPHeader(); if (header == null) header = envelope.addHeader(); // add an header if non exists SOAPHeaderElement accessElement = header.addHeaderElement(envelope.createName("Access", "ns0", JPLAG_TYPES_NS)); SOAPElement usernameelem = accessElement.addChildElement("username"); usernameelem.addTextNode(username); SOAPElement passwordelem = accessElement.addChildElement("password"); passwordelem.addTextNode(password); SOAPElement compatelem = accessElement.addChildElement("compatLevel"); compatelem.addTextNode(compatibilityLevel + ""); } catch (SOAPException x) { System.out.println("Unable to create access SOAP header!"); x.printStackTrace(); } } return true; }
private String getOperationFromSOAPHdr(SOAPHeader soapHeader) { @SuppressWarnings("unchecked") Iterator<SOAPHeaderElement> it = soapHeader.examineAllHeaderElements(); SOAPHeaderElement opHdr = null; while (it.hasNext()) { opHdr = it.next(); if ("operation".equals(opHdr.getLocalName())) { System.out.println("Found operation in SOAP header"); return opHdr.getTextContent(); } } return null; }
private SOAPHeaderElement getSecurityHeader(SOAPEnvelope envelope) throws SOAPException { if (envelope != null) { SOAPHeader header = envelope.getHeader(); if (header != null) { Iterator<?> iter = header.getChildElements(WSSE_QNAME); if (iter.hasNext()) { return (SOAPHeaderElement)iter.next(); } iter = header.getChildElements(WSSE_2_QNAME); if (iter.hasNext()) { return (SOAPHeaderElement)iter.next(); } iter = header.getChildElements(WSSE_11_QNAME); if (iter.hasNext()) { return (SOAPHeaderElement)iter.next(); } } } return null; }
/** * Creates a new <CODE>SOAPHeaderElement</CODE> object initialized with the specified name and * adds it to this <CODE>SOAPHeader</CODE> object. * * @param name a <CODE>Name</CODE> object with the name of the new <CODE>SOAPHeaderElement</CODE> * object * @return the new <CODE>SOAPHeaderElement</CODE> object that was inserted into this * <CODE>SOAPHeader</CODE> object * @throws SOAPException if a SOAP error occurs */ public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException { if (name.getURI() == null || name.getURI().trim().length() == 0) { throw new SOAPException("SOAP1.1 and SOAP1.2 requires all HeaderElements to have " + "a namespace."); } String prefix = name.getPrefix() == null ? "" : name.getPrefix(); OMNamespace ns = new NamespaceImpl(name.getURI(), prefix); SOAPHeaderBlock headerBlock = null; if (this.element.getOMFactory() instanceof SOAP11Factory) { headerBlock = new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader, (SOAPFactory)this.element.getOMFactory()); } else { headerBlock = new SOAP12HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader, (SOAPFactory)this.element.getOMFactory()); } SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock); element.setUserData(SAAJ_NODE, this, null); soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null); soapHeaderElement.setParentElement(this); return soapHeaderElement; }
private Iterator getChildren(Iterator childIter) { Collection childElements = new ArrayList(); while (childIter.hasNext()) { org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next(); Node saajNode = toSAAJNode(domNode); if (saajNode instanceof javax.xml.soap.Text) { childElements.add(saajNode); } else if (!(saajNode instanceof SOAPHeaderElement)) { // silently replace node, as per saaj 1.2 spec SOAPHeaderElement headerEle = new SOAPHeaderElementImpl((SOAPHeaderBlock)domNode); ((NodeImpl)domNode).setUserData(SAAJ_NODE, headerEle, null); childElements.add(headerEle); } else { childElements.add(saajNode); } } return childElements.iterator(); }
@Validated @Test public void testHeaderElements() throws Exception { SOAPEnvelope envelope = getSOAPEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPHeaderElement headerEle = header.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI")); headerEle.setActor("actor-URI"); headerEle.setMustUnderstand(true); Iterator iterator = header.extractHeaderElements("actor-URI"); int cnt = 0; while (iterator.hasNext()) { cnt++; SOAPHeaderElement resultHeaderEle = (SOAPHeaderElement)iterator.next(); assertEquals(headerEle.getActor(), resultHeaderEle.getActor()); assertEquals(resultHeaderEle.getMustUnderstand(), headerEle.getMustUnderstand()); } assertTrue(cnt == 1); iterator = header.extractHeaderElements("actor-URI"); assertTrue(!iterator.hasNext()); }
@Validated @Test public void testAddSource2() throws Exception { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope(); SOAPHeader header = soapEnv.getHeader(); SOAPBody body = soapEnv.getBody(); assertTrue(header.addChildElement("ebxmlms1", "ch2", "http://test.apache.org") instanceof SOAPHeaderElement); assertTrue(header.addHeaderElement( soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null); assertTrue(header.addHeaderElement( new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null); body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org"); soapMessage.saveChanges(); SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage2.getSOAPPart(); soapPart.setContent(soapMessage.getSOAPPart().getContent()); soapMessage2.saveChanges(); assertNotNull(soapMessage2); }
@Validated @Test public void testAddSource3() throws Exception { SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope(); SOAPHeader header = soapEnv.getHeader(); SOAPBody body = soapEnv.getBody(); assertTrue(header.addChildElement("ebxmlms1", "ch2", "http://test.apache.org") instanceof SOAPHeaderElement); assertTrue(header.addHeaderElement( soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null); assertTrue(header.addHeaderElement( new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null); body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org"); soapMessage.saveChanges(); SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage2.getSOAPPart(); soapPart.setContent(soapMessage.getSOAPPart().getContent()); soapMessage2.saveChanges(); assertNotNull(soapMessage2); }
@Validated @Test public void testExamineHeaderElements() throws Exception { javax.xml.soap.SOAPMessage soapMessage = javax.xml.soap.MessageFactory.newInstance( SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(); javax.xml.soap.SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope(); javax.xml.soap.SOAPHeader header = soapEnv.getHeader(); SOAPHeaderElement soapHeaderElement = header.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI")); Iterator iterator = null; soapHeaderElement.setRole("role-URI"); iterator = header.examineHeaderElements("role1-URI"); int count = 0; while (iterator.hasNext()) { count++; iterator.next(); } assertEquals(0, count); }
private void parse() { if (!parsedMessage) { try { access(); if (headers == null) headers = new HeaderList(); SOAPHeader header = sm.getSOAPHeader(); if (header != null) { headerAttrs = header.getAttributes(); Iterator iter = header.examineAllHeaderElements(); while (iter.hasNext()) { headers.add(new SAAJHeader((SOAPHeaderElement) iter.next())); } } attachmentSet = new SAAJAttachmentSet(sm); parsedMessage = true; } catch (SOAPException e) { throw new WebServiceException(e); } } }
/** * Test method for {@link io.apiman.gateway.engine.io.SoapPayloadIO#marshall(org.w3c.dom.Document)}. */ @Test public void testMarshall_Simple() throws Exception { MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPHeaderElement cheader = header.addHeaderElement(new QName("urn:ns1", "CustomHeader")); cheader.setTextContent("CVALUE"); SoapPayloadIO io = new SoapPayloadIO(); byte[] data = io.marshall(envelope); String actual = new String(data); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header><CustomHeader xmlns=\"urn:ns1\">CVALUE</CustomHeader></SOAP-ENV:Header><SOAP-ENV:Body/></SOAP-ENV:Envelope>"; Assert.assertEquals(expected, actual); }
/** * @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain) */ @SuppressWarnings("nls") @Override public void apply(final ApiRequest request, final IPolicyContext context, final Object config, final IPolicyChain<ApiRequest> chain) { try { SOAPEnvelope soapPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (SOAPEnvelope) null); if (soapPayload != null) { SOAPHeader header = soapPayload.getHeader(); SOAPHeaderElement header1 = (SOAPHeaderElement) header.examineAllHeaderElements().next(); String prop1 = header1.getTextContent(); request.getHeaders().put("X-Property-1", prop1); header.addHeaderElement(new QName("urn:ns5", "Property5")).setTextContent("value-5"); } chain.doApply(request); } catch (Exception e) { chain.throwError(e); } }
/** * The method is invoked for normal processing of outbound messages. * * @param context * the message context. * @return An indication of whether handler processing should continue for * the current message. Return <code>true</code> to continue * processing. * * @throws Exception * Causes the JAX-WS runtime to cease fault message processing. **/ @Override public boolean handleMessage(SOAPMessageContext context) { Boolean request_p = (Boolean) context .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (request_p.booleanValue()) { try { SOAPMessage msg = context.getMessage(); SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader hdr = env.getHeader(); if (hdr == null) { hdr = env.addHeader(); } QName qname_user = new QName("http://com/auth/", "auth"); SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user); helem_user.setActor(VERSION); if (version != null && version.trim().length() != 0) { helem_user.addTextNode(version); } msg.saveChanges(); message = soapMessage2String(msg); } catch (Exception e) { e.printStackTrace(); } } return true; }
/** * The method is invoked for normal processing of outbound messages. * * @param context * the message context. * @return An indication of whether handler processing should continue for * the current message. Return <code>true</code> to continue * processing. * * @throws Exception * Causes the JAX-WS runtime to cease fault message processing. **/ @Override public boolean handleMessage(SOAPMessageContext context) { Boolean request_p = (Boolean) context .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (request_p.booleanValue()) { try { SOAPMessage msg = context.getMessage(); SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader hdr = env.getHeader(); if (hdr == null) { hdr = env.addHeader(); } QName qname_user = new QName("http://com/auth/", "auth"); SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user); helem_user.setActor(VERSION); if (version == null || version.trim().length() == 0) { helem_user.addTextNode(apiVersionInfo.getProperty(VERSION)); } else { helem_user.addTextNode(version); } msg.saveChanges(); message = soapMessage2String(msg); } catch (Exception e) { e.printStackTrace(); } } return true; }
public void writeTo(SOAPMessage saaj) throws SOAPException { SOAPHeader header = saaj.getSOAPHeader(); if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag); she = header.addHeaderElement(new QName(av.nsUri, wrapper)); she.addTextNode(problemValue); }
public void writeTo(SOAPMessage saaj) throws SOAPException { SOAPHeader header = saaj.getSOAPHeader(); if(header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); SOAPHeaderElement she = header.addHeaderElement(name); if(mustUnderstand) { she.setMustUnderstand(true); } she.addTextNode(value); }
public void writeTo(SOAPMessage saaj) throws SOAPException { SOAPHeader header = saaj.getSOAPHeader(); if(header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart())); she.addChildElement(actionLocalName); she.addTextNode(action); if (soapAction != null) { she.addChildElement(soapActionLocalName); she.addTextNode(soapAction); } }
@Override public void writeTo(SOAPMessage saaj) throws SOAPException { SOAPHeader header = saaj.getSOAPHeader(); if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); SOAPHeaderElement she = header.addHeaderElement(name); if (type != null) she.addAttribute(typeAttributeName, type); she.addTextNode(value); }
@Override public Header get(String nsUri, String localName, boolean markAsUnderstood) { SOAPHeaderElement h = find(nsUri, localName); if (h != null) { if (markAsUnderstood) { understood(nsUri, localName); } return new SAAJHeader(h); } return null; }
@Override public Iterator<Header> getHeaders(final String nsUri, final String localName, final boolean markAsUnderstood) { SOAPHeader soapHeader = ensureSOAPHeader(); if (soapHeader == null) { return null; } Iterator allHeaders = soapHeader.examineAllHeaderElements(); if (markAsUnderstood) { //mark all the matchingheaders as understood up front //make an iterator while we're doing that List<Header> headers = new ArrayList<Header>(); while (allHeaders.hasNext()) { SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next(); if (nextHdr != null && nextHdr.getNamespaceURI().equals(nsUri)) { if (localName == null || nextHdr.getLocalName().equals(localName)) { understood(nextHdr.getNamespaceURI(), nextHdr.getLocalName()); headers.add(new SAAJHeader(nextHdr)); } } } return headers.iterator(); } //if we got here markAsUnderstood is false - return a lazy iterator rather //than traverse the entire list of headers now return new HeaderReadIterator(allHeaders, nsUri, localName); }
private SOAPHeaderElement find(String nsUri, String localName) { SOAPHeader soapHeader = ensureSOAPHeader(); if (soapHeader == null) { return null; } Iterator allHeaders = soapHeader.examineAllHeaderElements(); while(allHeaders.hasNext()) { SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next(); if (nextHdrElem.getNamespaceURI().equals(nsUri) && nextHdrElem.getLocalName().equals(localName)) { return nextHdrElem; } } return null; }
private void advance() { while (soapHeaders.hasNext()) { SOAPHeaderElement nextHdr = (SOAPHeaderElement) soapHeaders.next(); if (nextHdr != null && (myNsUri == null || nextHdr.getNamespaceURI().equals(myNsUri)) && (myLocalName == null || nextHdr.getLocalName().equals(myLocalName))) { current = nextHdr; //found it return; } } //if we got here we didn't find a match current = null; }
@Override public List<Header> asList() { SOAPHeader soapHeader = ensureSOAPHeader(); if (soapHeader == null) { return Collections.emptyList(); } Iterator allHeaders = soapHeader.examineAllHeaderElements(); List<Header> headers = new ArrayList<Header>(); while (allHeaders.hasNext()) { SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next(); headers.add(new SAAJHeader(nextHdr)); } return headers; }