How to use handleInboundAttachments method of com.consol.citrus.ws.message.converter.SoapMessageConverter class

Best Citrus code snippet using com.consol.citrus.ws.message.converter.SoapMessageConverter.handleInboundAttachments

Source:SoapMessageConverter.java Github

copy

Full Screen

...147 final SoapMessage message,148 final WebServiceEndpointConfiguration endpointConfiguration) {149 handleInboundNamespaces(soapMessage, message);150 handleInboundSoapHeaders(soapMessage, message);151 handleInboundAttachments(soapMessage, message);152 if (endpointConfiguration.isHandleMimeHeaders()) {153 handleInboundMimeHeaders(soapMessage, message);154 }155 }156 private void handleInboundNamespaces(final org.springframework.ws.soap.SoapMessage soapMessage,157 final SoapMessage message) {158 final Source envelopeSource = soapMessage.getEnvelope().getSource();159 if (envelopeSource != null && envelopeSource instanceof DOMSource) {160 final Node envelopeNode = ((DOMSource) envelopeSource).getNode();161 final NamedNodeMap attributes = envelopeNode.getAttributes();162 for (int i = 0; i < attributes.getLength(); i++) {163 final Node attribute = attributes.item(i);164 if (StringUtils.hasText(attribute.getNamespaceURI()) && attribute.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) {165 if (StringUtils.hasText(attribute.getNodeValue()) && !attribute.getNodeValue().equals(envelopeNode.getNamespaceURI())) {166 final String messagePayload = message.getPayload(String.class);167 if (StringUtils.hasText(messagePayload)) {168 int xmlProcessingInstruction = messagePayload.indexOf("?>");169 xmlProcessingInstruction = xmlProcessingInstruction > 0 ? (xmlProcessingInstruction + 2) : 0;170 int rootElementEnd = messagePayload.indexOf('>', xmlProcessingInstruction);171 if (rootElementEnd > 0) {172 if (messagePayload.charAt(rootElementEnd - 1) == '/') {173 // root element is closed immediately e.g. <root/> need to adjust root element end174 rootElementEnd--;175 }176 final String namespace = attribute.getNodeName() + "=\"" + attribute.getNodeValue() + "\"";177 if (!messagePayload.contains(namespace)) {178 message.setPayload(messagePayload.substring(0, rootElementEnd) + " " + namespace + messagePayload.substring(rootElementEnd));179 }180 }181 }182 }183 }184 }185 }186 }187 /**188 * Reads information from Http connection and adds them as Http marked headers to internal message representation.189 *190 * @param message191 */192 protected void handleInboundHttpHeaders(final SoapMessage message,193 final WebServiceEndpointConfiguration endpointConfiguration) {194 final TransportContext transportContext = TransportContextHolder.getTransportContext();195 if (transportContext == null) {196 log.warn("Unable to get complete set of http request headers - no transport context available");197 return;198 }199 final WebServiceConnection connection = transportContext.getConnection();200 if (connection instanceof HttpServletConnection) {201 final UrlPathHelper pathHelper = new UrlPathHelper();202 final HttpServletConnection servletConnection = (HttpServletConnection) connection;203 final HttpServletRequest httpServletRequest = servletConnection.getHttpServletRequest();204 message.setHeader(SoapMessageHeaders.HTTP_REQUEST_URI, pathHelper.getRequestUri(httpServletRequest));205 message.setHeader(SoapMessageHeaders.HTTP_CONTEXT_PATH, pathHelper.getContextPath(httpServletRequest));206 final String queryParams = pathHelper.getOriginatingQueryString(httpServletRequest);207 message.setHeader(SoapMessageHeaders.HTTP_QUERY_PARAMS, queryParams != null ? queryParams : "");208 message.setHeader(SoapMessageHeaders.HTTP_REQUEST_METHOD, httpServletRequest.getMethod());209 if (endpointConfiguration.isHandleAttributeHeaders()) {210 final Enumeration<String> attributeNames = httpServletRequest.getAttributeNames();211 while (attributeNames.hasMoreElements()) {212 final String attributeName = attributeNames.nextElement();213 final Object attribute = httpServletRequest.getAttribute(attributeName);214 message.setHeader(attributeName, attribute);215 }216 }217 } else {218 log.warn("Unable to get complete set of http request headers");219 try {220 message.setHeader(SoapMessageHeaders.HTTP_REQUEST_URI, connection.getUri());221 } catch (final URISyntaxException e) {222 log.warn("Unable to get http request uri from http connection", e);223 }224 }225 }226 /**227 * Reads all soap headers from web service message and 228 * adds them to message builder as normal headers. Also takes care of soap action header.229 * 230 * @param soapMessage the web service message.231 * @param message the response message builder.232 */233 protected void handleInboundSoapHeaders(final org.springframework.ws.soap.SoapMessage soapMessage,234 final SoapMessage message) {235 try {236 final SoapHeader soapHeader = soapMessage.getSoapHeader();237 if (soapHeader != null) {238 final Iterator<?> iter = soapHeader.examineAllHeaderElements();239 while (iter.hasNext()) {240 final SoapHeaderElement headerEntry = (SoapHeaderElement) iter.next();241 MessageHeaderUtils.setHeader(message, headerEntry.getName().getLocalPart(), headerEntry.getText());242 }243 if (soapHeader.getSource() != null) {244 final StringResult headerData = new StringResult();245 final TransformerFactory transformerFactory = TransformerFactory.newInstance();246 final Transformer transformer = transformerFactory.newTransformer();247 transformer.transform(soapHeader.getSource(), headerData);248 message.addHeaderData(headerData.toString());249 }250 }251 if (StringUtils.hasText(soapMessage.getSoapAction())) {252 if (soapMessage.getSoapAction().equals("\"\"")) {253 message.setHeader(SoapMessageHeaders.SOAP_ACTION, "");254 } else {255 if (soapMessage.getSoapAction().startsWith("\"") && soapMessage.getSoapAction().endsWith("\"")) {256 message.setHeader(SoapMessageHeaders.SOAP_ACTION,257 soapMessage.getSoapAction().substring(1, soapMessage.getSoapAction().length() - 1));258 } else {259 message.setHeader(SoapMessageHeaders.SOAP_ACTION, soapMessage.getSoapAction());260 }261 }262 }263 } catch (final TransformerException e) {264 throw new CitrusRuntimeException("Failed to read SOAP header source", e);265 }266 }267 /**268 * Adds a HTTP message header to the SOAP message.269 *270 * @param message the SOAP request message.271 * @param name the header name.272 * @param value the header value.273 * @param handleMimeHeaders should handle mime headers.274 */275 private void handleOutboundMimeMessageHeader(final org.springframework.ws.soap.SoapMessage message,276 final String name,277 final Object value,278 final boolean handleMimeHeaders) {279 if (!handleMimeHeaders) {280 return;281 }282 if (message instanceof SaajSoapMessage) {283 final SaajSoapMessage soapMsg = (SaajSoapMessage) message;284 final MimeHeaders headers = soapMsg.getSaajMessage().getMimeHeaders();285 headers.setHeader(name, value.toString());286 } else if (message instanceof AxiomSoapMessage) {287 log.warn("Unable to set mime message header '" + name + "' on AxiomSoapMessage - unsupported");288 } else {289 log.warn("Unsupported SOAP message implementation - unable to set mime message header '" + name + "'");290 }291 }292 293 /**294 * Adds mime headers to constructed response message. This can be HTTP headers in case295 * of HTTP transport. Note: HTTP headers may have multiple values that are represented as 296 * comma delimited string value.297 * 298 * @param soapMessage the source SOAP message.299 * @param message the message build constructing the result message.300 */301 protected void handleInboundMimeHeaders(final org.springframework.ws.soap.SoapMessage soapMessage,302 final SoapMessage message) {303 final Map<String, String> mimeHeaders = new HashMap<String, String>();304 MimeHeaders messageMimeHeaders = null;305 306 // to get access to mime headers we need to get implementation specific here307 if (soapMessage instanceof SaajSoapMessage) {308 messageMimeHeaders = ((SaajSoapMessage)soapMessage).getSaajMessage().getMimeHeaders();309 } else if (soapMessage instanceof AxiomSoapMessage) {310 // we do not handle axiom message implementations as it is very difficult to get access to the mime headers there311 log.warn("Skip mime headers for AxiomSoapMessage - unsupported");312 } else {313 log.warn("Unsupported SOAP message implementation - skipping mime headers");314 }315 316 if (messageMimeHeaders != null) {317 final Iterator<?> mimeHeaderIterator = messageMimeHeaders.getAllHeaders();318 while (mimeHeaderIterator.hasNext()) {319 final MimeHeader mimeHeader = (MimeHeader)mimeHeaderIterator.next();320 // http headers can have multpile values so headers might occur several times in map321 if (mimeHeaders.containsKey(mimeHeader.getName())) {322 // header is already present, so concat values to a single comma delimited string323 String value = mimeHeaders.get(mimeHeader.getName());324 value += ", " + mimeHeader.getValue();325 mimeHeaders.put(mimeHeader.getName(), value);326 } else {327 mimeHeaders.put(mimeHeader.getName(), mimeHeader.getValue());328 }329 }330 331 for (final Entry<String, String> httpHeaderEntry : mimeHeaders.entrySet()) {332 message.setHeader(httpHeaderEntry.getKey(), httpHeaderEntry.getValue());333 }334 }335 }336 337 /**338 * Adds all message properties from web service message to message builder 339 * as normal header entries.340 * 341 * @param messageContext the web service request message context.342 * @param message the request message builder.343 */344 protected void handleInboundMessageProperties(final MessageContext messageContext,345 final SoapMessage message) {346 if (messageContext == null) { return; }347 348 final String[] propertyNames = messageContext.getPropertyNames();349 if (propertyNames != null) {350 for (final String propertyName : propertyNames) {351 message.setHeader(propertyName, messageContext.getProperty(propertyName));352 }353 }354 }355 356 /**357 * Adds attachments if present in soap web service message.358 * 359 * @param soapMessage the web service message.360 * @param message the response message builder.361 */362 protected void handleInboundAttachments(final org.springframework.ws.soap.SoapMessage soapMessage,363 final SoapMessage message) {364 final Iterator<Attachment> attachments = soapMessage.getAttachments();365 while (attachments.hasNext()) {366 final Attachment attachment = attachments.next();367 final SoapAttachment soapAttachment = SoapAttachment.from(attachment);368 if (log.isDebugEnabled()) {369 log.debug(String.format("SOAP message contains attachment with contentId '%s'", soapAttachment.getContentId()));370 }371 message.addAttachment(soapAttachment);372 }373 }374 private SoapMessage convertMessageToSoapMessage(final Message message) {375 final SoapMessage soapMessage;376 if (message instanceof SoapMessage) {...

Full Screen

Full Screen

handleInboundAttachments

Using AI Code Generation

copy

Full Screen

1protected void handleInboundAttachments(Attachment[] attachments) {2 for (Attachment attachment : attachments) {3 try {4 System.out.println("Inbound attachment: " + attachment.getContentId() + " - " + attachment.getDataHandler().getContentType());5 } catch (IOException e) {6 e.printStackTrace();7 }8 }9}10protected void handleOutboundAttachments(Attachment[] attachments) {11 for (Attachment attachment : attachments) {12 try {13 System.out.println("Outbound attachment: " + attachment.getContentId() + " - " + attachment.getDataHandler().getContentType());14 } catch (IOException e) {15 e.printStackTrace();16 }17 }18}19protected void handleInboundAttachments(Attachment[] attachments) {20 for (Attachment attachment : attachments) {21 try {22 System.out.println("Inbound attachment: " + attachment.getContentId() + " - "

Full Screen

Full Screen

handleInboundAttachments

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner2import com.consol.citrus.dsl.design.TestDesignerBefore3import com.consol.citrus.dsl.design.TestDesignerAfter4import com.consol.citrus.dsl.design.TestDesignerBeforeSuite5import com.consol.citrus.dsl.design.TestDesignerAfterSuite6import com.consol.citrus.dsl.design.TestDesignerBeforeClass7import com.consol.citrus.dsl.design.TestDesignerAfterClass8import com.consol.citrus.dsl.design.TestDesignerBeforeTest9import com.consol.citrus.dsl.design.TestDesignerAfterTest10import com.consol.citrus.dsl.design.TestDesignerBeforeEach11import com.consol.citrus.dsl.design.TestDesignerAfterEach12import com.consol.citrus.dsl.design.TestDesignerBeforeGroups13import com.consol.citrus.dsl.design.TestDesignerAfterGroups14import com.consol.citrus.dsl.design.TestDesignerParameters15import com.consol.citrus.dsl.design.TestDesignerXmlSupport16import com.consol.citrus.dsl.design.TestDesignerXmlSupport17import co

Full Screen

Full Screen

handleInboundAttachments

Using AI Code Generation

copy

Full Screen

1public class SoapAttachmentTestIT extends TestNGCitrusTestDesigner {2 public void soapAttachmentTest() {3 variable("attachmentData", "Hello Citrus!");4 variable("attachmentId", "citrus:randomUUID()");5 http()6 .client("attachmentClient")7 .send()8 .post()9 .fork(true)10 .header("Content-Type", "application/soap+xml;charset=UTF-8")11 .attachment("citrus:randomUUID()", "text/plain", "Hello Citrus!");12 receive()13 .endpoint("attachmentEndpoint")14 .header("Content-Type", "application/soap+xml;charset=UTF-8")15 .attachment("citrus:randomUUID()", "text/plain", "Hello Citrus!");16 }17}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful