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

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

Source:SoapMessageConverter.java Github

copy

Full Screen

...123 transformer.transform(webServiceMessage.getPayloadSource(), payloadResult);124 payload = payloadResult.toString();125 }126 final SoapMessage message = new SoapMessage(payload);127 handleInboundMessageProperties(messageContext, message);128 if (webServiceMessage instanceof org.springframework.ws.soap.SoapMessage) {129 handleInboundSoapMessage((org.springframework.ws.soap.SoapMessage) webServiceMessage, message, endpointConfiguration);130 }131 handleInboundHttpHeaders(message, endpointConfiguration);132 return message;133 } catch (final TransformerException e) {134 throw new CitrusRuntimeException("Failed to read web service message payload source", e);135 } catch (final IOException e) {136 throw new CitrusRuntimeException("Failed to read web service message", e);137 }138 }139 /**140 * Method handles SOAP specific message information such as SOAP action headers and SOAP attachments.141 *142 * @param soapMessage143 * @param message144 * @param endpointConfiguration145 */146 protected void handleInboundSoapMessage(final org.springframework.ws.soap.SoapMessage soapMessage,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 * ...

Full Screen

Full Screen

handleInboundMessageProperties

Using AI Code Generation

copy

Full Screen

1com.consol.citrus.ws.message.converter.SoapMessageConverter.handleInboundMessageProperties(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)2com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessageProperties(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)3com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessageHeaders(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)4com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessagePayload(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)5com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessagePayload(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)6com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessagePayload(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)7com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessagePayload(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)8com.consol.citrus.ws.message.converter.SoapMessageConverter.handleOutboundMessagePayload(org.springframework.ws.soap.SoapMessage, com.consol.citrus.message.Message)

Full Screen

Full Screen

handleInboundMessageProperties

Using AI Code Generation

copy

Full Screen

1import org.springframework.context.annotation.Bean;2import org.springframework.context.annotation.Configuration;3import org.springframework.context.annotation.ImportResource;4import org.springframework.ws.soap.SoapMessageFactory;5import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;6import org.springframework.ws.transport.http.HttpComponentsMessageSender;7import com.consol.citrus.dsl.builder.HttpServerActionBuilder;8import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder;9import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder;10import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder;11import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseBodyBuilder;12import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder.HttpResponseHeaderEntryBuilder;13import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseBodyBuilder.HttpResponseBodyEntryBuilder;14import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder.HttpResponseHeaderEntryBuilder.HttpResponseHeaderEntryValueBuilder;15import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseBodyBuilder.HttpResponseBodyEntryBuilder.HttpResponseBodyEntryValueBuilder;16import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder.HttpResponseHeaderEntryBuilder.HttpResponseHeaderEntryValueBuilder.HttpResponseHeaderEntryValueDataBuilder;17import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseBodyBuilder.HttpResponseBodyEntryBuilder.HttpResponseBodyEntryValueBuilder.HttpResponseBodyEntryValueDataBuilder;18import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder.HttpResponseHeaderEntryBuilder.HttpResponseHeaderEntryValueBuilder.HttpResponseHeaderEntryValueDataBuilder.HttpResponseHeaderEntryValueDataBuilderSupport;19import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseBodyBuilder.HttpResponseBodyEntryBuilder.HttpResponseBodyEntryValueBuilder.HttpResponseBodyEntryValueDataBuilder.HttpResponseBodyEntryValueDataBuilderSupport;20import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder.HttpResponseBuilder.HttpResponseHeaderBuilder.HttpResponseHeaderEntryBuilder.HttpResponseHeaderEntryValueBuilder.HttpResponseHeaderEntryValueDataBuilder.HttpResponseHeaderEntryValueDataBuilderSupport.HttpResponseHeaderEntryValueDataBuilderSupportSupport;21import com.consol.citrus.dsl.builder.Http

Full Screen

Full Screen

handleInboundMessageProperties

Using AI Code Generation

copy

Full Screen

1public class SoapMessageConverterTest {2 public void testHandleInboundMessageProperties() {3 SoapMessageConverter soapMessageConverter = new SoapMessageConverter();4 soapMessageConverter.setWebServiceTemplate(new WebServiceTemplate());5 soapMessageConverter.setMarshaller(new XStreamMarshaller());6 soapMessageConverter.setUnmarshaller(new XStreamMarshaller());7 soapMessageConverter.setPayloadRootClass(SayHello.class);8 soapMessageConverter.setPayloadElementClass(SayHello.class);9 soapMessageConverter.setSoapAction("sayHello");10 soapMessageConverter.setSoapVersion(SoapVersion.SOAP_12);11 soapMessageConverter.setSoap11FaultCodeServer("server");12 soapMessageConverter.setSoap11FaultCodeClient("client");13 soapMessageConverter.setSoap11FaultCodeVersionMismatch("versionMismatch");14 soapMessageConverter.setSoap11FaultCodeMustUnderstand("mustUnderstand");15 soapMessageConverter.setSoap11FaultCodeDataEncodingUnknown("dataEncodingUnknown");16 soapMessageConverter.setSoap11FaultCodeSender("sender");17 soapMessageConverter.setSoap11FaultCodeReceiver("receiver");18 soapMessageConverter.setSoap11FaultCodeSenderMustUnderstand("senderMustUnderstand");19 soapMessageConverter.setSoap11FaultCodeReceiverMustUnderstand("receiverMustUnderstand");20 soapMessageConverter.setSoap11FaultCodeDataEncodingUnknownMustUnderstand("dataEncodingUnknownMustUnderstand");21 soapMessageConverter.setSoap12FaultCodeSender("sender");22 soapMessageConverter.setSoap12FaultCodeReceiver("receiver");23 soapMessageConverter.setSoap12FaultCodeVersionMismatch("versionMismatch");24 soapMessageConverter.setSoap12FaultCodeMustUnderstand("mustUnderstand");25 soapMessageConverter.setSoap12FaultCodeDataEncodingUnknown("dataEncodingUnknown");26 soapMessageConverter.setSoap12FaultCodeSenderMustUnderstand("senderMustUnderstand");27 soapMessageConverter.setSoap12FaultCodeReceiverMustUnderstand("receiverMustUnderstand");28 soapMessageConverter.setSoap12FaultCodeDataEncodingUnknownMustUnderstand("dataEncodingUnknownMustUnderstand");

Full Screen

Full Screen

handleInboundMessageProperties

Using AI Code Generation

copy

Full Screen

1soap().client()2 .send()3 .soapAction("urn:examples:helloservice:HelloServicePortType:helloRequest")4 </soapenv:Envelope>");5soap().server()6 .receive()7 .soapAction("urn:examples:helloservice:HelloServicePortType:helloResponse")8 </soapenv:Envelope>");

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