Thursday, October 25, 2012

#204 Calling a REST service from Fusion CRM

Building on the REST enabled Facebook service from the previous posts...

Now I want to call this from FCRM.
I apologise for the scenario, it may seem somewhat unrealistic, however it does illustrate the concepts.

In this scenario, I want to post comments regarding an opportunity to my Facebook page.
Please expand the picture to see the fields on the right.

I click on the link to call the REST service.

The link is defined as follows -

I constuct the url and include the Comments.

def myUrl = "http://myWLSHost/FacebookClient-RESTfulService-context-root/jersey/post2FB/postMsg2Page?msg=" + Comments
return (myUrl)

I then include the link in the Opportunities page.

The result -

Wednesday, October 24, 2012

#203 REST enabled my Facebook service running on WLS.

I am referring to the web service I created 2 posts back.
Now I would like the same functionality, albeit via REST.

So I created a new project in JDeveloper.

The implementation is as follows -

I deployed to the embedded WLS by simply running the above -

Test it out -

#202 ADF Mobile available

well worth looking into...

ADF Mobile

Tuesday, October 23, 2012

#201 Calling Facebook (restFB) from Weblogic

Scenario: I have a web service running on WLS that posts messages to a Facebook page.  
Part 1 - The Facebook Client

I use restFB here --> restFB  

The client code -

package fb;
import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.Parameter;
import com.restfb.types.Account;
import com.restfb.types.FacebookType;
import com.restfb.types.Page;
import com.restfb.types.Post;
import com.restfb.types.User;
import java.util.Arrays;
import java.util.List;

public class PostMsg2Page {
public PostMsg2Page() {

 public String post(String msg) {
String MY_ACCESS_TOKEN = "GetYourAccessToken as described in the restFB docs"; System.out.println("PostMsg2Page()");
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
System.out.println("PostMsg2Page() FB client got!");
User user = facebookClient.fetchObject("me", User.class);
System.out.println("User name: " + user.getName());

 // Add posts to a Page
DefaultFacebookClient fbClient;
Connection myAccounts; fbClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
myAccounts = fbClient.fetchConnection("me/accounts", Account.class);
System.out.println("MyAccounts size = " +myAccounts.getData().size());

Account myAccount = new Account();
   for (int i =0; i < myAccounts.getData().size(); i++){
       myAccount = (Account)myAccounts.getData().get(i);
       String accountName = myAccount.getName();
       System.out.println("Account name = " + accountName);

if (accountName.equalsIgnoreCase("NiallsTestPage")){
// get the page access token
String pageAccessToken = myAccount.getAccessToken();
fbClient = new DefaultFacebookClient(pageAccessToken);
System.out.println("About to post...");
fbClient.publish("me/feed", FacebookType.class, Parameter.with("message", msg));
 catch (Exception e){
return "success";

Here I essentially connect to my Facebook account.
I then browse thru my pages (accounts) until I find the one I want to post to.
This is, in my case, NiallsTestPage. I then do the necessary...

 Regarding the OAuth token -
Login to to get your own.
I test and see that all is working.
I then jar up this project and add it to my web service project.  

The Java web service is as follows -

WebService(endpointInterface = "fbws.ClientPortType")
@WLHttpTransport(serviceUri = "/ClientPort", portName = "ClientPort")
public class Client {
 public Client() {
 public String post2FB(String msg) {
     PostMsg2Page pm = new PostMsg2Page();;
     return "success";
 I deploy to WLS.

I now login to again,
this time just to save the Facebook cert locally. I then add this cert to my cacerts store

Note the location -
I re-start WLS and then test the web service -
I check the Facebook page -

Monday, October 15, 2012

#200 Fusion Apps: Getting user data via Groovy

Scenario: Accessing user data such as email via a Groovy script - Thanks to my colleague ChrisV for this - Here is the Groovy function to get the user data
Here I call it from an action (button)
Here I test
Now I go to em to check the logs -
Right click on Fram_CRMDomain --> logs then search for Notifications.