Friday, July 16, 2010

Add Hibernate Tool For Eclipse

1)First make sure the Eclipse version you are using

2)Downlaod eclipseplugin-hibernate_tools-3.3.1.GA-src
from http://jboss.org/tools/download/stable/3_1_GA.html as shown below





3)Extract it and copy 1)Content from features to Eclipse features folder
2)Content from plugins to Eclipse plugin folder
4)Restart or Open the Eclipse Ide

Tuesday, April 13, 2010

Webservice in java using Eclipse

1) First create a client project and make sure that you have following jars in your client project and server Project
activation.jar
axis-1.4.jar
commons-collections-3.1.jar
commons-discovery-0.2.jar
commons-io-1.3.1.jar
commons-logging.jar
jaxrpc.jar
mail.jar
saaj.jar
utility.jar
webserviceutils.jar
wsdl4j-1.5.1.jar
xercesImpl.jar
xmlsec.jar
2) create class that invokes and call the webservice in Client project
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
public class Client {
public static void main(String[] args) {
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setOperationName(new QName(endpoint, "addtwonumbers"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
System.out.println("In the Try"+call);
Integer ret = (Integer) call.invoke(new Object[] {
new Integer(10), new Integer(11) });
System.out.println("addInt(5, 7) = " + ret);
} catch (Exception e) {
System.err.println("Execution failed. Exception: " + e);
e.printStackTrace(); }
}
}
3) Create Destined project to be webserviced
public class AddFunction {
public int addInt(int a, int b){
return (a+b);
}}
4)Copy the AddFunction Class and Rename with (.jws) extention
5)Right click onthe AddFunction class ->New->others->Webservices->wsdl
6) change the soap address in wsdl as below
"http://localhost:8080/serverProject/services/AddFunction"
7) Deploy the server project in required server




Thursday, March 25, 2010

Twitter java to send message (or) feed wall

Twitter setup is pretty simple compare to Facebook .Facebook need server to connect or send messages to wall .Twitter can be connected by using Standalone

First download the Twitter4j API and Sample codes from below link :

click here

Sample code as below:

Twitter twitter = new TwitterFactory().getInstance(twitterID,twitterPassword);
Status status = twitter.updateStatus(latestStatus);
System.out.println("Successfully updated the status to [" + status.getText() + "].");

Facebook java Example to send message (or) Feed to wall

First download the Facebook Api :
Clickhere

and copy the lib to your project lib

Click on the below link for basic setup with Facebook:
Click here

After that use this below example to Test the message:

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import com.google.code.facebookapi.FacebookException;
import com.google.code.facebookapi.FacebookJsonRestClient;

/**
* Servlet implementation class Test
*/
public class Test extends HttpServlet {
String FB_APP_API_KEY = new String("your APIKEY");
String FB_APP_SECRET = new String("Your secret");
String FB_SESSION_KEY = new String("your session");

private static final long serialVersionUID = 1L;


/**
* @see HttpServlet#HttpServlet()
*/
public Test() {

super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
FacebookJsonRestClient facebook = new FacebookJsonRestClient(
FB_APP_API_KEY, FB_APP_SECRET, FB_SESSION_KEY);

// FacebookJsonRestClient facebookClient2 =
// (FacebookJsonRestClient)facebook.getFacebookRestClient();
FacebookJsonRestClient facebookClient = (FacebookJsonRestClient) facebook;
try {
facebookClient.stream_publish("Sample Message From:java App2", null, null, null, null);
} catch (FacebookException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
JSONArray response1 = (JSONArray)facebook.friends_get();
System.out.println("Friends->"+response1);
} catch (FacebookException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("successfully updated");

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

use the Following url to get session using your API KEY:

http://www.facebook.com/login.php?api_key=YOURAPIKEY&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access