How to use toString method of com.consol.citrus.ws.message.SoapFault class

Best Citrus code snippet using com.consol.citrus.ws.message.SoapFault.toString

Source:WebServiceEndpoint.java Github

copy

Full Screen

...78 Assert.notNull(messageContext.getRequest(), "Request must not be null - unable to send message");79 80 Message requestMessage = endpointConfiguration.getMessageConverter().convertInbound(messageContext.getRequest(), messageContext, endpointConfiguration);81 if (log.isDebugEnabled()) {82 log.debug("Received SOAP request:\n" + requestMessage.toString());83 }84 85 //delegate request processing to endpoint adapter86 Message replyMessage = endpointAdapter.handleMessage(requestMessage);87 88 if (simulateHttpStatusCode(replyMessage)) {89 return;90 }91 92 if (replyMessage != null && replyMessage.getPayload() != null) {93 if (log.isDebugEnabled()) {94 log.debug("Sending SOAP response:\n" + replyMessage.toString());95 }96 97 SoapMessage response = (SoapMessage) messageContext.getResponse();98 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 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 {218 headerElement = response.getSoapHeader().addHeaderElement(getDefaultQName(headerEntry.getKey()));219 }220 } else {221 throw new SoapHeaderException("Failed to add SOAP header '" + headerEntry.getKey() + "', " +222 "because of invalid QName");223 }224 headerElement.setText(headerEntry.getValue().toString());225 }226 }227 for (String headerData : replyMessage.getHeaderData()) {228 TransformerFactory transformerFactory = TransformerFactory.newInstance();229 Transformer transformer = transformerFactory.newTransformer();230 transformer.transform(new StringSource(headerData),231 response.getSoapHeader().getResult());232 }233 }234 /**235 * Adds a SOAP fault to the SOAP response body. The SOAP fault is declared236 * as QName string in the response message's header (see {@link com.consol.citrus.ws.message.SoapMessageHeaders})237 * 238 * @param response...

Full Screen

Full Screen

Source:SoapFault.java Github

copy

Full Screen

...201 transformer.transform(detail.getSource(), detailResult);202 } catch (TransformerException e) {203 throw new CitrusRuntimeException(e);204 }205 return detailResult.toString();206 }207 /**208 * Adds token value decoration according to syntax.209 * @return210 */211 private static String decorate(String value) {212 return DECORATION_PREFIX + value + DECORATION_SUFFIX;213 }214 @Override215 public String toString() {216 StringBuilder builder = new StringBuilder();217 QName faultCodeQName = getFaultCodeQName();218 if (StringUtils.hasLength(faultCodeQName.getNamespaceURI()) && StringUtils.hasLength(faultCodeQName.getPrefix())) {219 builder.append(decorate(decorate(faultCodeQName.getNamespaceURI()) + faultCodeQName.getPrefix() + ":" + faultCodeQName.getLocalPart()));220 } else if (StringUtils.hasLength(faultCodeQName.getNamespaceURI())) {221 builder.append(decorate(decorate(faultCodeQName.getNamespaceURI()) + faultCodeQName.getLocalPart()));222 } else {223 builder.append(decorate(faultCodeQName.getLocalPart()));224 }225 if (StringUtils.hasText(getFaultString())) {226 builder.append(decorate(getFaultString()));227 if (getLocale() != null) {228 builder.append(decorate(getLocale().toString()));229 }230 if (faultActor != null) {231 builder.append(decorate(faultActor));232 }233 }234 return super.toString() + String.format("[fault: %s]", builder.toString());235 }236}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.ws.soap.SoapFault;3import org.springframework.ws.soap.SoapFaultDetail;4import org.springframework.ws.soap.SoapFaultDetailElement;5import org.springframework.ws.soap.SoapFaultDetailElementName;6import org.spring

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import org.springframework.ws.soap.SoapFault;3import org.springframework.ws.soap.SoapFaultDetail;4import org.springframework.ws.soap.SoapFaultDetailElement;5import org.springframework.ws.soap.SoapFaultReason;6import org.springframework.ws.soap.SoapFaultSubcode;7import org.springframework.ws.soap.SoapVersion;8import org.springframework.ws.soap.client.SoapFaultClientException;9import org.springframework.ws.soap.saaj.SaajSoapFault;10import org.springframework.ws.soap.saaj.SaajSoapMessage;11import org.springframework.xml.transform.StringSource;12import org.testng.Assert;13import org.testng.annotations.Test;14import org.w3c.dom.Document;15import org.w3c.dom.Element;16import org.w3c.dom.Node;17import org.w3c.dom.NodeList;18import javax.xml.soap.SOAPBody;19import javax.xml.soap.SOAPElement;20import javax.xml.soap.SOAPException;21import javax.xml.soap.SOAPFault;22import javax.xml.soap.SOAPFactory;23import javax.xml.transform.TransformerException;24import java.io.IOException;25import java.util.Iterator;26public class TestSoapFault {27 public void testGetFaultString() throws SOAPException, TransformerException, IOException {28 SOAPFactory soapFactory = SOAPFactory.newInstance();29 SOAPFault soapFault = soapFactory.createFault();30 soapFault.setFaultString("my fault string");31 soapFault.setFaultCode("my fault code");32 SaajSoapFault saajSoapFault = new SaajSoapFault(soapFault);33 SaajSoapMessage saajSoapMessage = new SaajSoapMessage(soapFault.getOwnerDocument());34 SoapFaultClientException soapFaultClientException = new SoapFaultClientException(saajSoapFault, saajSoapMessage);35 SoapFault soapFault1 = soapFaultClientException.getSoapFault();36 System.out.println(soapFault1.toString());37 Assert.assertEquals(soapFault1.getFaultString(), "my fault string");38 Assert.assertEquals(soapFault1.getFaultCode(), "my fault code");39 }40}41package com.consol.citrus.ws.actions;42import org.springframework.ws.soap.SoapFault;43import org.springframework.ws.soap.SoapFaultDetail;44import org.springframework.ws.soap.SoapFaultDetailElement;45import org.springframework.ws.soap.SoapFaultReason;46import org.springframework.ws.soap.SoapFault

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1SoapFault soapFault = new SoapFault();2soapFault.setFaultString("faultString");3soapFault.setFaultCode("faultCode");4soapFault.setFaultActor("faultActor");5soapFault.setFaultDetail("faultDetail");6System.out.println(soapFault.toString());7SoapMessage soapMessage = new SoapMessage();8soapMessage.setFault(soapFault);9System.out.println(soapMessage.toString());10SoapAttachment soapAttachment = new SoapAttachment();11soapAttachment.setContent("content");12soapAttachment.setMimeType("mimeType");13soapAttachment.setContentId("contentId");14soapAttachment.setCharset("charset");15System.out.println(soapAttachment.toString());16SoapAttachment soapAttachment = new SoapAttachment();17soapAttachment.setContent("content");18soapAttachment.setMimeType("mimeType");19soapAttachment.setContentId("contentId");20soapAttachment.setCharset("charset");21System.out.println(soapAttachment.toString());22SoapAttachment soapAttachment = new SoapAttachment();23soapAttachment.setContent("content");24soapAttachment.setMimeType("mimeType");25soapAttachment.setContentId("contentId");26soapAttachment.setCharset("charset");27System.out.println(soapAttachment.toString());28SoapAttachment soapAttachment = new SoapAttachment();29soapAttachment.setContent("content");30soapAttachment.setMimeType("mimeType");31soapAttachment.setContentId("contentId");32soapAttachment.setCharset("charset");33System.out.println(soapAttachment.toString());34SoapAttachment soapAttachment = new SoapAttachment();35soapAttachment.setContent("content");36soapAttachment.setMimeType("mimeType");37soapAttachment.setContentId("contentId");38soapAttachment.setCharset("charset");39System.out.println(soapAttachment.toString());40SoapAttachment soapAttachment = new SoapAttachment();41soapAttachment.setContent("content");42soapAttachment.setMimeType("mimeType");43soapAttachment.setContentId("contentId");44soapAttachment.setCharset("charset");45System.out.println(soapAttachment.toString());

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import org.testng.annotations.Test;5public class SoapFaultTest extends AbstractTestNGUnitTest {6 public void testSoapFault() {7 SoapFault soapFault = new SoapFault();8 soapFault.setFaultCode("Client");9 soapFault.setFaultString("Invalid request");10 soapFault.setFaultDetail("<detail><message>Invalid request</message></detail>");11 TestContext context = new TestContext();12 context.setVariable("faultCode", "Server");13 context.setVariable("faultString", "Internal server error");14 context.setVariable("faultDetail", "<detail><message>Internal server error</message></detail>");15 soapFault.setFaultCode("${faultCode}");16 soapFault.setFaultString("${faultString}");17 soapFault.setFaultActor("${faultActor}");18 soapFault.setFaultDetail("${faultDetail}");19 soapFault.applyDynamicValues(context);20 System.out.println(soapFault.toString());21 }22}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import com.consol.citrus.ws.message.SoapFault;3import org.springframework.ws.soap.SoapVersion;4import org.springframework.ws.soap.SoapMessageFactory;5import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;6import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;7import org.springframework.ws.soap.server.endpoint.SoapFaultDefinitionEditor;8public class SoapFaultTest {9 public static void main(String[] args) {10 SoapFaultDefinitionEditor soapFaultDefinitionEditor = new SoapFaultDefinitionEditor();11 soapFaultDefinitionEditor.setAsText("Client");12 SoapFaultDefinition soapFaultDefinition = (SoapFaultDefinition) soapFaultDefinitionEditor.getValue();13 SoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();14 soapMessageFactory.setSoapVersion(SoapVersion.SOAP_12);15 SoapFault soapFault = new SoapFault(soapFaultDefinition, soapMessageFactory);16 System.out.println(soapFault.toString());17 }18}19package com.consol.citrus.ws;20import com.consol.citrus.ws.message.SoapFault;21import org.springframework.ws.soap.SoapVersion;22import org.springframework.ws.soap.SoapMessageFactory;23import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;24import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;25import org.springframework.ws.soap.server.endpoint.SoapFaultDefinitionEditor;26public class SoapFaultTest {27 public static void main(String[] args) {28 SoapFaultDefinitionEditor soapFaultDefinitionEditor = new SoapFaultDefinitionEditor();29 soapFaultDefinitionEditor.setAsText("Client");30 SoapFaultDefinition soapFaultDefinition = (SoapFaultDefinition) soapFaultDefinitionEditor.getValue();31 SoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory();32 soapMessageFactory.setSoapVersion(SoapVersion.SOAP_12);33 SoapFault soapFault = new SoapFault(soapFaultDefinition, soapMessageFactory);34 System.out.println(soapFault.toString());35 }36}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1SoapFault soapFault = new SoapFault();2soapFault.setFaultCode("soap:Server");3soapFault.setFaultString("SOAP Fault");4soapFault.setFaultDetail("This is a detailed fault message");5soapFault.setFaultReasonText("Reason text");6soapFault.setFaultDetailText("Detail text");7soapFault.setFaultDetailElementName("faultDetail");8soapFault.setFaultDetailAttributes(Collections.singletonMap("type", "error"));9soapFault.setFaultDetailElements(Collections.singletonMap("faultDetailElement", "faultDetailElementValue"));10soapFault.setFaultReasonTexts(Arrays.asList("Reason text 1", "Reason text 2"));11soapFault.setFaultReasonLanguages(Arrays.asList("en", "de"));12System.out.println(soapFault.toString());13SoapMessage soapMessage = new SoapMessage();14soapMessage.setFault(soapFault);15soapMessage.setSoapAction("soapAction");16soapMessage.setSoapVersion(SoapVersion.SOAP_12);17soapMessage.setSoapFactory(new SaajSoapMessageFactory(SoapVersion.SOAP_12));18soapMessage.setSoapEnvelope(soapMessage.getSoapFactory().createSoapEnvelope());19soapMessage.getSoapEnvelope().setBody(soapMessage.getSoapFactory().createSoapBody());20soapMessage.getSoapEnvelope().getBody().addFault(soapFault);21soapMessage.getSoapEnvelope().setHeader(soapMessage.getSoapFactory().createSoapHeader());22soapMessage.getSoapEnvelope().getHeader().addHeaderElement("headerElement");23soapMessage.getSoapEnvelope().getHeader().addHeaderElement("headerElement2");24soapMessage.getSoapEnvelope().getHeader().addHeaderElement("headerElement3");25soapMessage.getSoapEnvelope().getHeader().addHeaderElement("headerElement4");26System.out.println(soapMessage.toString());27SoapAttachment soapAttachment = new SoapAttachment();28soapAttachment.setContentId("contentId");29soapAttachment.setContentType("contentType");30soapAttachment.setContentLocation("contentLocation

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1SoapFault soapFault = new SoapFault();2soapFault.setFaultCode("Client");3soapFault.setFaultString("Invalid request");4soapFault.setFaultDetail("Invalid request");5soapFault.setFaultCodeWithPrefix("Client");6soapFault.setFaultCodeWithPrefix("Client");7soapFault.setFaultCodeWithPrefix("Client");

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful