/** * Extracts the {@link UsernameToken} from the given {@link Envelope}. * * @param message the message from which the token should be extracted * * @return the extracted token */ @Nullable private UsernameToken getUsernameToken(@Nonnull final Envelope message) { final Header header = message.getHeader(); final List<XMLObject> securityHeaders = header.getUnknownXMLObjects(Security.ELEMENT_NAME); if (securityHeaders == null || securityHeaders.size() == 0) { log.debug("{} Inbound message does not contain <Security>", getLogPrefix()); return null; } final List<XMLObject> usernameTokens = ((Security) securityHeaders.get(0)).getUnknownXMLObjects(UsernameToken.ELEMENT_NAME); if (usernameTokens == null || usernameTokens.size() == 0) { log.debug("{} Inbound message security header does not contain <UsernameToken>", getLogPrefix()); return null; } return (UsernameToken) usernameTokens.get(0); } }
/** * Determine the value of the SOAPAction HTTP header to send. * * <p> * The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. * </p> * * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction() { Envelope env = getSOAPEnvelope(); Header header = env.getHeader(); if (header == null) { return null; } List<XMLObject> objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } }
/** * Determine the value of the SOAPAction HTTP header to send. * * <p> * The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. * </p> * * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction() { final Envelope env = getSOAPEnvelope(); final Header header = env.getHeader(); if (header == null) { return null; } final List<XMLObject> objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } }
/** * Determine the value of the SOAPAction HTTP header to send. * * <p> * The default behavior is to return the value of the SOAP Envelope's WS-Addressing Action header, * if present. * </p> * * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction() { Envelope env = getSOAPEnvelope(); Header header = env.getHeader(); if (header == null) { return null; } List<XMLObject> objList = header.getUnknownXMLObjects(Action.ELEMENT_NAME); if (objList == null || objList.isEmpty()) { return null; } else { return ((Action)objList.get(0)).getValue(); } }
/** * Get a header block from the SOAP 1.1 envelope. * * @param envelope the SOAP 1.1 envelope to process * @param headerName the name of the header block to return * @param targetNodes the explicitly specified SOAP node actors for which the header is desired * @param isFinalDestination true specifies that headers targeted for message final destination should be returned, * false specifies they should not be returned * @return the list of matching header blocks */ @Nonnull public static List<XMLObject> getSOAP11HeaderBlock(@Nonnull final Envelope envelope, @Nonnull final QName headerName, @Nullable final Set<String> targetNodes, boolean isFinalDestination) { Constraint.isNotNull(envelope, "Envelope cannot be null"); Constraint.isNotNull(headerName, "Header name cannot be null"); Header envelopeHeader = envelope.getHeader(); if (envelopeHeader == null) { return Collections.emptyList(); } LazyList<XMLObject> headers = new LazyList<>(); for (XMLObject header : envelopeHeader.getUnknownXMLObjects(headerName)) { if (isSOAP11HeaderTargetedToNode(header, targetNodes, isFinalDestination)) { headers.add(header); } } return headers; }
/** * Add a header to the SOAP 1.1 Envelope. * * @param envelope the SOAP 1.1 envelope to process * @param headerBlock the header to add */ public static void addSOAP11HeaderBlock(@Nonnull final Envelope envelope, @Nonnull final XMLObject headerBlock) { Constraint.isNotNull(envelope, "Envelope cannot be null"); Constraint.isNotNull(headerBlock, "Header block cannot be null"); Header envelopeHeader = envelope.getHeader(); if (envelopeHeader == null) { envelopeHeader = (Header) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder( Header.DEFAULT_ELEMENT_NAME).buildObject(Header.DEFAULT_ELEMENT_NAME); envelope.setHeader(envelopeHeader); } envelopeHeader.getUnknownXMLObjects().add(headerBlock); }