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

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

Source:WebServiceEndpoint.java Github

copy

Full Screen

...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 response201 * @param replyMessage202 */203 private void addSoapHeaders(SoapMessage response, Message replyMessage) throws TransformerException {204 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {205 if (MessageHeaderUtils.isSpringInternalHeader(headerEntry.getKey()) ||206 headerEntry.getKey().startsWith(DEFAULT_JMS_HEADER_PREFIX)) {207 continue;208 }209 if (headerEntry.getKey().equalsIgnoreCase(SoapMessageHeaders.SOAP_ACTION)) {210 response.setSoapAction(headerEntry.getValue().toString());211 } else if (!headerEntry.getKey().startsWith(MessageHeaders.PREFIX)) {212 SoapHeaderElement headerElement;213 if (QNameUtils.validateQName(headerEntry.getKey())) {214 QName qname = QNameUtils.parseQNameString(headerEntry.getKey());215 if (StringUtils.hasText(qname.getNamespaceURI())) {216 headerElement = response.getSoapHeader().addHeaderElement(qname);217 } else {...

Full Screen

Full Screen

addSoapHeaders

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner2import com.consol.citrus.dsl.design.TestDesignerRunner3import com.consol.citrus.ws.client.WebServiceClient4import com.consol.citrus.ws.server.WebServiceEndpoint5import com.consol.citrus.ws.message.SoapMessageHeaders6import com.consol.citrus.dsl.runner.TestRunner7class SoapHeaderTest extends TestDesignerRunner {8 void configure() {9 WebServiceEndpoint server = getWebServiceServerBuilder()10 .server("soapHeaderServer")11 .autoStart(true)12 .build()13 WebServiceClient client = getWebServiceClientBuilder()14 .client("soapHeaderClient")15 .build()16 variable("header1", "value1")17 variable("header2", "value2")18 soap()19 .client(client)20 .send()21 .soapAction("getSoapHeader")22 "<text>citrus:concat('Hello ', 'World!')</text>" +23 soap()24 .server(server)25 .receive()26 "<text>${text}</text>" +27 .header(SoapMessageHeaders.SOAP_ACTION, "getSoapHeaderResponse")28 .extractFromHeader(SoapMessageHeaders.SOAP_ACTION, "soapAction")29 soap()30 .server(server)31 .send()32 "<text>${text}</text>" +33 .header(SoapMessageHeaders.SOAP_ACTION, "getSoapHeaderResponse")

Full Screen

Full Screen

addSoapHeaders

Using AI Code Generation

copy

Full Screen

1public void addSoapHeaders(org.springframework.ws.soap.SoapHeader soapHeader) {2}3public void addSoapHeader(String name, String value) {4}5public void addSoapHeader(QName name, String value) {6 getSoapHeaders().add(new SoapHeader(name, value));7}8public void addSoapHeader(String name, String value, String namespace) {9 addSoapHeader(new QName(namespace, name, "citrus"), value);10}11public void addSoapHeader(QName name, String value, String namespace) {12 getSoapHeaders().add(new SoapHeader(name, value, namespace));13}14public void addSoapHeader(QName name, String value, String namespace, String prefix) {15 getSoapHeaders().add(new SoapHeader(name, value, namespace, prefix));16}17public void addSoapHeader(QName name, String value, String namespace, String prefix, String actor) {18 getSoapHeaders().add(new SoapHeader(name, value, namespace, prefix, actor));19}20public void addSoapHeader(QName name, String value, String namespace, String prefix, String actor, boolean mustUnderstand) {21 getSoapHeaders().add(new SoapHeader(name, value, namespace, prefix, actor, mustUnderstand));22}

Full Screen

Full Screen

addSoapHeaders

Using AI Code Generation

copy

Full Screen

1send(soapEndpoint)2 .header("Operation", "sayHello")3 .header("citrus_soap_action", "sayHello");4receive(soapEndpoint)5 .header("Operation", "sayHello")6 .header("citrus_soap_action", "sayHello")7send(soapEndpoint)8 .header("Operation", "sayHello")9 .header("citrus_soap_action", "sayHello");10receive(soapEndpoint)11 .header("Operation", "sayHello")12 .header("citrus_soap_action", "sayHello")13send(soapEndpoint)

Full Screen

Full Screen

addSoapHeaders

Using AI Code Generation

copy

Full Screen

1public void test() {2 SoapHeader soapHeader = new SoapHeader();3 soapHeader.setPrefix("ns1");4 soapHeader.setValue("testValue");5 List<SoapHeader> soapHeaders = new ArrayList<>();6 soapHeaders.add(soapHeader);7 SoapHeaderElement soapHeaderElement = new SoapHeaderElement();8 soapHeaderElement.setPrefix("ns1");9 soapHeaderElement.setValue("testValue");10 List<SoapHeaderElement> soapHeaderElements = new ArrayList<>();11 soapHeaderElements.add(soapHeaderElement);12 SoapHeaderBlock soapHeaderBlock = new SoapHeaderBlock();13 soapHeaderBlock.setPrefix("ns1");14 soapHeaderBlock.setValue("testValue");15 List<SoapHeaderBlock> soapHeaderBlocks = new ArrayList<>();16 soapHeaderBlocks.add(soapHeaderBlock);17 SoapHeaderFragment soapHeaderFragment = new SoapHeaderFragment();18 soapHeaderFragment.setPrefix("ns1");19 soapHeaderFragment.setValue("testValue");

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