Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create a multichannel composite portlet application using Rational Application Developer 8.0.4: Part 3. Displaying data from Microsoft SharePoint in a portlet

Gaurav Bhattacharjee, Technical Lead, Rational Application Developer Portal Tools, IBM
Gaurav Bhattacharjee 照片
Gaurav Bhattacharjee is a technical lead in the IBM India Software Labs in Delhi, India. He works with the Rational Application Developer Portal Tooling team in the IBM Software Group, IBM Collaboration Solutions.

Summary:  Multichannel portlet applications present appropriate views when run from different devices. This means that when you view it from a desktop browser, the portlet presents the desktop version. Similarly, when you view it from a smart phone, you see the mobile version of the portlet. Part 3 of this five-part series shows you how to use IBM Rational Application Developer, Version 8.0.4 or later, to fetch and display data from Microsoft SharePoint in a portlet.

View more content in this series

Date:  14 Feb 2012
Level:  Intermediate PDF:  A4 and Letter (941KB | 19 pages)Get Adobe® Reader®
Also available in:   Chinese

Activity:  11232 views
Comments:  

Now that you have seen how to fetch and display data from database tables using Service Data Objects (SDOs), let's concentrate on integrating with other data sources. In this part, you will enable the portlet application to fetch data from a Microsoft SharePoint server. SharePoint exposes different web services for working with a lot of its features. Here is a list of web services exposed by SharePoint (see the Resources section here for a link). By using these web services, you can generate skeleton code in IBM® Rational® Application Developer.


Before starting with this section, please see the Setup section in Part 1.

Enable portlets to fetch SharePoint data

In this section, you will enable portlets to fetch data from SharePoint server.

Important:
Before starting with this section, be sure to review the Prerequisite and the Setup sections in Part 1 (see "More content in this series").

Here is a brief summary of things that you will do to use data from SharePoint:

  1. Generate skeleton code in Rational Application Developer by using SharePoint exposed web services with the Java API for XML web Services (JAX-WS) tool in Rational Application Developer.
  2. Write business logic on top of the skeleton code to appropriately use data from SharePoint.
  3. Use the business logic to fetch and show data from SharePoint document libraries. The data fetched will be used and rendered by the portlet in a portal page.

Generate skeleton code from SharePoint web services

To generate skeleton code from SharePoint web services, follow these steps:

  1. Create a new Java project in the workspace, and name it SharePointProject, as shown in Figure 1.

Figure 1. Java project
New java project in workspace

  1. Select Windows > Show View > Other > Services to open the Services view shown in Figure 2.

Figure 2. Services view
JAX-WS option selected in Services ta

  1. Right-click on JAX-WS under the Services tab, and select the Create Client option (Figure 3) to open the Web Service Client wizard shown in Figure 4.

Figure 3. Services tab
Create Client selected on the drop-down menu


Figure 4. Web Service Client wizard
Screen to select a service definition

  1. Under the Configuration section in the Web Service Client wizard, for Server Runtime, click the WebSphere Application Server v8.0 link to launch the Client Environment Configuration window so that you can choose IBM® WebSphere® Portal v7.0 Server, instead, as shown in Figure 5.
    Note:
    WebSphere Application Server v8.0, in Figure 5, would be available only if you would have chosen to install it as one of the run-time servers during Rational Application Developer installation.

Figure 5. Client Environment Configuration window
WebSphere Portal v7.0 selected

  1. Similarly, change the client project to SharePointProject, which was created in step 1, so that the Web Service Client window looks like Figure 6.

Figure 6. Web Services dialog window
Configuration list shows SharePointProject

  1. Click the Browse button to launch the Select Service Implementation window that Figure 7 shows.
  2. Enter the URL of the Lists web services provided by SharePoint and, if necessary, expand to the third level, as shown in Figure 7.
    Note:
    You will also be prompted to enter the SharePoint-specific username and password the first time that you connect to a particular web service.

Figure 7. Service Implementation window
Specify the WDL URL

  1. Click OK to return to the Web Service Client wizard.
  2. Click Next.
  3. Click Finish.

After clicking Finish, notice that the skeleton code is generated in the src folder of SharePointProject project, as shown in Figure 8.


Figure 8. Generated skeleton code files
Contents of src folder

  1. For this tutorial, use the ListsSoap.java interface that was created by the JAX-WS tool from the Lists web service.

Write custom code for SharePoint

Now that you have generated the skeletal code, it's time to write the business logic on top of the skeletal code. The whole code for the achieving this is also packaged in the sample with this tutorial. The code has the logic to fetch the contents from a SharePoint document or picture library that you created in the setup section. In this section let's take a look upon the relevant code snippets.

Authenticate through the SharePoint server

Before you can fetch the contents from a relevant document or picture library, you'll need to authenticate with the SharePoint server. This is achieved through the code for your business logic. This code would make use of the skeletal code to connect and authenticate through SharePoint server. Listing 1 shows how to authenticate with the SharePoint server.


Listing 1. Authenticating with the SharePoint server
     public static ListsSoap authenticateForList(String spUserId, 
                String spPassword, String spWebServiceUrl) {
     ListsSoap listSoapPort = null;
		Map<String,String> authenticationParameters = new  
            HashMap<String,String>();
		authenticationParameters.put(userId, spUserId);
		authenticationParameters.put(password, spPassword);
		authenticationParameters.put(webServiceUrl,spWebServiceUrl);

		if (spUserId != null && spPassword != null && 
                spWebServiceUrl != null) {
	         
        Lists listService = new Lists();
		   listSoapPort = listService.getListsSoap12();
		   
        Map<String,Object> requestContext =  
          ((BindingProvider)listSoapPort).getRequestContext();
		   
        requestContext.put(webserviceUrl, spWebServiceUrl);
		   requestContext.put(webServiceUserName, spUserId);
		   requestContext.put(webServiceUserPassword, spPassword);

		} 
		return listSoapPort;
	}

In this code listing, using the SOAP port for the lists service, the context of the SharePoint server is obtained and appropriate parameters such as the web service to be invoked (in this case, Lists web service), username, and password of the SharePoint site is passed on to the context. This is enough to authenticate through the SharePoint server.

Note:
As indicated in the setup section in Part 1, this tutorial is based on the assumption that your authentication type is set to BASIC for the IIS server on which the SharePoint server is installed.

Retrieve contents from a document or picture library

Now that you have authenticated through the SharePoint server, the next step is to connect and retrieve contents from a library. Listing 2 shows how to do that. In this example, you will retrieve only the contents of a document library. The contents of a picture library can be retrieved in a similar manner.


Listing 2. Connect and retrieve contents from the SharePoint library
     GetListItemsResponse.GetListItemsResult resultantList =   
     listSoapPort.getListItems(listToBeRetreived, view, CAMLQuery,   
     fieldsToBeViewed, noOfRows, options, web_id);

In the code in Listing 2, the getListItems method queries the SharePoint server for a document or a picture library. The listToBeRetreived parameter specifies the name of the document or the picture library, the contents of which you want to retrieve. Some of the other parameters include a CAMLQuery which is equivalent of a SQL query, as well as the fields or columns that you want to retrieve from the library.

After you have the result of the method call stored in the resultantList variable, you can use the code in Listing 3 to get an instance of the library as an object. Then you can use that object to retrieve the desired content.


Listing 3. Code to get an instance of the SharePoint library as an object
     Object resultObj = resultantList.getContent().get(0);
   
     if ((resultObj != null) && 
      (resultObj instanceof ElementNSImpl)) 
     {
      ElementNSImpl node = (ElementNSImpl) resultObj;

      NodeList list = node.getElementsByTagName(row);

      MyBean myBean = null;
     
      int i = 0;
      
      while(i < list.getLength()){
   	NamedNodeMap attributes = list.item(i).getAttributes();
	String id = attributes.getNamedItem("ows_ID").getNodeValue();
        String name = attributes.getNamedItem 
                     ("ows_NameOrTitle").getNodeValue();
        myBean = new MyBean();
        myBean.setId(id);
        myBean.setName(name);  
        ...........................................................
        ...........................................................
        ...........................................................

        i++
       }// end of while
     }//end of if

In the code in Listing 3, the resultObj object represents an instance of a row in a document or a picture library in SharePoint. As you can see in the Listing 3, the id and name variables contain the ID and title of a row present in a SharePoint library.

The full code for Listing 1, 2, and 3 is inside the SharePointIntegrationManager class within the SharePointProject in the attached sample (see Downloads). You can simply copy the contents of these classes into your own custom classes.

Write a utility class to fetch a URL for a document

You can use the code in Listing 4 to fetch the URL pointing to a document in a document library.


Listing 4. Fetch the URL that points to the document in the library
public String getUrl(String companyName){
    List<MyBean> myList=null;
	  try {
		  ListsSoap listSoapPort = (ListsSoap)
       SharePointIntegrationManager.authenticateForList 
       (this.userName, this.password, this.spwebServiceUrl);

		  myList = SharePointIntegrationManager.sharePointList
              (listSoapPort, companyName, null, this.rowLimit);

		   } catch (Exception e) {

		     }
     MyBean bean = myList.get(0);
     String docUrl = bean.getFileRef();
     docUrl = docUrl.replace(" ", "%20");

     if(docUrl!=null){
        	return docUrl;
         }
		return null;
	}

Note:
The getUrl and getPicUrl methods fetch a document and a picture URL from the respective libraries.

The full code for Listing 4 is inside of the SharePointDataAccess class within the SharePointProject in the sample project (see the Downloads section). Again, you can simply copy the contents of this class into your own custom class.


Retrieve content from SharePoint libraries

This section concentrates on enabling and writing code that uses SharePoint library content retrieval code, as discussed in the earlier section. You will also be changing the portlet JavaServer Page (JSP) file so that appropriate SharePoint library content is displayed.

Using the business logic of SharePoint library content retrieval

The first step in using the APIs that retrieve the contents from SharePoint libraries is to associate the project that contains the API with a portlet project. In this case, associate the SharePointProject project with the DealsProject portlet project:

  1. In the Enterprise Explorer view, right-click the DealsProject and, from the drop-down context menu, click the Properties option.
  2. In the Properties window (Figure 9), choose the Deployment Assembly option.

Figure 9. Web Deployment Assembly view
Configure dependent projects

  1. Click the Add button to launch New Assembly Directive window.
  2. Choose the Project option, and click Next.
  3. Choose SharePointProject as shown in Figure 10, and click Finish.

Figure 10. Choosing the deployment assembly project
Choose SharePointProject as the dependent project

  1. Click OK in the main window.

Now that you have associated the SharePointProject with the portlet project, you will write some code to use the API's provided by SharePointProject:

  1. In the DealsProject, open the SDOPropertResolver class.
  2. Go to the getValue(Object base, Object property) method, and modify it as shown in the Listing 5.

Listing 5. Method modifications
	public Object getValue(Object base, Object property)
	throws PropertyNotFoundException {
	  try {
	   if (base instanceof DataObject) {
	    if (property != null && !(property.toString().
              equalsIgnoreCase("DOCURL"))) {
		 //First try custom getter...
	       try {
			 return invokeCustomGetter(base, property);
		     } 
              catch (PropertyNotFoundException pne) {
		   //otherwise try the DataObejct getter
		    return (((DataObject) base).get(property.toString
                ()));
		  }
	   }else{
	    String companyDocURL=null;
	    if(property.toString().equalsIgnoreCase("DOCURL")){
	     DataObject account=(DataObject)(((DataObject) base).get  
           ("DEALS_ACCOUNT_DETAILS"));
	     String companyName=account.get("NAME").toString();
	     SharePointDataAccess spDataAccess=
        SharePointDataAccess.getInstance();
	      companyDocURL=spDataAccess.getUrl(companyName);

	     }
	     return companyDocURL;
	    }
	 }
	} catch (NoClassDefFoundError ncdfe) {
			// wdo jars are not available
 }

	if (oldPropResolver != null) {
		return oldPropResolver.getValue(base, property);
	  }
	 throw new PropertyNotFoundException();
	}

In this method, whenever there is a property by the name of DOCURL, the getUrl method of the SharePointAccess class is invoked. This basically retrieves a URL of a document hosted in a SharePoint document library. The input to this method is the name of the actual document library, which for this example is Liquid Sugar Corp (recall that you created a document library named Liquid Sugar Corp in the setup process in Part 1).

Display SharePoint content

Now that you have all of the code for fetching content from SharePoint libraries, you will display it along with the content fetched earlier from the IBM® DB2® database. Make some changes in the portlet JSP, DealsView.jsp:

  1. Open the DealsView.jsp file in the Page Designer.
  2. Select the data table that you created earlier, in Part 2 of this series.
  3. Open the Properties view.
  4. In the Properties view, click the Add button for columns, as shown in Figure 11.

Figure 11. Properties view
Add a column through the Properties view

  1. Enter Comments as the column name, as shown in Figure 12.

Figure 12. Add a column in the Properties view
Specify the column name in the Properties view

  1. Save the file.
  2. Open the Palette view, and expand Enhanced Faces Component drawer.
  3. Choose Link from the Enhanced Faces Component drawer, as shown in Figure 13, and drag it over the Comments column to invoke the Configure URL window.

Figure 13. Palette
Insert a Link in JSP from Palette

  1. Enter this in the URL field:
    #{vardealsInformationList.DOCURL}
  2. Enter this in the in the Label field (see Figure 14):
    #{vardealsInformationList.DEALS_ACCOUNT_DETAILS.NAME}

Figure 14. Configure URL section
Enter the URL and label information

  1. Save the file.
  2. Run the portlet project on the server as you did before.

You will see the portlet rendered in browser, as shown in Figure 14. Notice the Comments column. It provides a URL to the respective document stored in a SharePoint document library. If you click on the URL, opens the respective documents.


Figure 15. Portlet with the SharePoint data rendered in a web browser
Running the portlet on the server

This concludes the SharePoint integration instructions. You can fetch data from a picture library in a similar fashion. You can also implement the SharePoint data use case for the smart phone JSPs as you did for the desktop portlet JSP in Part 1.


Next in this series

Part 3 shows how to create event-enabled portlets that can share data.



Download

DescriptionNameSizeDownload method
Scenarios and use cases for the seriesscenarios_use_cases_sample.zip5MBHTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the author

Gaurav Bhattacharjee 照片

Gaurav Bhattacharjee is a technical lead in the IBM India Software Labs in Delhi, India. He works with the Rational Application Developer Portal Tooling team in the IBM Software Group, IBM Collaboration Solutions.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=793014
ArticleTitle=Create a multichannel composite portlet application using Rational Application Developer 8.0.4: Part 3. Displaying data from Microsoft SharePoint in a portlet
publish-date=02142012

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers