Thursday, November 5, 2009

Use mail transport in ESB to convert the SOAP message to a plain text mail

Scenario:
Imagine a scenario where you are using the mail transport in ESB. You need to convert the SOAP message to a plain text mail, without any XML in it. This blogpost is written to address it :).

How To:
Following steps will guide you to get your scenario up and running.

1) Uncomment the mail TransportSender and TransportReceiver from axis2.xml

2) Add the following line to axis2.xml's MessageFormatters.

<messageFormatter contentType="text/plain" class="org.apache.axis2.format.PlainTextFormatter"/>

3) Build the SimpleStockQuote service (which is residing inside the samples). Run sample axis2Server.

4) Use the attached proxy configuration.

<!-- Using the mail transport -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
<proxy name="StockQuoteProxy" transports="mailto">

<parameter name="transport.mail.Address">synapse.demo.1@gmail.com</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="mail.pop3.host">pop.gmail.com</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.user">synapse.demo.1</parameter>
<parameter name="mail.pop3.password">mailpassword</parameter>
<parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.ContentType">application/xml</parameter>

<target>
<inSequence>
<property name="senderAddress" expression="get-property('transport', 'From')"/>
<log level="full">
<property name="Sender Address" expression="get-property('senderAddress')"/>
</log>

<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="Subject" value="Custom Subject for Response" scope="transport"/>
<property name="messageType" value="text/plain" scope="axis2-client"/>
<script language="js"><![CDATA[
mc.setPayloadXML(<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">Plain text received!</ns:text>);
]]></script>
<header name="To" expression="fn:concat('mailto:', get-property('senderAddress'))"/>
<log level="full">
<property name="message" value="Response message"/>
<property name="Sender Address" expression="get-property('senderAddress')"/>
</log>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
</proxy>
</definitions>
5) Send an email to synapse.demo.1@gmail.com

6) You will receive the response in plain text.

Wednesday, October 21, 2009

Exposing a non-secured service with security using ESB

This article explains how to expose a non-secure service as a secured service using WSO2 ESB. The unsecured service is SimpleStockQuoteService. The strategy taken up is to secure SimpleStockQuoteService throught a secured proxy. A proxy service is written to enable username token authentication and logging of messages. Steps specified in the article demonstrates how to get this scenario up and running. [Read the full article for more info]

Sunday, October 11, 2009

My article on IBM Developer Works

It was one of my dreams to publish an article in IBM dW. Last week one of my articles got published in the IBM developerWorks. A special thank goes out to Chris Walden (Web Development Editor) of developerWorks who made this happen.

Saturday, October 3, 2009

Basketball @ WSO2 : How to Survive



It's been a while since I wrote a blogpost that relates to sports. Since annual basketball tournament at wso2 is coming up next week, I thought it would be the perfect time to write a blogpost on WSO2 basketball. The ideas & views expressed below can be a KnowledgeBase for anyone joining wso2 or newbie who wants to play basketball @ wso2.

Wso2 folks dont have a permanent basketball court to play basketball. Instead they have transformed the car park into a basketball court. It is car-park by day and basketball court by night. We have portable baskeball posts, so we move em to the car-park in the evening. The court is not having the ideal dimensions of a standard basketball court; it is due to the limited space available in the car park.

We started playing basketball @ wso2 around 1 year back and we followed it up with a inter-house basketball tournament, which was a blast. It was a very successful event and everyone enjoyed it a lot(apart from the people who got injured while playing lol). Now 1 year has elapsed since the introduction of basketball to wso2 and IMO I say that we are playing a different flavor of basketball.

Basketball is having several flavors ranging from Streetball to Slamball. Wso2's basketball has evolved into a unique flavor apart from these. I'd say it is a hybrid of both basketball and rugby :D. I'd like to call it RugBBall. Since I said that this would be a KB item, following are some tips to be successful(or survive lol) @ basketball court, during practice sessions.
  • You should be able to tolerate elbow shots and slaps, cos these arn't fouls :)
  • Dont ever argue with guys on "whether it was a foul or not". You could never win that argument :). Therefore it's better to carry on with the game without arguing.
  • After a practice session you'd feel like if you were scratched by a kitten and tackled by a NFL linebacker lol.
Those are the fun facts to know before you enter into the bb court.

I will follow this post up with a pre-tournament analysis of the wso2's inter-house basketball teams. So stay tuned ;) .

Thursday, September 10, 2009

Create ZIP archieve from multiple files

Following code snippet shows how to create a zip archieve from multiple files.

import java.util.zip.*;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.io.*;

public class ZipDemo {
static int BUFFER_SIZE = 1024;
static String zipArchieveName = "allfiles.zip";

public static void main(String args[]) {
try {
// Reference to the file we will be adding to the zipfile
BufferedInputStream origin = null;

// Reference to zip file
FileOutputStream dest = new FileOutputStream(zipArchieveName);

// Wrap our destination zipfile with a ZipOutputStream
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));

// Create a byte[] buffer that we will read data from the source
// files into and then transfer it to the zip file
byte[] data = new byte[BUFFER_SIZE];

List files = new ArrayList();
files.add("/tmp/systemInfo.txt");
files.add("/tmp/osgiInfo.txt");
files.add("/tmp/errorInfo.txt");

// Iterate over all of the files in list
for (Iterator i = files.iterator(); i.hasNext();) {
// Get a BufferedInputStream that we can use to read the source file
String filename = (String) i.next();
System.out.println("Adding: " + filename);
FileInputStream fi = new FileInputStream(filename);
origin = new BufferedInputStream(fi, BUFFER_SIZE);

// Setup the entry in the zip file
ZipEntry entry = new ZipEntry(filename);
out.putNextEntry(entry);

// Read data from the source file and write it out to the zip file
int count;
while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
out.write(data, 0, count);
}

// Close the source file
origin.close();
}

// Close the zip file
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Monday, August 31, 2009

How to add a Log4j Appender to WSO2 Carbon

1) Write a java class and extend AppenderSkeleton. Add the logic to the append(LoggingEvent e) method.
public class JiraAppender extends AppenderSkeleton {
protected void append(LoggingEvent loggingEvent) {
if (loggingEvent.getLevel().toString().equalsIgnoreCase("INFO")) {
System.out.println("INFO invoked!");
}
}

public boolean requiresLayout() {
return false;
}

public void close() {
}
}


2) Modify the log4j.properties file located at
/carbon-platform-2.0.1/carbondistribution/carbon-home/lib/log4j.properties 


a) Add the following entry to the log4j.properties file.
# CARBON_JIRA is set to be a MemoryAppender using a PatternLayout.
log4j.appender.CARBON_JIRA=org.wso2.carbon.utils.JiraAppender
log4j.appender.CARBON_JIRA.layout=org.apache.log4j.PatternLayout
log4j.appender.CARBON_JIRA.layout.ConversionPattern=[%d] %5p - %x %m%n
log4j.appender.CARBON_JIRA.threshold=DEBUG


b) Update the log4j.properties file with the following entry.
log4j.rootLogger=INFO, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, CARBON_SYS_LOG, CARBON_JIRA

log4j.logger.org.apache.axis2.wsdl.codegen.writer.PrettyPrinter=ERROR, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA
log4j.logger.org.apache.axis2.clustering=DEBUG, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_JIRA
log4j.logger.org.apache=INFO, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA
log4j.logger.org.apache.catalina=WARN
log4j.logger.org.apache.tiles=WARN
log4j.logger.org.apache.coyote=WARN
log4j.logger.org.hibernate=ERROR, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA
log4j.logger.org.mortbay=ERROR, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA
log4j.logger.net.sf=ERROR
log4j.logger.org.wso2=INFO
log4j.logger.org.apache.axis2.enterprise=FATAL, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA
log4j.logger.de.hunsicker.jalopy.io=FATAL, CARBON_LOGFILE, CARBON_MEMORY, CARBON_JIRA

Tuesday, August 25, 2009

WSO2 Carbon Articles

Following are a list of useful articles on WSO2 Carbon.

Getting Started with WSO2 Carbon

How Stuff Works – WSO2 Carbon