public String toString() { StringBuilder builder = new StringBuilder("SaajSoapMessage"); try { SOAPEnvelope envelope = getImplementation().getEnvelope(saajMessage); if (envelope != null) { SOAPBody body = getImplementation().getBody(envelope); if (body != null) { SOAPElement bodyElement = getImplementation().getFirstBodyElement(body); if (bodyElement != null) { builder.append(' '); builder.append(getImplementation().getName(bodyElement)); } } } } catch (SOAPException ex) { // ignore } return builder.toString(); }
/** * Create a new <code>SaajSoapMessage</code> based on the given SAAJ <code>SOAPMessage</code>. * * @param soapMessage the SAAJ SOAPMessage * @param langAttributeOnSoap11FaultString * whether a {@code xml:lang} attribute is allowed on SOAP 1.1 {@code <faultstring>} elements * @param messageFactory the message factory */ public SaajSoapMessage(SOAPMessage soapMessage, boolean langAttributeOnSoap11FaultString, MessageFactory messageFactory) { Assert.notNull(soapMessage, "soapMessage must not be null"); saajMessage = soapMessage; this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString; MimeHeaders headers = getImplementation().getMimeHeaders(soapMessage); if (ObjectUtils.isEmpty(headers.getHeader(TransportConstants.HEADER_SOAP_ACTION))) { headers.addHeader(TransportConstants.HEADER_SOAP_ACTION, "\"\""); } this.messageFactory = messageFactory; }
public Attachment getAttachment(String contentId) { Assert.hasLength(contentId, "contentId must not be empty"); MimeHeaders mimeHeaders = new MimeHeaders(); mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_ID, contentId); Iterator<AttachmentPart> iterator = getImplementation().getAttachment(getSaajMessage(), mimeHeaders); if (!iterator.hasNext()) { return null; } AttachmentPart saajAttachment = iterator.next(); return new SaajAttachment(saajAttachment); }
public Attachment addAttachment(String contentId, DataHandler dataHandler) { Assert.hasLength(contentId, "contentId must not be empty"); Assert.notNull(dataHandler, "dataHandler must not be null"); AttachmentPart saajAttachment = getImplementation().addAttachmentPart(getSaajMessage(), dataHandler); saajAttachment.setContentId(contentId); saajAttachment.setMimeHeader(TransportConstants.HEADER_CONTENT_TRANSFER_ENCODING, "binary"); return new SaajAttachment(saajAttachment); }
public Iterator<Attachment> getAttachments() throws AttachmentException { Iterator<AttachmentPart> iterator = getImplementation().getAttachments(getSaajMessage()); return new SaajAttachmentIterator(iterator); }
public void writeTo(OutputStream outputStream) throws IOException { MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage()); if (ObjectUtils.isEmpty(mimeHeaders.getHeader(TransportConstants.HEADER_ACCEPT))) { mimeHeaders.setHeader(TransportConstants.HEADER_ACCEPT, getVersion().getContentType()); } try { getImplementation().writeTo(getSaajMessage(), outputStream); outputStream.flush(); } catch (SOAPException ex) { throw new SaajSoapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex); } }
public SoapEnvelope getEnvelope() { if (envelope == null) { try { SOAPEnvelope saajEnvelope = getImplementation().getEnvelope(getSaajMessage()); envelope = new SaajSoapEnvelope(saajEnvelope, langAttributeOnSoap11FaultString); } catch (SOAPException ex) { throw new SaajSoapEnvelopeException(ex); } } return envelope; }
public String getSoapAction() { MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage()); if (SoapVersion.SOAP_11 == getVersion()) { String[] actions = mimeHeaders.getHeader(TransportConstants.HEADER_SOAP_ACTION); return ObjectUtils.isEmpty(actions) ? TransportConstants.EMPTY_SOAP_ACTION : actions[0]; } else if (SoapVersion.SOAP_12 == getVersion()) { String[] contentTypes = mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE); return !ObjectUtils.isEmpty(contentTypes) ? SoapUtils.extractActionFromContentType(contentTypes[0]) : TransportConstants.EMPTY_SOAP_ACTION; } else { throw new IllegalStateException("Unsupported SOAP version: " + getVersion()); } }
public void setSoapAction(String soapAction) { MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage()); soapAction = SoapUtils.escapeAction(soapAction); if (SoapVersion.SOAP_11 == getVersion()) { mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction); } else if (SoapVersion.SOAP_12 == getVersion()) { // force save of Content Type header if (saajMessage.saveRequired()) { try { saajMessage.saveChanges(); } catch (SOAPException ex) { throw new SaajSoapMessageException("Could not save message", ex); } } String[] contentTypes = mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE); String contentType = !ObjectUtils.isEmpty(contentTypes) ? contentTypes[0] : getVersion().getContentType(); contentType = SoapUtils.setActionInContentType(contentType, soapAction); mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType); mimeHeaders.removeHeader(TransportConstants.HEADER_SOAP_ACTION); } else { throw new IllegalStateException("Unsupported SOAP version: " + getVersion()); } }