How to use addSoapBody method of com.consol.citrus.ws.server.WebServiceEndpoint class

Best Citrus code snippet using com.consol.citrus.ws.server.WebServiceEndpoint.addSoapBody

Source:WebServiceEndpoint.java Github

copy

Full Screen

...99 //add soap fault or normal soap body to response100 if (replyMessage instanceof SoapFault) {101 addSoapFault(response, (SoapFault) replyMessage);102 } else {103 addSoapBody(response, replyMessage);104 }105 addSoapAttachments(response, replyMessage);106 addSoapHeaders(response, replyMessage);107 addMimeHeaders(response, replyMessage);108 } else {109 if (log.isDebugEnabled()) {110 log.debug("No reply message from endpoint adapter '" + endpointAdapter + "'");111 }112 log.warn("No SOAP response for calling client");113 }114 }115 private void addSoapAttachments(MimeMessage response, Message replyMessage) {116 if (replyMessage instanceof com.consol.citrus.ws.message.SoapMessage) {117 List<SoapAttachment> soapAttachments = ((com.consol.citrus.ws.message.SoapMessage) replyMessage).getAttachments();118 soapAttachments.stream()119 .filter(soapAttachment -> !soapAttachment.isMtomInline())120 .forEach(soapAttachment -> {121 String contentId = soapAttachment.getContentId();122 if (!contentId.startsWith("<")) {123 contentId = "<" + contentId + ">";124 }125 response.addAttachment(contentId, soapAttachment.getDataHandler());126 });127 }128 }129 /**130 * If Http status code is set on reply message headers simulate Http error with status code.131 * No SOAP response is sent back in this case.132 * @param replyMessage133 * @return134 * @throws IOException 135 */136 private boolean simulateHttpStatusCode(Message replyMessage) throws IOException {137 if (replyMessage == null || CollectionUtils.isEmpty(replyMessage.getHeaders())) {138 return false;139 }140 141 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {142 if (headerEntry.getKey().equalsIgnoreCase(SoapMessageHeaders.HTTP_STATUS_CODE)) {143 WebServiceConnection connection = TransportContextHolder.getTransportContext().getConnection();144 145 int statusCode = Integer.valueOf(headerEntry.getValue().toString());146 if (connection instanceof HttpServletConnection) {147 ((HttpServletConnection)connection).setFault(false);148 ((HttpServletConnection)connection).getHttpServletResponse().setStatus(statusCode);149 return true;150 } else {151 log.warn("Unable to set custom Http status code on connection other than HttpServletConnection (" + connection.getClass().getName() + ")");152 }153 }154 }155 156 return false;157 }158 /**159 * Adds mime headers outside of SOAP envelope. Header entries that go to this header section 160 * must have internal http header prefix defined in {@link com.consol.citrus.ws.message.SoapMessageHeaders}.161 * @param response the soap response message.162 * @param replyMessage the internal reply message.163 */164 private void addMimeHeaders(SoapMessage response, Message replyMessage) {165 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {166 if (headerEntry.getKey().toLowerCase().startsWith(SoapMessageHeaders.HTTP_PREFIX)) {167 String headerName = headerEntry.getKey().substring(SoapMessageHeaders.HTTP_PREFIX.length());168 169 if (response instanceof SaajSoapMessage) {170 SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;171 MimeHeaders headers = saajSoapMessage.getSaajMessage().getMimeHeaders();172 headers.setHeader(headerName, headerEntry.getValue().toString());173 } else if (response instanceof AxiomSoapMessage) {174 log.warn("Unable to set mime message header '" + headerName + "' on AxiomSoapMessage - unsupported");175 } else {176 log.warn("Unsupported SOAP message implementation - unable to set mime message header '" + headerName + "'");177 }178 }179 }180 }181 /**182 * Add message payload as SOAP body element to the SOAP response.183 * @param response184 * @param replyMessage185 */186 private void addSoapBody(SoapMessage response, Message replyMessage) throws TransformerException {187 if (!(replyMessage.getPayload() instanceof String) || 188 StringUtils.hasText(replyMessage.getPayload(String.class))) {189 Source responseSource = getPayloadAsSource(replyMessage.getPayload());190 191 TransformerFactory transformerFactory = TransformerFactory.newInstance();192 Transformer transformer = transformerFactory.newTransformer();193 194 transformer.transform(responseSource, response.getPayloadResult());195 }196 }197 198 /**199 * Translates message headers to SOAP headers in response.200 * @param response...

Full Screen

Full Screen

addSoapBody

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTest;4import com.consol.citrus.xml.XsdSchemaRepository;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.core.io.ClassPathResource;7import org.springframework.http.HttpStatus;8import org.springframework.http.MediaType;9import org.springframework.ws.soap.SoapBody;10import org.testng.annotations.Test;11public class AddSoapBodyTest extends TestNGCitrusTest {12 private XsdSchemaRepository schemaRepository;13 public void addSoapBody() {14 TestRunner runner = citrus.createTestRunner();15 runner.http(builder -> builder.client("httpClient")16 .send()17 .post()18 .contentType(MediaType.APPLICATION_XML_VALUE)19 "</ns0:echoRequest>"));20 runner.http(builder -> builder.client("httpClient")21 .receive()22 .response(HttpStatus.OK)23 .messageType("application/xml;charset=UTF-8")24 .validateScript("addSoapBody()"));25 runner.http(builder -> builder.client("httpClient")26 .send()27 .post()28 .contentType(MediaType.APPLICATION_XML_VALUE)29 "</ns0:echoRequest>"));30 runner.http(builder -> builder.client("httpClient")31 .receive()32 .response(HttpStatus.OK)33 .messageType("application/xml;charset=UTF-8")34 .validateScript("addSoapBody()"));35 }36 public void addSoapBody() {37 soap().server("soapServer")38 .receive()39 "</ns0:echoRequest>");40 soap().server("soapServer")41 .addSoapBody()42 .schemaValidation(false)43 .schemaRepository(schemaRepository)

Full Screen

Full Screen

addSoapBody

Using AI Code Generation

copy

Full Screen

1public class SampleWebService {2 public String sayHello(String name) {3 return "Hello " + name;4 }5}6public void testSoapBody() {7 http()8 .client(webServiceClient)9 .send()10 .post("/sayHello")11 .soap()12 + "<name>citrus:concat('Hello ', 'World!')</name>"13 + "</sayHello>");14 http()15 .client(webServiceClient)16 .receive()17 .response(HttpStatus.OK)18 + "<return>citrus:concat('Hello ', 'World!')</return>"19 + "</sayHelloResponse>");20 webService()21 .server(webServiceServer)22 .receive()23 .post("/sayHello")24 + "<name>citrus:concat('Hello ', 'World!')</name>"25 + "</sayHello>");26 webService()27 .server(webServiceServer)28 .send()29 .response(HttpStatus.OK)30 + "<return>citrus:concat('Hello ', 'World!')</return>"31 + "</sayHelloResponse>");32 webService()33 .server(webServiceServer)34 .send()35 .response(HttpStatus.OK)36 .addSoapBody()37 + "<return>citrus:concat('Hello ', 'World!')</return>"38 + "</sayHelloResponse>");39 http()40 .client(webServiceClient)41 .send()42 .post("/sayHello")43 .soap()44 + "<name>citrus:concat('Hello ', 'World!')</name>"45 + "</sayHello>");46 http()47 .client(webServiceClient)48 .receive()49 .response(HttpStatus.OK)

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