How to use mtomEnabled method of com.consol.citrus.ws.message.SoapMessage class

Best Citrus code snippet using com.consol.citrus.ws.message.SoapMessage.mtomEnabled

Source:SendSoapMessageAction.java Github

copy

Full Screen

...47 private static final Logger LOG = LoggerFactory.getLogger(SendSoapMessageAction.class);48 /** SOAP attachments */49 private final List<SoapAttachment> attachments;50 /** enable/disable mtom attachments */51 private final boolean mtomEnabled;52 /** Marker for inline mtom binary data */53 public static final String CID_MARKER = "cid:";54 public SendSoapMessageAction(SendSoapMessageBuilder<?, ?, ?> builder) {55 super(builder);56 this.attachments = builder.getMessageBuilderSupport().getAttachments();57 this.mtomEnabled = builder.getMessageBuilderSupport().isMtomEnabled();58 }59 @Override60 protected SoapMessage createMessage(TestContext context, String messageType) {61 Message message = super.createMessage(context, getMessageType());62 SoapMessage soapMessage = new SoapMessage(message).mtomEnabled(mtomEnabled);63 try {64 for (SoapAttachment attachment : attachments) {65 attachment.setTestContext(context);66 if (mtomEnabled) {67 String messagePayload = soapMessage.getPayload(String.class);68 String cid = CID_MARKER + attachment.getContentId();69 if (attachment.isMtomInline() && messagePayload.contains(cid)) {70 byte[] attachmentBinaryData = FileUtils.readToString(attachment.getInputStream(), Charset.forName(attachment.getCharsetName())).getBytes(Charset.forName(attachment.getCharsetName()));71 if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_BASE64_BINARY)) {72 if (LOG.isDebugEnabled()) {73 LOG.debug(String.format("Adding inline base64Binary data for attachment: %s", cid));74 }75 messagePayload = messagePayload.replaceAll(cid, Base64.encodeBase64String(attachmentBinaryData));76 } else if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_HEX_BINARY)) {77 if (LOG.isDebugEnabled()) {78 LOG.debug(String.format("Adding inline hexBinary data for attachment: %s", cid));79 }80 messagePayload = messagePayload.replaceAll(cid, Hex.encodeHexString(attachmentBinaryData).toUpperCase());81 } else {82 throw new CitrusRuntimeException(String.format("Unsupported encoding type '%s' for SOAP attachment: %s - choose one of %s or %s",83 attachment.getEncodingType(), cid, SoapAttachment.ENCODING_BASE64_BINARY, SoapAttachment.ENCODING_HEX_BINARY));84 }85 } else {86 messagePayload = messagePayload.replaceAll(cid, String.format("<xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"%s\"/>", CID_MARKER + URLEncoder.encode(attachment.getContentId(), "UTF-8")));87 soapMessage.addAttachment(attachment);88 }89 soapMessage.setPayload(messagePayload);90 } else {91 soapMessage.addAttachment(attachment);92 }93 }94 } catch (IOException e) {95 throw new CitrusRuntimeException(e);96 }97 return soapMessage;98 }99 /**100 * Gets the attachments.101 * @return the attachments102 */103 public List<SoapAttachment> getAttachments() {104 return attachments;105 }106 /**107 * Gets mtom attachments enabled108 * @return109 */110 public boolean getMtomEnabled() {111 return this.mtomEnabled;112 }113 /**114 * Action builder.115 */116 public static final class Builder extends SendSoapMessageBuilder<SendSoapMessageAction, Builder.SendSoapMessageBuilderSupport, Builder> {117 public Builder() {118 message(new StaticMessageBuilder(soapMessage));119 }120 @Override121 public SendSoapMessageBuilderSupport getMessageBuilderSupport() {122 if (messageBuilderSupport == null) {123 messageBuilderSupport = new SendSoapMessageBuilderSupport(soapMessage, this);124 }125 return super.getMessageBuilderSupport();126 }127 public static class SendSoapMessageBuilderSupport extends SoapMessageBuilderSupport<SendSoapMessageAction, Builder, SendSoapMessageBuilderSupport> {128 protected SendSoapMessageBuilderSupport(SoapMessage soapMessage, Builder delegate) {129 super(soapMessage, delegate);130 }131 }132 @Override133 public SendSoapMessageAction doBuild() {134 return new SendSoapMessageAction(this);135 }136 }137 /**138 * Action builder.139 */140 public abstract static class SendSoapMessageBuilder<T extends SendSoapMessageAction, M extends SoapMessageBuilderSupport<T, B, M>, B extends SendSoapMessageBuilder<T, M, B>> extends SendMessageActionBuilder<T, M, B> {141 /** Soap message to send */142 protected SoapMessage soapMessage = new SoapMessage();143 public B mtomEnabled(boolean mtomEnabled) {144 getMessageBuilderSupport().mtomEnabled(mtomEnabled);145 return self;146 }147 }148 public static class SoapMessageBuilderSupport<T extends SendSoapMessageAction, B extends SendSoapMessageBuilder<T, M, B>, M extends SoapMessageBuilderSupport<T, B, M>> extends SendMessageBuilderSupport<T, B, M> {149 protected final SoapMessage soapMessage;150 private final List<SoapAttachment> attachments = new ArrayList<>();151 private boolean mtomEnabled = false;152 protected SoapMessageBuilderSupport(SoapMessage soapMessage, B delegate) {153 super(delegate);154 this.soapMessage = soapMessage;155 }156 @Override157 public M body(String payload) {158 soapMessage.setPayload(payload);159 return self;160 }161 @Override162 public M name(String name) {163 soapMessage.setName(name);164 return super.name(name);165 }166 @Override167 public M from(Message controlMessage) {168 SoapMessageUtils.copy(controlMessage, soapMessage);169 type(controlMessage.getType());170 return self;171 }172 /**173 * Sets special SOAP action message header.174 * @param soapAction175 * @return176 */177 public M soapAction(String soapAction) {178 soapMessage.header(SoapMessageHeaders.SOAP_ACTION, soapAction);179 return self;180 }181 /**182 * Sets the attachment with string content.183 * @param contentId184 * @param contentType185 * @param content186 * @return187 */188 public M attachment(String contentId, String contentType, String content) {189 SoapAttachment attachment = new SoapAttachment();190 attachment.setContentId(contentId);191 attachment.setContentType(contentType);192 attachment.setContent(content);193 attachment(attachment);194 return self;195 }196 /**197 * Sets the attachment with content resource.198 * @param contentId199 * @param contentType200 * @param contentResource201 * @return202 */203 public M attachment(String contentId, String contentType, Resource contentResource) {204 return attachment(contentId, contentType, contentResource, FileUtils.getDefaultCharset());205 }206 /**207 * Sets the attachment with content resource.208 * @param contentId209 * @param contentType210 * @param contentResource211 * @param charset212 * @return213 */214 public M attachment(String contentId, String contentType, Resource contentResource, Charset charset) {215 SoapAttachment attachment = new SoapAttachment();216 attachment.setContentId(contentId);217 attachment.setContentType(contentType);218 try {219 attachment.setContent(FileUtils.readToString(contentResource, charset));220 } catch (IOException e) {221 throw new CitrusRuntimeException("Failed to read attachment resource", e);222 }223 attachment(attachment);224 return self;225 }226 /**227 * Sets the charset name for this send action builder's attachment.228 * @param charsetName229 * @return230 */231 public M charset(String charsetName) {232 if (!this.attachments.isEmpty()) {233 this.attachments.get(this.attachments.size() - 1).setCharsetName(charsetName);234 }235 return self;236 }237 /**238 * Sets the attachment from Java object instance.239 * @param attachment240 * @return241 */242 public M attachment(SoapAttachment attachment) {243 this.attachments.add(attachment);244 return self;245 }246 /**247 * Set the endpoint URI for the request. This works only if the HTTP endpoint used248 * doesn't provide an own endpoint URI resolver.249 *250 * @param uri absolute URI to use for the endpoint251 * @return self252 */253 public M uri(String uri) {254 soapMessage.header(EndpointUriResolver.ENDPOINT_URI_HEADER_NAME, uri);255 return self;256 }257 /**258 * Sets the request content type header.259 * @param contentType260 * @return261 */262 public M contentType(String contentType) {263 soapMessage.header(SoapMessageHeaders.HTTP_CONTENT_TYPE, contentType);264 return self;265 }266 /**267 * Sets the request accept header.268 * @param accept269 * @return270 */271 public M accept(String accept) {272 soapMessage.header(SoapMessageHeaders.HTTP_ACCEPT, accept);273 return self;274 }275 public M mtomEnabled(boolean mtomEnabled) {276 soapMessage.mtomEnabled(mtomEnabled);277 this.mtomEnabled = mtomEnabled;278 return self;279 }280 protected List<SoapAttachment> getAttachments() {281 return attachments;282 }283 protected boolean isMtomEnabled() {284 return mtomEnabled;285 }286 }287}...

Full Screen

Full Screen

Source:SoapServerResponseActionBuilder.java Github

copy

Full Screen

...139 soapMessage.header(SoapMessageHeaders.HTTP_CONTENT_TYPE, contentType);140 return this;141 }142 143 public SoapServerResponseActionBuilder mtomEnabled(boolean mtomEnabled) {144 soapMessage.mtomEnabled(mtomEnabled);145 getAction().setMtomEnabled(mtomEnabled);146 return this;147 }148 @Override149 protected SendSoapMessageAction getAction() {150 return (SendSoapMessageAction) super.getAction();151 }152}...

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.ws.client.WebServiceClient;6import com.consol.citrus.ws.message.SoapMessage;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.core.io.ClassPathResource;9import org.springframework.http.HttpStatus;10import org.springframework.http.MediaType;11import org.testng.annotations.Test;12import java.util.HashMap;13import java.util.Map;14import static com.consol.citrus.actions.CreateVariablesAction.Builder.createVariable;15import static com.consol.citrus.container.FinallySequence.Builder.doFinally;16import static com.consol.citrus.container.Parallel.Builder.parallel;17import static com.consol.citrus.container.Sequence.Builder.sequential;18import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.assertException;19import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.receive;20import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.send;21import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.variable;22import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.variableExpressionSupport;23import static com.consol.citrus.dsl.builder.Builder.BuilderSupport.variableSupport;24public class SoapAttachmentTest extends TestNGCitrusTestDesigner {25 private WebServiceClient webServiceClient;26 public void attachmentTest() {27 parallel().actions(28 sequential().actions(29 send(webServiceClient)30 .message(new SoapMessage()31 .attachment("citrus:resource:classpath:com/consol/citrus/samples/attachment.txt")32 .attachment("citrus:resource:classpath:com/consol/citrus/samples/attachment.pdf")33 .attachment("citrus:resource:classpath:com/consol/citrus/samples/attachment.xls")34 .attachment("citrus:resource:classpath:com/consol/citrus/samples/attachment.doc")35 .attachment("citrus:resource:classpath:com/consol/citrus/samples

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.runner.TestRunners;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.ws.message.SoapMessage;5import org.testng.annotations.Test;6public class mtomEnabled {7 public void mtomEnabled() {8 TestRunner runner = TestRunners.inline().actions(9 .messageType(MessageType.SOAP)10 .header("SOAPAction", "sayHello")11 .header("Content-Type", "application/soap+xml; charset=UTF-8")12 .header("Content-Transfer-Encoding", "binary")13 .header("Content-ID", "<SOAP-ENV:Envelope>")14 .header("MTOM", "true")15 .header("Accept-Encoding", "gzip,deflate")16 .header("Connection", "Keep-Alive")17 .header("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)")18 .header("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")19 .header("Host", "localhost:8080")20 .header("Content-Length", "263")21 .header("Expect", "100-continue")22 );23 }24}25import com.consol.citrus.dsl.runner.TestRunner;26import com.consol.citrus.dsl.runner.TestRunners;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.ws.message.SoapMessage;29import org.testng.annotations.Test;30public class mtomEnabled {31 public void mtomEnabled() {32 TestRunner runner = TestRunners.inline().actions(33 .messageType(MessageType.SOAP)34 .payload("<ns0:HelloRequest xmlns:ns0=\"http

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import com.consol.citrus.endpoint.Endpoint;3import com.consol.citrus.message.Message;4import com.consol.citrus.testng.AbstractTestNGUnitTest;5import com.consol.citrus.ws.message.SoapMessage;6import org.mockito.Mockito;7import org.springframework.ws.soap.SoapMessageFactory;8import org.springframework.ws.soap.SoapVersion;9import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;10import org.testng.annotations.Test;11import static org.mockito.Mockito.*;12public class SoapMessageTest extends AbstractTestNGUnitTest {13 private SoapMessageFactory soapMessageFactory = Mockito.mock(SaajSoapMessageFactory.class);14 public void testMtomEnabled() throws Exception {15 SoapMessage soapMessage = new SoapMessage();16 soapMessage.setSoapMessageFactory(soapMessageFactory);17 when(soapMessageFactory.getSoapVersion()).thenReturn(SoapVersion.SOAP_11);18 soapMessage.mtomEnabled(true);19 verify(soapMessageFactory, times(1)).setMtomEnabled(true);20 soapMessage.mtomEnabled(false);21 verify(soapMessageFactory, times(1)).setMtomEnabled(false);22 }23}24package com.consol.citrus.ws;25import com.consol.citrus.endpoint.Endpoint;26import com.consol.citrus.message.Message;27import com.consol.citrus.testng.AbstractTestNGUnitTest;28import com.consol.citrus.ws.message.SoapMessage;29import org.mockito.Mockito;30import org.springframework.ws.soap.SoapMessageFactory;31import org.springframework.ws.soap.SoapVersion;32import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;33import org.testng.annotations.Test;34import static org.mockito.Mockito.*;35public class SoapMessageTest extends AbstractTestNGUnitTest {36 private SoapMessageFactory soapMessageFactory = Mockito.mock(SaajSoapMessageFactory.class);37 public void testMtomEnabled() throws Exception {38 SoapMessage soapMessage = new SoapMessage();39 soapMessage.setSoapMessageFactory(soapMessageFactory);40 when(soapMessageFactory.getSoapVersion()).thenReturn(SoapVersion.SOAP_11);41 soapMessage.mtomEnabled(true);42 verify(soapMessageFactory, times(1)).setMtomEnabled(true);

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.ws.soap.SoapMessage;3import org.springframework.ws.soap.SoapMessageFactory;4import org.springframework.ws.soap.SoapVersion;5import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;6import org.springframework.ws.soap.saaj.SaajSoapMessageUtils;7import org.springframework.ws.soap.saaj.SaajSoapVersion;8import javax.xml.soap.*;9import java.io.ByteArrayInputStream;10import java.io.IOException;11import java.io.InputStream;12import java.io.OutputStream;13import java.util.Iterator;14import java.util.Map;15public class SoapMessage extends org.springframework.ws.soap.saaj.SaajSoapMessage {16 public SoapMessage(SoapMessageFactory messageFactory, SOAPMessage saajSoapMessage) {17 super(messageFactory, saajSoapMessage);18 }19 public SoapMessage(SoapMessageFactory messageFactory, SOAPMessage saajSoapMessage, boolean mtomEnabled) {20 super(messageFactory, saajSoapMessage);21 SaajSoapMessageUtils.setMtomEnabled(saajSoapMessage, mtomEnabled);22 }23 public SoapMessage(SoapMessageFactory messageFactory, String payload) {24 super(messageFactory, payload);25 }26 public SoapMessage(SoapMessageFactory messageFactory, String payload, boolean mtomEnabled) {27 super(messageFactory, payload);28 SaajSoapMessageUtils.setMtomEnabled(getSaajMessage(), mtomEnabled);29 }

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.http.MediaType;4import org.springframework.http.converter.ByteArrayHttpMessageConverter;5import org.springframework.http.converter.HttpMessageConverter;6import org.testng.annotations.Test;7import java.util.ArrayList;8import java.util.List;9import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;10import static com.consol.citrus.actions.SendMessageAction.Builder.send;11public class 3 extends TestNGCitrusTestDesigner {12 public void 3() {13 variable("attachmentName", "test.txt");14 variable("attachmentData", "This is a test attachment");15 http(httpActionBuilder -> httpActionBuilder16 .client("httpClient")17 .send()18 .post()19 " <ns2:AttachmentName>${attachmentName}</ns2:AttachmentName>\n" +20 " <ns2:AttachmentData>${attachmentData}</ns2:AttachmentData>\n" +21 .contentType(MediaType.APPLICATION_XML_VALUE)

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1public class 3 extends TestCase {2 public void 3() {3 variable("msgId", "urn:uuid:123456789");4 variable("msgId2", "urn:uuid:123456789");5 variable("msgId3", "urn:uuid:123456789");6 variable("msgId4", "urn:uuid:123456789");7 variable("msgId5", "urn:uuid:123456789");8 variable("msgId6", "urn:uuid:123456789");9 variable("msgId7", "urn:uuid:123456789");10 variable("msgId8", "urn:uuid:123456789");11 variable("msgId9", "urn:uuid:123456789");12 variable("msgId10", "urn:uuid:123456789");13 variable("msgId11", "urn:uuid:123456789");14 variable("msgId12", "urn:uuid:123456789");15 variable("msgId13", "urn:uuid:123456789");16 variable("msgId14", "urn:uuid:123456789");17 variable("msgId15", "urn:uuid:123456789");18 variable("msgId16", "urn:uuid:123456789");19 variable("msgId17", "urn:uuid:123456789");20 variable("msgId18", "urn:uuid:123456789");21 variable("msgId19", "urn:uuid:123456789");22 variable("msgId20", "urn:uuid:123456789");23 variable("msgId21", "urn:uuid:123456789");24 variable("msgId22", "urn:uuid:123456789");25 variable("msgId23", "urn:uuid:123456789");26 variable("msgId24", "urn:uuid:123456789");27 variable("msgId25", "urn:uuid:123456789");28 variable("msgId26", "urn:uuid:123456789");29 variable("msgId27", "urn:uuid:123456789");30 variable("msgId28", "urn:uuid:123456789");31 variable("msgId29", "urn:uuid:123456789");32 variable("msgId30", "urn:uuid:123456789

Full Screen

Full Screen

mtomEnabled

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import com.consol.citrus.message.Message;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import org.springframework.ws.soap.SoapMessage;5import org.testng.Assert;6import org.testng.annotations.Test;7public class SoapMessageTest extends AbstractTestNGUnitTest {8 public void testMtomEnabled() {9 SoapMessage message = new SoapMessageFactory().createWebServiceMessage();10 Message soapMessage = new SoapMessage(message);11 soapMessage.setMtomEnabled(true);12 Assert.assertTrue(soapMessage.isMtomEnabled());13 soapMessage.setMtomEnabled(false);14 Assert.assertFalse(soapMessage.isMtomEnabled());15 }16}17package com.consol.citrus.ws.message;18import com.consol.citrus.message.Message;19import com.consol.citrus.testng.AbstractTestNGUnitTest;20import org.springframework.ws.soap.SoapMessage;21import org.testng.Assert;22import org.testng.annotations.Test;23public class SoapMessageTest extends AbstractTestNGUnitTest {24 public void testGetPayload() {25 SoapMessage message = new SoapMessageFactory().createWebServiceMessage();26 Message soapMessage = new SoapMessage(message);27 Assert.assertEquals(soapMessage.getPayload(), message.getPayloadSource());28 }29}30package com.consol.citrus.ws.message;31import com.consol.citrus.message.Message;32import com.consol.citrus.testng.AbstractTestNGUnitTest;33import org.springframework.ws.soap.SoapMessage;34import org.testng.Assert;35import org.testng.annotations.Test;36import javax.xml.transform.Source;37import javax.xml.transform.stream.StreamSource;38import java.io.StringReader;39public class SoapMessageTest extends AbstractTestNGUnitTest {40 public void testSetPayload() {

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