Archive

Archives pour 04/2009

Just testing the Google App Engine Java Version

23/04/2009

Just tested the Google App Engine Java version and its Eclipse plugin, really amazing. The sample application is deployed from Eclipse and is running at http://hamerlingchristophe.appspot.com/

I think that I will try to do some things related to SOA and PEtALS on this platform, just need time…

Google ,

Google Data API presentation

23/04/2009

A quick entry on a really good presentation of the Google Data API, simple and interesting…

http://www.infoq.com/presentations/google-data-api-gdata

Frank Mantek discusses the Google Data API (GData) including decisions to use REST rather than SOAP technology, how the API is used, numerous examples of how GData has been used by clients, and future plans for evolving the API. A discussion of how GData facilitates Cloud Computing concludes the presentation.

Google ,

Developing under Mac OS X : The keyboard…

16/04/2009

Mac OS X is cool but where are my special characters I need while developing??? Here are some keys combinations which are (quite) useful :

  • | is under OPTION+SHIFT+L
  • { is under OPTION+( and } is under OPTION+)
  • [ is under OPTION+( and ] is under OPTION+)
  • \ is under OPTION+SHIFT+/
Should be easier now…

Non classé

Apache CXF Clients : null result when using bad client factory

09/04/2009

Just a quick note to show that the client factory choice is important with Apache CXF 2.1.4.

The service interface definition :

package org.ow2.petals.usecase.soapaddressing.server;
 
import javax.jws.WebMethod;
import javax.jws.WebService;
 
/**
 * @author chamerling - eBM WebSourcing
 *
 */
@WebService
public interface AddressingService {
 
    /**
     * Get the local information
     * 
     * @return
     */
    @WebMethod
    String getInfo();
 
}

The client with the bad client factory :

package org.ow2.petals.usecase.soapaddressing.client;
 
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.ow2.petals.usecase.soapaddressing.server.AddressingService;
 
/**
 * @author chamerling - eBM WebSourcing
 *
 */
public class BadFactory {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
        factory.setServiceClass(AddressingService.class);
        factory.setAddress("http://localhost:8084/petals/services/Service01");
        AddressingService client = (AddressingService) factory.create();
        String info = client.getInfo();
        System.out.println(info);
    }
}

With that client code, the Web Service is really invoked, but the result of the getInfo operation is null. So, let’s do it with the right client factory…

The client with the good client factory :

package org.ow2.petals.usecase.soapaddressing.client;
 
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.ow2.petals.usecase.soapaddressing.server.AddressingService;
 
/**
 * @author chamerling - eBM WebSourcing
 *
 */
public class GoodFactory {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(AddressingService.class);
        factory.setAddress("http://localhost:8084/petals/services/Service01");
        AddressingService client = (AddressingService) factory.create();
        String info = client.getInfo();
        System.out.println(info);
    }
}

This time the result is not null and is really the one expected…

WebService , ,

JSR181 Servive Engine sample : Talk to Twitter

01/04/2009

Just for fun…

The current article will show you that the JSR181 Service Engine really provides an easy way to create JBI services. Since creating simple HelloWorld service is quite boring, let’s talk to twitter micro blogging site.

I will use the Twitter4J API () to talk to Twitter (right all the Twitter job is done here… The current article is not a Twitter tutorial but just a small PEtALS one…).

Interface definition

package net.chamerling.petals.twitter;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
/**
 * @author chamerling
 *
 */
@WebService
public interface TwitterService {
 
	@WebMethod
	public String update(@WebParam(name = "id") String login,
			@WebParam(name = "password") String password,
			@WebParam(name = "status") String status) throws TwitterServiceException;
 
	@WebMethod
	public String[] getTimeLine(@WebParam(name = "id") String login,
			@WebParam(name = "password") String password,
			@WebParam(name = "user") String user) throws TwitterServiceException;
}

Implementation (quick)

package net.chamerling.petals.twitter;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
 
/**
 * @author chamerling
 *
 */
@WebService(serviceName = "TwitterService", name = "TwitterService", targetNamespace = "http://twitter.chamerling.net/petals")
public class TwitterServiceImpl implements TwitterService {
 
	/*
	 * (non-Javadoc)
	 * @see net.chamerling.petals.twitter.TwitterService#update(java.lang.String, java.lang.String, java.lang.String)
	 */
	@WebMethod
	public String update(@WebParam(name = "id") String login,
			@WebParam(name = "password") String password,
			@WebParam(name = "status") String status) throws TwitterServiceException {
		String result = null;
		try {
			Status s = getTwitter(login, password).update(status);
			result = s.getText();
		} catch (twitter4j.TwitterException e) {
			throw new TwitterServiceException(e.getMessage());
		}
		return result;
	}
 
	/*
	 * (non-Javadoc)
	 * @see net.chamerling.petals.twitter.TwitterService#getTimeLine(java.lang.String, java.lang.String, java.lang.String)
	 */
	@WebMethod
	public String[] getTimeLine(@WebParam(name = "id") String login,
			@WebParam(name = "password") String password,
			@WebParam(name = "user") String user) throws TwitterServiceException {
		Twitter twitter = getTwitter(login, password);
		List result = new ArrayList();
		List status = null;
		try {
			if (user == null) {
				status = twitter.getUserTimeline();
			} else {
				status = twitter.getUserTimeline(user);
			}
		} catch (TwitterException e) {
			throw new TwitterServiceException(e.getMessage());
		}
 
		for (Status status2 : status) {
			result.add(status2.getText());
		}
 
		return result.toArray(new String[0]);
	}
 
	/**
	 * TODO : Some work to do for caching...
	 * 
	 * @param login
	 * @param password
	 * @return
	 */
	private Twitter getTwitter(String login, String password) {
		return new Twitter(login, password);
	}
}

Put all of this in a JSR181 Service Unit, ie create the good Service Unit descriptor (cf to source attchment), package it (use PEtALS Maven plugin) and that’s all. JSR181 makes it easy ;o)

So now you can publish some status to Twitter with PEtALS.
I have created a test acount here http://twitter.com/chamerlingtest on which I have published messages with PEtALS.

Service Unit sources are available here : http://dl.getdropbox.com/u/73785/blog/twitter-jsr181.zip

PEtALS, SOCIAL , ,