Java Code Examples for org.apache.cxf.binding.soap.SoapMessage#getHeaders()
The following examples show how to use
org.apache.cxf.binding.soap.SoapMessage#getHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderVerifier.java From cxf with Apache License 2.0 | 6 votes |
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(); } }
Example 2
Source File: MustUnderstandInterceptor.java From cxf with Apache License 2.0 | 6 votes |
public void handleMessage(SoapMessage soapMessage) throws Fault { SoapVersion soapVersion = soapMessage.getVersion(); Set<QName> notFound = new HashSet<>(); List<Header> heads = soapMessage.getHeaders(); for (Header header : heads) { if (header instanceof SoapHeader && ((SoapHeader)header).isMustUnderstand() && header.getDirection() == Header.Direction.DIRECTION_IN && !knownHeaders.contains(header.getName()) && (StringUtils.isEmpty(((SoapHeader)header).getActor()) || soapVersion.getUltimateReceiverRole() .equals(((SoapHeader)header).getActor()))) { notFound.add(header.getName()); } } if (!notFound.isEmpty()) { soapMessage.remove(UNKNOWNS); throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound), soapVersion.getMustUnderstand()); } }
Example 3
Source File: RMSoapOutInterceptor.java From cxf with Apache License 2.0 | 6 votes |
/** * Encode the SequenceFault in protocol-specific header. * * @param message the SOAP message. * @param sf the SequenceFault. */ public static void encodeFault(SoapMessage message, SequenceFault sf) { LOG.log(Level.FINE, "Encoding SequenceFault in SOAP header"); try { Message inmsg = message.getExchange().getInMessage(); RMProperties rmps = RMContextUtils.retrieveRMProperties(inmsg, false); AddressingProperties maps = RMContextUtils.retrieveMAPs(inmsg, false, false); ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()); Header header = protocol.getCodec().buildHeaderFault(sf); List<Header> headers = message.getHeaders(); headers.add(header); } catch (JAXBException je) { LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je); } }
Example 4
Source File: RMSoapOutInterceptor.java From cxf with Apache License 2.0 | 6 votes |
/** * Encode the current RM properties in protocol-specific headers. * * @param message the SOAP message. * @param rmps the current RM properties. */ public static void encode(SoapMessage message, RMProperties rmps) { if (null == rmps) { return; } LOG.log(Level.FINE, "encoding RMPs in SOAP headers"); try { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true); ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()); List<Header> headers = message.getHeaders(); int startSize = headers.size(); protocol.getCodec().buildHeaders(rmps, headers); if (startSize != headers.size() && MessageUtils.isPartialResponse(message)) { // make sure the response is returned as HTTP 200 and not 202 message.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK); } } catch (JAXBException je) { LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je); } }
Example 5
Source File: AbstractTokenInterceptor.java From cxf with Apache License 2.0 | 6 votes |
protected Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if ("Security".equals(n.getLocalPart()) && (n.getNamespaceURI().equals(WSS4JConstants.WSSE_NS) || n.getNamespaceURI().equals(WSS4JConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.getEmptyDocument(); Element el = doc.createElementNS(WSS4JConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns:wsse", WSS4JConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSS4JConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 6
Source File: HeaderVerifier.java From cxf with Apache License 2.0 | 6 votes |
private void verify(SoapMessage message, boolean outgoingPartialResponse) { try { List<String> wsaHeaders = new ArrayList<>(); List<Header> headers = message.getHeaders(); if (headers != null) { recordWSAHeaders(headers, wsaHeaders, Names.WSA_NAMESPACE_NAME); recordWSAHeaders(headers, wsaHeaders, Names200408.WSA_NAMESPACE_NAME); recordWSAHeaders(headers, wsaHeaders, MAPTestBase.CUSTOMER_NAME.getNamespaceURI()); } boolean partialResponse = isIncomingPartialResponse(message) || outgoingPartialResponse; verificationCache.put(MAPTestBase.verifyHeaders(wsaHeaders, partialResponse, isRequestLeg(message), false)); } catch (SOAPException se) { verificationCache.put("SOAP header verification failed: " + se); } }
Example 7
Source File: SamlTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 8
Source File: UsernameTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 9
Source File: SamlTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 10
Source File: UsernameTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 11
Source File: SamlTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 12
Source File: UsernameTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 13
Source File: SamlTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 14
Source File: UsernameTokenInterceptor.java From steady with Apache License 2.0 | 6 votes |
private Header findSecurityHeader(SoapMessage message, boolean create) { for (Header h : message.getHeaders()) { QName n = h.getName(); if (n.getLocalPart().equals("Security") && (n.getNamespaceURI().equals(WSConstants.WSSE_NS) || n.getNamespaceURI().equals(WSConstants.WSSE11_NS))) { return h; } } if (!create) { return null; } Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(WSConstants.WSSE_NS, "wsse:Security"); el.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS); SoapHeader sh = new SoapHeader(new QName(WSConstants.WSSE_NS, "Security"), el); sh.setMustUnderstand(true); message.getHeaders().add(sh); return sh; }
Example 15
Source File: WSAFromJavaTest.java From cxf with Apache License 2.0 | 5 votes |
public void handleMessage(SoapMessage message) throws Fault { List<Header> headers = message.getHeaders(); Header h2 = null; for (Header h : headers) { if ("RelatesTo".equals(h.getName().getLocalPart())) { h2 = h; } } headers.remove(h2); }
Example 16
Source File: SonosLinkSecurityInterceptor.java From airsonic-advanced with GNU General Public License v3.0 | 5 votes |
public static Credentials getCredentials(SoapMessage message) throws JAXBException { QName credentialQName = new QName("http://www.sonos.com/Services/1.1", "credentials"); for (Header header : message.getHeaders()) { if (credentialQName.equals(header.getName())) { return unmarshaller.unmarshal((Node) header.getObject(), Credentials.class).getValue(); } } return null; }
Example 17
Source File: PolicyBasedWSS4JInInterceptor.java From cxf with Apache License 2.0 | 5 votes |
private boolean containsSecurityHeader(SoapMessage message, String actor, boolean soap12) throws WSSecurityException { String actorLocal = WSConstants.ATTR_ACTOR; String soapNamespace = WSConstants.URI_SOAP11_ENV; if (soap12) { actorLocal = WSConstants.ATTR_ROLE; soapNamespace = WSConstants.URI_SOAP12_ENV; } // // Iterate through the security headers // for (Header h : message.getHeaders()) { QName n = h.getName(); if (WSConstants.WSSE_LN.equals(n.getLocalPart()) && (n.getNamespaceURI().equals(WSS4JConstants.WSSE_NS) || n.getNamespaceURI().equals(WSS4JConstants.OLD_WSSE_NS))) { Element elem = (Element)h.getObject(); Attr attr = elem.getAttributeNodeNS(soapNamespace, actorLocal); String hActor = (attr != null) ? attr.getValue() : null; if (WSSecurityUtil.isActorEqual(actor, hActor)) { return true; } } } return false; }
Example 18
Source File: MAPCodecTest.java From cxf with Apache License 2.0 | 5 votes |
private SoapMessage setUpMessage(boolean requestor, boolean outbound, boolean invalidMAP, boolean preExistingSOAPAction, Boolean generateRelatesTo, String exposeAs) throws Exception { SoapMessage message = new SoapMessage(new MessageImpl()); setUpOutbound(message, outbound); expectRelatesTo = generateRelatesTo != null ? generateRelatesTo : (requestor && !outbound) || (!requestor && outbound); message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor)); String mapProperty = getMAPProperty(requestor, outbound); AddressingProperties maps = getMAPs(requestor, outbound, exposeAs); final Element header = control.createMock(Element.class); codec.setHeaderFactory(new MAPCodec.HeaderFactory() { public Element getHeader(SoapVersion version) { return header; } }); List<Header> headers = message.getHeaders(); JAXBContext jaxbContext = control.createMock(JAXBContext.class); ContextJAXBUtils.setJAXBContext(jaxbContext); Names200408.setJAXBContext(jaxbContext); Names200403.setJAXBContext(jaxbContext); if (outbound) { setUpEncode(requestor, message, header, maps, mapProperty, invalidMAP, preExistingSOAPAction); } else { setUpDecode(message, headers, maps, mapProperty, requestor); } control.replay(); return message; }
Example 19
Source File: RMSoapInInterceptor.java From cxf with Apache License 2.0 | 5 votes |
/** * Decode the RM properties from protocol-specific headers. * * @param message the SOAP message * @return the RM properties */ public RMProperties unmarshalRMProperties(SoapMessage message) { RMProperties rmps = (RMProperties)message.get(RMContextUtils.getRMPropertiesKey(false)); if (rmps == null) { rmps = new RMProperties(); } List<Header> headers = message.getHeaders(); if (headers != null) { decodeHeaders(message, headers, rmps); } return rmps; }
Example 20
Source File: MAPCodecTest.java From cxf with Apache License 2.0 | 4 votes |
private void verifyMessage(SoapMessage message, boolean requestor, boolean outbound, boolean exposedAsNative) { if (requestor) { if (outbound) { String id = expectedValues[1] instanceof AttributedURIType ? ((AttributedURIType)expectedValues[1]).getValue() : expectedValues[0] instanceof AttributedURI ? ((AttributedURI)expectedValues[1]).getValue() : ((org.apache.cxf.ws.addressing.v200403.AttributedURI)expectedValues[1]).getValue(); assertSame("unexpected correlated exchange", codec.uncorrelatedExchanges.get(id), message.getExchange()); } else { if (isReply(exposedAsNative)) { assertSame("unexpected correlated exchange", correlatedExchange, message.getExchange()); } else { assertNotSame("unexpected correlated exchange", correlatedExchange, message.getExchange()); } assertEquals("expected empty uncorrelated exchange cache", 0, codec.uncorrelatedExchanges.size()); } } if (outbound) { int expectedMarshals = requestor ? expectedValues.length - 1 : expectedValues.length; if (!expectFaultTo) { --expectedMarshals; } List<Header> headers = message.getHeaders(); assertTrue("expected holders added to header list", headers.size() >= expectedMarshals); for (int i = 0; i < (expectFaultTo ? expectedValues.length : expectedValues.length - 1); i++) { if (i == 4 && !expectRelatesTo) { i++; } assertTrue("expected " + expectedNames[i] + " added to headers", message .hasHeader(expectedNames[i])); } } assertTrue("unexpected MAPs", verifyMAPs(message.get(getMAPProperty(requestor, outbound)))); }