Cool Features of Web Services in the Java SE 6 Platform
I tried Java SE 6 webservices today by turning an existing class into webservice and it worked perfectly fine. I got it done both, manually and also using NetBeans 5.5. Watch out for annotation @WebService. If you selectively want to put methods as web services, you could as well use @WebMethod annotation. This is one cool feature thats coming in java se 6.
package generalproj;
import javax.jws.WebService;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import javax.xml.ws.Endpoint;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import javax.xml.ws.Endpoint;
@WebService
public class GeneralClass {
public GeneralClass() {
}
public void writeToFile( String a_file, String a_content ) {
if( a_file != null && a_content != null ) {
try {
FileOutputStream l_fos = new FileOutputStream( new File( a_file ));
byte[] l_bytes = a_content.getBytes();
l_fos.write( l_bytes, 0, l_bytes.length );
l_fos.close();
} catch( IOException iox ) {
iox.printStackTrace();
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Endpoint.publish(
"http://localhost:8077/generalproj/GeneralClass",
new GeneralClass());
public class GeneralClass {
public GeneralClass() {
}
public void writeToFile( String a_file, String a_content ) {
if( a_file != null && a_content != null ) {
try {
FileOutputStream l_fos = new FileOutputStream( new File( a_file ));
byte[] l_bytes = a_content.getBytes();
l_fos.write( l_bytes, 0, l_bytes.length );
l_fos.close();
} catch( IOException iox ) {
iox.printStackTrace();
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Endpoint.publish(
"http://localhost:8077/generalproj/GeneralClass",
new GeneralClass());
}
}
}
For reference, visit the webpage http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/
0 Comments:
Post a Comment
<< Home