OIM Notification/ UMS EmailService API


  1. package com.oimacademy.personal;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import javax.activation.DataHandler;
  5. import javax.mail.MessagingException;
  6. import javax.mail.internet.MimeBodyPart;
  7. import javax.mail.internet.MimeMultipart;
  8. import javax.xml.ws.BindingProvider;
  9. import oracle.ucs.messaging.ws.ClientConstants;
  10. import oracle.ucs.messaging.ws.MessagingFactory;
  11. import oracle.ucs.messaging.ws.types.Message;
  12. import oracle.ucs.messaging.ws.types.DeliveryType;
  13. import oracle.ucs.messaging.ws.MessagingClient;
  14. import oracle.sdp.messaging.util.StringDataSource;
  15. import oracle.wsm.security.util.SecurityConstants;
  16. /*
  17.  <classpathentry kind="lib" path="D:/OIMAPIclients/ExternalJars/sdpmessagingcommon.jar"/>
  18.  <classpathentry kind="lib" path="D:/OIMAPIclients/ExternalJars/sdpmessagingclient.jar"/>
  19.   <classpathentry kind="lib" path="D:/OIMAPIclients/ExternalJars/wsclient_extended.jar"/>*/
  20. public class UMSEmailServiceTestUsingWS_URL {
  21.  public UMSEmailServiceTestUsingWS_URL() {
  22.   }
  23.  private static Map configureUMSClient() {
  24.   long lStartTime = System.currentTimeMillis();
  25.   Map config = new HashMap();
  26.   String ws_url = "http://localhost:8001/ucs/messaging/webservice";
  27.   config.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ws_url);
  28.   config.put(ClientConstants.POLICIES, new String[] {});
  29.   config.put(SecurityConstants.Config.CLIENT_CREDS_LOCATION,
  30.     SecurityConstants.Config.CLIENT_CREDS_LOC_SUBJECT);
  31.   long lEndTime = System.currentTimeMillis();
  32.   long difference = lEndTime - lStartTime;
  33.   System.out.println("Elapsed milliseconds in configureUMSClient: "+ difference);
  34.   return config;
  35.  }
  36.  private static void sendMessage(Message message, Map config) {
  37.   long lStartTime = System.currentTimeMillis();
  38.   MessagingClient mClient = null;
  39.   try {
  40.    mClient = new MessagingClient(config);
  41.   } catch (Throwable t) {
  42.    t.printStackTrace();
  43.   }
  44.   String id = null;
  45.   try {
  46.    id = mClient.send(message, null, null);
  47.    System.out.println("Message id: " + id);
  48.   } catch (Exception e) {
  49.    e.printStackTrace();
  50.   }
  51.   long lEndTime = System.currentTimeMillis();
  52.   long difference = lEndTime - lStartTime;
  53.   System.out.println("Elapsed milliseconds in sendMessage: " + difference);
  54.  }
  55.  public static void main(String[] args) {
  56.   long lStartTime = System.currentTimeMillis();
  57.   try {
  58.    Map config = configureUMSClient();
  59.    Message message = MessagingFactory.createMessage();
  60.    message.setSubject("UMS Test Client Subject");
  61.    String messageContent = "We are Testing UMS Test Client";
  62.    StringDataSource dataSource = new StringDataSource(messageContent, "text/html; charset=UTF-8");
  63.    MimeMultipart mp = new MimeMultipart("mixed");
  64.    MimeBodyPart mp_partRich = new MimeBodyPart();
  65.    try {
  66.     mp_partRich.setDataHandler(new DataHandler(dataSource));
  67.     mp.addBodyPart(mp_partRich);
  68.    } catch (MessagingException e) {
  69.     e.printStackTrace();
  70.    }
  71.    message.setContent(new DataHandler(mp, mp.getContentType()));
  72.    message.getRecipients().add( MessagingFactory.createAddress(DeliveryType.EMAIL + ":"+ "chvmadhusudhanrao@gmail.com"));
  73.    message.getSenders().add(MessagingFactory.createAddress(DeliveryType.EMAIL + ":"+ "chvmadhusudhanrao@gmail.com"));
  74.    message.getReplyTos().add(MessagingFactory.createAddress(DeliveryType.EMAIL + ":"+ "chvmadhusudhanrao@gmail.com"));
  75.    sendMessage(message, config);
  76.   } catch (Exception e) {
  77.    e.printStackTrace();
  78.   }
  79.   long lEndTime = System.currentTimeMillis();
  80.   long difference = lEndTime - lStartTime;
  81.   System.out.println("Elapsed milliseconds in main: " + difference);
  82.  }
  83. }

No comments:

Post a Comment