Sunday, 4 March 2007

Web Services with Java SE 6

One of the most interesting features of Java SE 6 is the new new end-to-end web services stack - JAXWS 2.0 FCS RI. The new runtime offers an embedded simple web server which can be used for deploying web services. Coupled with the embedded Derby DB JavaSE 6 become a complete platform.

Here is a simple example, lets start with a POJO annotated with @WebService annotation. This annotation tells JAXWS that its a Web Service endpoint. You may also annotate the methods that will be exposed as web services method with @WebMethod annotation. If all the methods will be exposed as web services method, it is not needed to annotate each method.

package com.muratyener;
import javax.jws.WebService;import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class Service {

@WebMethod
public String helloWorld(String message) {
return "Hello "+ message + "!!!";
}
public static void main(String[] args){
// create and publish an endpoint
Service service = new Service ();
Endpoint endpoint = Endpoint.publish(http://localhost:8080/service, service);
}

}

Well thats it, now we have to do two things to deploy our service.

To compile and generate wrapper classes;
apt -d sample com/muratyener/service.java

To publish the service;
java -cp sample com.muratyener.Service


Now, lets try accessing our deploed WSDL by typing http://localhost:8080/service?wsdl. JAXWS internally provides all the required stuff using light-weight HTTP server.
It is fast and simple, a very nice improvement.

Friday, 2 March 2007

Why Java Hosting is the most expensive solution?

I was looking for Java hosting and it is so disappointing that the cheapest Java hosting is at least $15 to $20 monthly where PHPor ASP hostings are available as low as $1.5 or $2 monthly.

If you google it you will find many reasons such as diffuculties of running multiple JVMs or running multiple hosting packages in one JVM... Well they may all be true but how will Java powered open source systems would run?

By the way while I was looking for java hosting I came across to http://www.myjavaserver.com/ . They offer free EE hosting but there is an interesting signup process. They give an online quiz in which a small piece of code is wanted. The code written is compiled instantly and the output is displayed. Well of cource I passed and to be honest it is not much hard but there was some small tricks which was fun to solve.