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

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

Source:SoapMessageConverter.java Github

copy

Full Screen

...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);...

Full Screen

Full Screen

handleInboundHttpHeaders

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.endpoint.CitrusEndpoints2import com.consol.citrus.dsl.runner.TestRunner3import com.consol.citrus.dsl.runner.TestRunnerSupport4import com.consol.citrus.message.MessageType5import com.consol.citrus.ws.client.WebServiceClient6import com.consol.citrus.ws.message.converter.SoapMessageConverter7void test() {8 .soap()9 .client()10 .messageConverter(new SoapMessageConverter() {11 public void handleInboundHttpHeaders(MessageHeaders httpHeaders, Map<String, Object> messageHeaders) {12 super.handleInboundHttpHeaders(httpHeaders, messageHeaders)13 messageHeaders.put("SOAPAction", httpHeaders.get("SOAPAction"))14 }15 })16 .build()17 TestRunner runner = TestRunnerSupport.testRunner()18 runner.http(builder -> builder19 .client(client)20 .send()21 .post()22 .header("SOAPAction", "echo")23 .accept("text/xml")24 runner.receive(builder -> builder25 .client(client)26 .messageType(MessageType.XML)

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