/** * Add a header block to the SOAP envelope contained within the specified message context's * {@link MessageContext#getOutboundMessage()}. * * @param messageContext the message context being processed * @param headerBlock the header block to add */ public static void addHeaderBlock(MessageContext messageContext, XMLObject headerBlock) { XMLObject outboundEnvelope = messageContext.getOutboundMessage(); if (outboundEnvelope == null) { throw new IllegalArgumentException("Message context does not contain a SOAP envelope"); } // SOAP 1.1 Envelope if (outboundEnvelope instanceof Envelope) { addSOAP11HeaderBlock((Envelope) outboundEnvelope, headerBlock); } //TODO SOAP 1.2 support when object providers are implemented }
/** {@inheritDoc} */ protected void encodeToTransport(MessageContext messageContext) throws MessageEncodingException { Element envelopeElem = marshallMessage(messageContext.getOutboundMessage()); preprocessTransport(messageContext); try { OutTransport outTransport = messageContext.getOutboundMessageTransport(); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) { log.error("JVM does not support required UTF-8 encoding"); throw new MessageEncodingException("JVM does not support required UTF-8 encoding"); } catch (IOException e) { log.error("Unable to write message content to outbound stream", e); throw new MessageEncodingException("Unable to write message content to outbound stream", e); } }
/** * Encode the message context to the transport. * * @param messageContext the message context to process * @throws MessageEncodingException thrown if there is a problem encoding the message context * to the transport */ protected void encodeToTransport(MessageContext messageContext) throws MessageEncodingException { Element envelopeElem = marshallMessage(messageContext.getOutboundMessage()); preprocessTransport(messageContext); try { OutTransport outTransport = messageContext.getOutboundMessageTransport(); Writer out = new OutputStreamWriter(outTransport.getOutgoingStream(), "UTF-8"); XMLHelper.writeNode(envelopeElem, out); out.flush(); } catch (UnsupportedEncodingException e) { log.error("JVM does not support required UTF-8 encoding"); throw new MessageEncodingException("JVM does not support required UTF-8 encoding"); } catch (IOException e) { log.error("Unable to write message content to outbound stream", e); throw new MessageEncodingException("Unable to write message content to outbound stream", e); } }
/** * Log the encoded message to the protocol message logger. * * @param messageContext the message context to process */ protected void logEncodedMessage(MessageContext messageContext) { if(protocolMessageLog.isDebugEnabled() && messageContext.getOutboundMessage() != null){ if (messageContext.getOutboundMessage().getDOM() == null) { try { marshallMessage(messageContext.getOutboundMessage()); } catch (MessageEncodingException e) { log.error("Unable to marshall message for logging purposes: " + e.getMessage()); return; } } protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getOutboundMessage().getDOM())); } }
/** * Get a header block from the SOAP envelope contained within the specified message context's * {@link MessageContext#getOutboundMessage()}. * * @param msgContext the message context being processed * @param headerName the name of the header block to return * @param targetNodes the explicitly specified SOAP node actors (1.1) or roles (1.2) 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 */ public static List<XMLObject> getOutboundHeaderBlock(MessageContext msgContext, QName headerName, Set<String> targetNodes, boolean isFinalDestination) { XMLObject outboundEnvelope = msgContext.getOutboundMessage(); if (outboundEnvelope == null) { throw new IllegalArgumentException("Message context does not contain an outbound SOAP envelope"); } // SOAP 1.1 Envelope if (outboundEnvelope instanceof Envelope) { return getSOAP11HeaderBlock((Envelope) outboundEnvelope, headerName, targetNodes, isFinalDestination); } //TODO SOAP 1.2 support when object providers are implemented return Collections.emptyList(); }
/** {@inheritDoc} */ protected void prepareMessageContext(MessageContext messageContext) throws MessageEncodingException { if (messageContext.getOutboundMessage() == null) { messageContext.setOutboundMessage(buildSOAPEnvelope(messageContext)); } }
/** * 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> * * @param messageContext the current message context being processed * @return a SOAPAction HTTP header URI value */ protected String getSOAPAction(MessageContext messageContext) { Envelope env = (Envelope) messageContext.getOutboundMessage(); 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(); } }