Pages

Tuesday, January 28, 2014

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed in Tomcat

Last week, I encountered a very weird error in my Email service application. The error was like this:
javax.mail.MessagingException: IOException while sending message;
  nested exception is:
 javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
 boundary="----=_Part_0_29947292.1390460403892"
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:625)

The issue is being encountered when the application is deployed in a separate Tomcat instance (not in the main server). What's weird is when I deploy it in the main instance's webapps or via Eclipse. There's no problem.

So, seems like activation.jar (it is a shared lib folder named endorsed) wasn’t able to locate the mail.jar file because they’re not in the same level when they were loaded by Tomcat (you know instance issues and stuff).

1) activiation.jar (exists in the endorsed folder)
2) mail.jar (exists in the applications’ lib folder)

So the easiest way to resolve this is put the mail.jar in the endorsed folder too.

However, we are just sharing an environment from the main instance (which is being used by other applications). Hence, for our case we can't just put it there. :( So I really got annoyed with the issue because I can't see any workaround anymore but luckily, after hours of checking and debugging, I finally found a way to resolve it. :)

So to fix the issue programmatically, you can configure your application's mailcap registry through MailcapCommandMap. I put this few lines before sending the message and it worked!
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
        mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
        mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");

You can check more about MailcapCommandMap here.

Monday, January 27, 2014

Birthday Getaway!

I just turned 26 yesterday and guess what I did? I went to Baguio City for a day trip all by myself! Talk about making some from your bucket list come true, this is indeed an achievement. :)

Can't really tell all the specifics of my trip but one great thing I did, I went to the Cemetery of Negativism at Camp John Hay and buried all the ill feelings I have (I guess and hoped). I had fun indeed. SOOOO MUCH! :)

Anyway, here's a picture of me at one of the tomb where a negative feeling was buried. Had a long and steep walk before reaching the place so I got plenty of exercise on my birthday. Hah!

Friday, August 31, 2012

Sending a HTTP request in Java SE

Here's an example on how to send a HTTP request in Java SE using the HttpURLConnection class. Basically, the sample code below will allow you to send a POST method request with 2 parameters.

URL siteUrl = new URL("http://www.youractionurl.com");
HttpURLConnection conn = (HttpURLConnection) siteUrl.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);

DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "param1=1234&param2=user1234";
out.writeBytes(content);
out.flush();
out.close();

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    while(in.readLine() != null) {
         System.out.println(in.readLine());
    }
in.close();

The HttpURLConnection class extends the URLConnection superclass & supports HTTP-specific features to provide a communication link between application and URL. You can just check the Java SE API for more information. :)

Thursday, December 22, 2011

Say Hello to Holga!

Yesterday, I got my very first lomo camera - the Holga 120N. Actually, I've been very fascinated with lomo pictures for quite some time. I find them cool! So after I finally learned about "Vignette", I decided to give lomography a try to make cool pictures myself... Wish me luck! :)


P.S.
I got my camera from Kara with 2 100F films. You can check her website! (http://www.lomolocoshop.com)

Price:
Holga 120N with Manual & Strap - P1,900
2 Provia 100F (Fujifilm) - P235/each

Friday, December 16, 2011

12.16.2011 is Apple Day!

Next Friday will definitely be an Apple Day here in the Philippines as two giant networks will simultaneously launch iPhone 4S as an addition to their postpaid handsets. Aside from the one doing it your way, the most amazing network is now in the picture. This will be, definitely, a war. :)

Thursday, December 8, 2011

Alone Time with Margarita


Margarita glass from Alley Gator.

I've been thinking of having a cocktail drink for some time and thought last night was the best time 'coz I had the "craving feeling". =) Actually, my initial plan was just --to have a single glass of margarita after my meal-- enough to satisfy my craving and go home. But I ended up ordering a pitcher and drink alone like a loner loser. Well, my abnormal decision was because of the Php100 price difference of a single glass shot versus their pitcher. For the single Margarita glass, they're offering it for Php120, their pitcher's price meanwhile was Php220. Pretty reasonable eh?

Anyway, sometimes its good for you to experience some alone stuff like this. Get some time to think, *reflect* & ETC... I had it last night and I enjoyed it! I did call some of my friends as well to catch some updates and found myself laughing over the phone. I want to try it again! :)

Thursday, October 20, 2011

The jaxws-maven-plugin

For sometime, I've been encountering an error in my JAX-WS application in Maven when deploying it to Websphere. The error occurs when your web service's return type is a List. Here's the exact error:

[javax.xml.bind.JAXBException: java.util.List is not known to this context]

Exporting the war file using IBM RAD will not let you encounter this problem. Unfortunately, RAD does not have a Maven plugin so we are using the native Eclipse IDE. So we've come up to a solution using the jaxws-maven-plugin to make sure the application will run properly in Websphere. Add this into your pom.xml :

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>2.2</version>
   <executions>
       <execution>
           <phase>generate-sources</phase>
           <goals>
               <goal>compile</goal>
           </goals>
      </execution>
   </executions>
   <configuration>
       <target>1.6</target>
       <source>1.6</source>
   </configuration>
</plugin>

<plugin>
    <groupid>org.codehaus.mojo</groupId>
    <artifactid>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsgen</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <destdir>src/main/java</destDir>     
        <sei>ph.com.src.endpoint.WsEndpoint</sei>     
        <keep>true</keep>      
        <verbose>true</verbose>
    </configuration>
</plugin>

The <sei> should be the location & name of your service endpoint interface. It will I think sort of override it so that no error will occur. :)