How to use getMarshaller method of com.consol.citrus.mail.client.MailEndpointConfiguration class

Best Citrus code snippet using com.consol.citrus.mail.client.MailEndpointConfiguration.getMarshaller

Source:MailMessageConverter.java Github

copy

Full Screen

...106 * @return107 */108 protected MailMessage createMailRequest(Map<String, Object> messageHeaders, BodyPart bodyPart, MailEndpointConfiguration endpointConfiguration) {109 return MailMessage.request(messageHeaders)110 .marshaller(endpointConfiguration.getMarshaller())111 .from(messageHeaders.get(CitrusMailMessageHeaders.MAIL_FROM).toString())112 .to(messageHeaders.get(CitrusMailMessageHeaders.MAIL_TO).toString())113 .cc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_CC).toString())114 .bcc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_BCC).toString())115 .subject(messageHeaders.get(CitrusMailMessageHeaders.MAIL_SUBJECT).toString())116 .body(bodyPart);117 }118 /**119 * Reads basic message information such as sender, recipients and mail subject to message headers.120 * @param msg121 * @return122 */123 protected Map<String,Object> createMessageHeaders(MimeMailMessage msg) throws MessagingException, IOException {124 Map<String, Object> headers = new HashMap<>();125 headers.put(CitrusMailMessageHeaders.MAIL_MESSAGE_ID, msg.getMimeMessage().getMessageID());126 headers.put(CitrusMailMessageHeaders.MAIL_FROM, StringUtils.arrayToCommaDelimitedString(msg.getMimeMessage().getFrom()));127 headers.put(CitrusMailMessageHeaders.MAIL_TO, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(javax.mail.Message.RecipientType.TO))));128 headers.put(CitrusMailMessageHeaders.MAIL_CC, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(javax.mail.Message.RecipientType.CC))));129 headers.put(CitrusMailMessageHeaders.MAIL_BCC, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getRecipients(javax.mail.Message.RecipientType.BCC))));130 headers.put(CitrusMailMessageHeaders.MAIL_REPLY_TO, StringUtils.arrayToCommaDelimitedString((msg.getMimeMessage().getReplyTo())));131 headers.put(CitrusMailMessageHeaders.MAIL_DATE, msg.getMimeMessage().getSentDate() != null ? dateFormat.format(msg.getMimeMessage().getSentDate()) : null);132 headers.put(CitrusMailMessageHeaders.MAIL_SUBJECT, msg.getMimeMessage().getSubject());133 headers.put(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, parseContentType(msg.getMimeMessage().getContentType()));134 return headers;135 }136 /**137 * Process message part. Can be a text, binary or multipart instance.138 * @param part139 * @return140 * @throws java.io.IOException141 */142 protected BodyPart handlePart(MimePart part) throws IOException, MessagingException {143 String contentType = parseContentType(part.getContentType());144 if (part.isMimeType("multipart/*")) {145 return handleMultiPart((Multipart) part.getContent());146 } else if (part.isMimeType("text/*")) {147 return handleTextPart(part, contentType);148 } else if (part.isMimeType("image/*")) {149 return handleImageBinaryPart(part, contentType);150 } else if (part.isMimeType("application/*")) {151 return handleApplicationContentPart(part, contentType);152 } else {153 return handleBinaryPart(part, contentType);154 }155 }156 /**157 * Construct multipart body with first part being the body content and further parts being the attachments.158 * @param body159 * @return160 * @throws IOException161 */162 private BodyPart handleMultiPart(Multipart body) throws IOException, MessagingException {163 BodyPart bodyPart = null;164 for (int i = 0; i < body.getCount(); i++) {165 MimePart entity = (MimePart) body.getBodyPart(i);166 if (bodyPart == null) {167 bodyPart = handlePart(entity);168 } else {169 BodyPart attachment = handlePart(entity);170 bodyPart.addPart(new AttachmentPart(attachment.getContent(), parseContentType(attachment.getContentType()), entity.getFileName()));171 }172 }173 return bodyPart;174 }175 /**176 * Construct body part form special application data. Based on known application content types delegate to text,177 * image or binary body construction.178 * @param applicationData179 * @param contentType180 * @return181 * @throws IOException182 */183 protected BodyPart handleApplicationContentPart(MimePart applicationData, String contentType) throws IOException, MessagingException {184 if (applicationData.isMimeType("application/pdf")) {185 return handleImageBinaryPart(applicationData, contentType);186 } else if (applicationData.isMimeType("application/rtf")) {187 return handleImageBinaryPart(applicationData, contentType);188 } else if (applicationData.isMimeType("application/java")) {189 return handleTextPart(applicationData, contentType);190 } else if (applicationData.isMimeType("application/x-javascript")) {191 return handleTextPart(applicationData, contentType);192 } else if (applicationData.isMimeType("application/xhtml+xml")) {193 return handleTextPart(applicationData, contentType);194 } else if (applicationData.isMimeType("application/json")) {195 return handleTextPart(applicationData, contentType);196 } else if (applicationData.isMimeType("application/postscript")) {197 return handleTextPart(applicationData, contentType);198 } else {199 return handleBinaryPart(applicationData, contentType);200 }201 }202 /**203 * Construct base64 body part from image data.204 * @param image205 * @param contentType206 * @return207 * @throws IOException208 */209 protected BodyPart handleImageBinaryPart(MimePart image, String contentType) throws IOException, MessagingException {210 ByteArrayOutputStream bos = new ByteArrayOutputStream();211 FileCopyUtils.copy(image.getInputStream(), bos);212 String base64 = Base64.encodeBase64String(bos.toByteArray());213 return new BodyPart(base64, contentType);214 }215 /**216 * Construct simple body part from binary data just adding file name as content.217 * @param mediaPart218 * @param contentType219 * @return220 * @throws IOException221 */222 protected BodyPart handleBinaryPart(MimePart mediaPart, String contentType) throws IOException, MessagingException {223 String contentId = mediaPart.getContentID() != null ? "(" + mediaPart.getContentID() + ")" : "";224 return new BodyPart(mediaPart.getFileName() + contentId, contentType);225 }226 /**227 * Construct simple binary body part with base64 data.228 * @param textPart229 * @param contentType230 * @return231 * @throws IOException232 */233 protected BodyPart handleTextPart(MimePart textPart, String contentType) throws IOException, MessagingException {234 String content;235 if (textPart.getContent() instanceof String) {236 content = (String) textPart.getContent();237 } else if (textPart.getContent() instanceof InputStream) {238 content = FileUtils.readToString((InputStream) textPart.getContent(), Charset.forName(parseCharsetFromContentType(contentType)));239 } else {240 throw new CitrusRuntimeException("Cannot handle text content of type: " + textPart.getContent().getClass().toString());241 }242 return new BodyPart(stripMailBodyEnding(content), contentType);243 }244 /**245 * Removes SMTP mail body ending which is defined by single '.' character in separate line marking246 * the mail body end of file.247 * @param textBody248 * @return249 */250 private String stripMailBodyEnding(String textBody) throws IOException {251 BufferedReader reader = null;252 StringBuilder body = new StringBuilder();253 try {254 reader = new BufferedReader(new StringReader(textBody));255 String line = reader.readLine();256 while (line != null && !line.equals(".")) {257 body.append(line);258 body.append(System.getProperty("line.separator"));259 line = reader.readLine();260 }261 } finally {262 if (reader != null) {263 try {264 reader.close();265 } catch (IOException e) {266 log.warn("Failed to close reader", e);267 }268 }269 }270 return body.toString().trim();271 }272 /**273 * Reads Citrus internal mail message model object from message payload. Either payload is actually a mail message object or274 * XML payload String is unmarshalled to mail message object.275 *276 * @param message277 * @param endpointConfiguration278 * @return279 */280 private MailRequest getMailRequest(Message message, MailEndpointConfiguration endpointConfiguration) {281 Object payload = message.getPayload();282 MailRequest mailRequest = null;283 if (payload != null) {284 if (payload instanceof MailRequest) {285 mailRequest = (MailRequest) payload;286 } else {287 mailRequest = (MailRequest) endpointConfiguration.getMarshaller()288 .unmarshal(message.getPayload(Source.class));289 }290 }291 if (mailRequest == null) {292 throw new CitrusRuntimeException("Unable to create proper mail message from payload: " + payload);293 }294 return mailRequest;295 }296 /**297 * When content type has multiple lines this method just returns plain content type information in first line.298 * This is the case when multipart mixed content type has boundary information in next line.299 * @param contentType300 * @return301 * @throws IOException...

Full Screen

Full Screen

Source:MailServer.java Github

copy

Full Screen

...211 /**212 * Gets the mail message marshaller.213 * @return214 */215 public MailMarshaller getMarshaller() {216 return marshaller;217 }218 /**219 * Sets the mail message marshaller.220 * @param marshaller221 */222 public void setMarshaller(MailMarshaller marshaller) {223 this.marshaller = marshaller;224 }225 /**226 * Gets the Java mail properties.227 * @return228 */229 public Properties getJavaMailProperties() {...

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.mail.client;2import org.springframework.context.annotation.Bean;3import org.springframework.context.annotation.Configuration;4import org.springframework.mail.javamail.JavaMailSenderImpl;5import org.springframework.oxm.Marshaller;6import org.springframework.oxm.jaxb.Jaxb2Marshaller;7public class MailEndpointConfiguration {8 public JavaMailSenderImpl mailSender() {9 JavaMailSenderImpl mailSender = new JavaMailSenderImpl();10 mailSender.setPort(2525);11 return mailSender;12 }13 public Marshaller marshaller() {14 Jaxb2Marshaller marshaller = new Jaxb2Marshaller();15 marshaller.setPackagesToScan("com.consol.citrus.mail.model");16 return marshaller;17 }18}19package com.consol.citrus.mail.client;20import com.consol.citrus.dsl.endpoint.CitrusEndpoints;21import com.consol.citrus.mail.message.MailMessage;22import com.consol.citrus.mail.message.MailMessageHeaders;23import com.consol.citrus.message.MessageType;24import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;25import org.springframework.beans.factory.annotation.Autowired;26import org.springframework.core.io.ClassPathResource;27import org.springframework.oxm.Marshaller;28import org.testng.annotations.Test;29import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;30import static com.consol.citrus.actions.SendMessageAction.Builder.send;31public class MailJavaClientIT extends TestNGCitrusSpringSupport {32 private MailEndpointConfiguration mailEndpointConfiguration;33 public void testMailClient() {34 Marshaller marshaller = mailEndpointConfiguration.marshaller();35 send(CitrusEndpoints.mail()36 .client(mailClient)37 .endpointConfiguration(mailEndpointConfiguration)38 .marshaller(marshaller)39 .message(MailMessage.plainText()40 .from("citrus@localhost")41 .to("citrus@localhost")42 .subject("Hello World")43 .body("Hello Citrus!")));44 receive(CitrusEndpoints.mail()45 .client(mailClient)46 .endpointConfiguration(mailEndpointConfiguration)47 .marshaller(marshaller)48 .message(MailMessage.plainText()

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.mail.client;2import java.util.HashMap;3import java.util.Map;4import org.springframework.oxm.jaxb.Jaxb2Marshaller;5public class getMarshaller {6 public static void main(String[] args) {7 MailEndpointConfiguration mailEndpointConfiguration = new MailEndpointConfiguration();8 Map<String, Object> map = new HashMap<String, Object>();9 map.put("com.consol.citrus.mail.model", "com.consol.citrus.mail.model");10 mailEndpointConfiguration.setMarshaller(getMarshaller(map));11 }12 public static Jaxb2Marshaller getMarshaller(Map<String, Object> map) {13 Jaxb2Marshaller marshaller = new Jaxb2Marshaller();14 marshaller.setContextPaths(map);15 return marshaller;16 }17}18package com.consol.citrus.mail.client;19import java.util.HashMap;20import java.util.Map;21import org.springframework.oxm.jaxb.Jaxb2Marshaller;22public class getUnmarshaller {23 public static void main(String[] args) {24 MailEndpointConfiguration mailEndpointConfiguration = new MailEndpointConfiguration();25 Map<String, Object> map = new HashMap<String, Object>();26 map.put("com.consol.citrus.mail.model", "com.consol.citrus.mail.model");27 mailEndpointConfiguration.setUnmarshaller(getUnmarshaller(map));28 }29 public static Jaxb2Marshaller getUnmarshaller(Map<String, Object> map) {30 Jaxb2Marshaller marshaller = new Jaxb2Marshaller();31 marshaller.setContextPaths(map);32 return marshaller;33 }34}35package com.consol.citrus.mail.client;36import java.util.Properties;37import org.springframework.mail.javamail.JavaMailSenderImpl;38public class getMailSender {39 public static void main(String[] args) {40 MailEndpointConfiguration mailEndpointConfiguration = new MailEndpointConfiguration();

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.mail.client;2import com.consol.citrus.mail.message.MailMarshaller;3import com.consol.citrus.mail.message.MailMessage;4import org.springframework.mail.javamail.JavaMailSender;5import org.springframework.mail.javamail.MimeMessageHelper;6import javax.mail.MessagingException;7import javax.mail.internet.MimeMessage;8public class MailEndpointConfiguration {9 private JavaMailSender mailSender;10 private MailMarshaller marshaller;11 public MailEndpointConfiguration() {12 }13 public MailEndpointConfiguration(JavaMailSender mailSender) {14 this.mailSender = mailSender;15 }16 public MimeMessage createMimeMessage() {17 return mailSender.createMimeMessage();18 }19 public void sendMailMessage(MimeMessage mailMessage) {20 mailSender.send(mailMessage);21 }22 public MimeMessage createMimeMessage(MailMessage mailMessage) throws MessagingException {23 MimeMessage mimeMessage = createMimeMessage();24 MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);25 messageHelper.setFrom(mailMessage.getFrom());26 messageHelper.setTo(mailMessage.getTo());27 messageHelper.setCc(mailMessage.getCc());28 messageHelper.setBcc(mailMessage.getBcc());29 messageHelper.setSubject(mailMessage.getSubject());30 messageHelper.setText(mailMessage.getContent());31 return mimeMessage;32 }33 public JavaMailSender getMailSender() {34 return mailSender;35 }36 public void setMailSender(JavaMailSender mailSender) {37 this.mailSender = mailSender;38 }

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.mail.client;2import javax.xml.bind.Marshaller;3import org.springframework.context.ApplicationContext;4import org.springframework.context.support.ClassPathXmlApplicationContext;5public class getMarshaller {6 public static void main(String[] args) {7 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");8 MailEndpointConfiguration mailEndpointConfiguration = (MailEndpointConfiguration) context.getBean("mailEndpointConfiguration");9 Marshaller marshaller = mailEndpointConfiguration.getMarshaller();10 System.out.println(marshaller);11 }12}

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1public void test() {2      MailEndpointConfiguration config = new MailEndpointConfiguration();3      config.setHost("localhost");4      config.setPort(25);5      config.setProtocol("smtp");6      config.setUsername("user");7      config.setPassword("pass");8      config.setMarshaller(getMarshaller());9      config.setUnmarshaller(getMarshaller());10      config.setJavaMailProperties(new Properties());11      config.setSocketFactoryClass("javax.net.ssl.SSLSocketFactory");12      config.setSocketFactoryFallback(false);13      config.setSocketFactoryPort(465);14      config.setStartTlsEnabled(true);15      config.setStartTlsRequired(false);16      config.setTrustStore("truststore");17      config.setTrustStorePassword("password");18      config.setTrustStoreType("JKS");19      config.setValidateServerIdentity(false);

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1public void test() {2 MailEndpointConfiguration mailEndpointConfiguration = new MailEndpointConfiguration();3 mailEndpointConfiguration.setJavaMailProperties(javaMailProperties);4 mailEndpointConfiguration.setMarshaller(marshaller);5 mailEndpointConfiguration.setMailSession(mailSession);6 mailEndpointConfiguration.setMarshallingStrategy(marshallingStrategy);7 mailEndpointConfiguration.setJavaMailSender(javaMailSender);8 mailEndpointConfiguration.setHost("localhost");9 mailEndpointConfiguration.setPort(25);10 mailEndpointConfiguration.setUsername("username");11 mailEndpointConfiguration.setPassword("password");12 mailEndpointConfiguration.setProtocol("smtp");13 mailEndpointConfiguration.setJavaMailProperties(javaMailProperties);14 mailEndpointConfiguration.setMarshaller(marshaller);15 mailEndpointConfiguration.setMarshallingStrategy(marshallingStrategy);16 mailEndpointConfiguration.setJavaMailSender(javaMailSender);17 mailEndpointConfiguration.setMailSession(mailSession);18 mailEndpointConfiguration.setHost("localhost");19 mailEndpointConfiguration.setPort(25);20 mailEndpointConfiguration.setUsername("username");21 mailEndpointConfiguration.setPassword("password");22 mailEndpointConfiguration.setProtocol("smtp");23 mailEndpointConfiguration.setJavaMailProperties(javaMailProperties);24 mailEndpointConfiguration.setMarshaller(marshaller);25 mailEndpointConfiguration.setMarshallingStrategy(marshallingStrategy);26 mailEndpointConfiguration.setJavaMailSender(javaMailSender);27 mailEndpointConfiguration.setMailSession(mailSession);28 mailEndpointConfiguration.setHost("localhost");29 mailEndpointConfiguration.setPort(25);30 mailEndpointConfiguration.setUsername("username");31 mailEndpointConfiguration.setPassword("password");32 mailEndpointConfiguration.setProtocol("smtp");33 mailEndpointConfiguration.setJavaMailProperties(javaMailProperties);34 mailEndpointConfiguration.setMarshaller(marshaller);35 mailEndpointConfiguration.setMarshallingStrategy(marshallingStrategy);36 mailEndpointConfiguration.setJavaMailSender(javaMailSender);37 mailEndpointConfiguration.setMailSession(mailSession);38 mailEndpointConfiguration.setHost("localhost");39 mailEndpointConfiguration.setPort(25);40 mailEndpointConfiguration.setUsername("username");41 mailEndpointConfiguration.setPassword("password");42 mailEndpointConfiguration.setProtocol("smtp");43 mailEndpointConfiguration.setJavaMailProperties(javaMailProperties);44 mailEndpointConfiguration.setMarshaller(marshaller);45 mailEndpointConfiguration.setMarshallingStrategy(marshallingStrategy);46 mailEndpointConfiguration.setJavaMailSender(javaMailSender);47 mailEndpointConfiguration.setMailSession(mailSession);48 mailEndpointConfiguration.setHost("localhost

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.mail.client;2import com.consol.citrus.mail.message.MailMessage;3import com.consol.citrus.marshaller.Marshaller;4import com.consol.citrus.message.Message;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.util.FileUtils;7import com.consol.citrus.xml.XsdSchemaRepository;8import com.consol.citrus.xml.namespace.NamespaceContextBuilder;9import com.consol.citrus.xml.namespace.SimpleNamespaceContextBuilder;10import org.springframework.oxm.Marshaller;11import org.springframework.oxm.jaxb.Jaxb2Marshaller;12import org.springframework.xml.transform.StringResult;13import org.springframework.xml.transform.StringSource;14import org.xml.sax.SAXException;15import javax.mail.MessagingException;16import javax.mail.internet.MimeMessage;17import javax.mail.util.ByteArrayDataSource;18import javax.xml.transform.*;19import javax.xml.transform.stream.StreamResult;20import javax.xml.transform.stream.StreamSource;21import java.io.ByteArrayInputStream;22import java.io.ByteArrayOutputStream;23import java.io.IOException;24import java.io.InputStream;25import java.nio.charset.Charset;26import java.util.Collections;27import java.util.Map;28public class MailEndpointConfiguration {29 private Marshaller marshaller;30 private String marshallerName;31 private String encoding = "UTF-8";32 private String contentType = "text/xml";33 private String schemaValidationEnabled = "false";34 private String schemaRepository;35 private String namespaceContextBuilder;36 private String schemaValidationErrorHandler;37 private String schemaValidationWarnOnErrors = "false";38 private Map<String, String> namespaces = Collections.emptyMap();39 public Marshaller getMarshaller() {40 return marshaller;41 }42 public void setMarshaller(Marshaller marshaller) {43 this.marshaller = marshaller;44 }45 public void setMarshallerName(String marshallerName) {46 this.marshallerName = marshallerName;47 }48 public String getMarshallerName() {49 return marshallerName;50 }51 public void setEncoding(String encoding) {52 this.encoding = encoding;53 }54 public String getEncoding() {55 return encoding;56 }57 public void setContentType(String contentType) {58 this.contentType = contentType;59 }60 public String getContentType() {

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