ShowTable of Contents
Previous |
Next
After creating the Office Supplies Service Provider as described in
10.2 Office Supplies service provider, you can move to the next step. This sample creates a Lotus Connections blog entry based on the selected data that is retrieved from a data source of a web application. Refer to the Connections Integration Sample in the IBM Web Experience Factory wiki for a set of
examples about retrieving and publishing data from or to the Lotus Connections components (blogs, bookmarks, and profiles).
Connection Config Data Model
This sample uses the Import to XML builder. The Import to XML builder adds to the model a variable that contains the contents of a Java properties file or an XML file. This model makes it easy to retrieve values from the
server_info.properties file where you can enter the server connections information for the current user.
To create the Connection Config Data model, follow these steps.
- Right-click the OfficeSupplies project and select New -> WebSphere Portlet Factory Model. The Choose Project dialog box that opens defaults to OfficeSupplies. Click Next.
- Select Empty under Factory Starter Models in the Select Model dialog box. Click Next.
- Expand the models folder, and highlight the redwiki folder to put the newly created model into that folder.
- Enter ConnectionConfigData in the name field, and click Finish.
- Click Add a new builder call from the builder call list.
- Select Import to XML from the All category.
- Enter serverURLs as the name.
- Enter /models/redwiki/config/server_info.properties as the File Path.
- Select Name/Value Properties File as the File Format.
- Leave the default for the remainder of the builder parameters.
- Click OK to finish and save.
You have to create a
server_info.properties file. You can either extract it from the sample zip file, or create it using the example data below:
#############################################
#
# Default configuration for accessing Connections servers.
#
# Note - HTTPS is required for the URL
#
#############################################
#
# Blogs Server Information
blogs_url=https://social.demos.ibm.com/blogs
blogs_default_handle=productblog
blogs_user_name=dmisawa
blogs_user_password=password
Blogs service provider model
The BlogsProvider is a service provider model that performs REST style calls to publish blog data back to the server. The blog publishing is done using the Atom publishing API. The REST Service Call builder is used to generate the runtime code to make requests and to publish to the server and to generate the design time of input and results xsd schema information for each operation in this provider model.
The BlogsProvider model uses four variables from the properties file, and also receives two parameters,
title and
content.
To create the service provider, follow these steps.
- Right-click the OfficeSupplies project and select New -> WebSphere Portlet Factory Model. The Choose Project dialog box that opens defaults to OfficeSupplies. Click Next.
- Select Empty under Factory Starter Models in the Select Model dialog box. Click Next.
- Expand the models folder, and highlight the redwiki folder to put the newly created model under that folder.
- Enter BlogsProvider in the name field, and click Finish.
Next, you add builders to the BlogsProvider model.
Importing the ConnectionsConfigData model
In order for the Blogs Provider to be able to read the Connections Config Data you need to import the ConnectionConfigData model into this BlogsProvider model.
To import the ConnectionsConfigData model, follow these steps.
- Click Add a new builder call from the builder call list.
- Select Imported Model from the All category.
- Enter ConnectionsConfigData in the name parameter.
- Select redwiki/ConnectionConfigData using the picker to specify the model to import.
- Leave the default for the remainder of the builder parameters.
- Click OK to finish.
Creating a blogsAccess service definition
To create a blogsAccess service definition, follow these steps.
- Click Add a new builder call from the builder call list.
- Select Service Definition from the All category.
- Enter blogsAccess in service name field.
- Expand the TestingSupport section, and enable the Add Testing Support and Generate Main options.
- Leave the default for the remainder of the builder parameters (see the figure below).
- Click OK to finish.
The figure below shows the blogsAccess service definition.

Creating the addEntry REST Service Call
This is the core of the Sample application where the REST call is made to the IBM Connections API.
To create REST service call, follow these steps.
- Click Add a new builder call from the builder call list.
- Select REST Service Call from the All category.
- Enter addEntry in the name field.
- Select POST from the HTTP request type radio button selection (see the figure below).
- Enter the following text in the URL field:
${Variables/serverURLs/Configuration/blogs_url}/${Variables/serverURLs/Configuration/blogs_default_handle}/api/entries
Enter this text carefully! There are 2 variables included here and some literal text for the complete URL.
- Enter createEntry/entry as the Body Content Data Type.
- Select application/atom+xml from the body content-type field.
- Use the picker to select the userName and userPassword variables for the corresponding User Name and Password fields (see the figure below).
- Make sure that the Ignore Results option is selected.
- Leave the default for the remainder of the builder parameters.
- Click OK to finish.
The figure below shows the REST Service Call properties.

Creating an addEntryData method
To create an addEntryData method, follow these steps.
- Click Add a new builder call from the builder call list.
- Select Method from the All category.
- Enter addEntryData in the name field.
- Enter the title and content arguments as String (see the figure below).
- Enter the following text in the method body field:
{ // Build up the new XML
IXml entry = XmlUtil.create("entry");
entry.setAttribute("xmlns", "http://www.w3.org/2005/Atom");
entry.setText("title", title);
IXml contentElement = entry.addChildElement("content");
contentElement.setAttribute("type", "html");
// decode the content. When running in portal this is encoded for security reasons.
// see for more information http://publib.boulder.ibm.com/infocenter/wpdoc/v6r0/index.jsp?topic=/com.ibm.wp.zos.doc/wps/tbl_sec.html
if(content != null)
{
content = content.replaceAll("<", "<");
content = content.replaceAll(">", ">");
}
contentElement.setText(content);
// Set the REST Service input
webAppAccess.getVariables().setXml("addEntryRestInputs", entry);
}
- Leave the default for the remainder of the builder parameters.
- Click OK to finish.
The figure below shows the addEntryData method builder.

Creating the addNewEntry Action List
To create the addNewEntry Action List, follow these steps.
- Click Add a new builder call from the builder call list.
- Select Action List from the All category.
- Enter addNewEntry as the Name.
- Add the two Arguments title and content with Data Type string as shown in the figure below
- Use the Picker button
to add the two Actions as shown in the figure below.
- Leave the default for the remainder of the builder parameters.
- Click OK to finish.
This figure shows the addNewEntry Action List.

Creating the createBlogEntry service operation
To create the createBlogEntry service operation, follow these steps:
- Click Add a new builder call from the builder call list.
- Select Service Operation from the All category.
- Select blogAccess from the data service selection list.
- Enter createBlogEntry in the name field.
- Click the Picker button
, and select addNewEntry from the picker dialog box.
- Expand the Operation Results section, and select No results from the result structure handling radio button.
- Leave the default for the remainder of the builder parameters.
- Click OK to finish.
This figure shows the createBlogEntry service operation.

Blogs service provider model summary
In summary, you have now created a service provider to allow other Web Experience Factory models or external applications to consume methods that are published by your provider. In this sample, the consumer is another Web Experience Factory model called
OfficeSupplies, which we discuss in
10.4 Office Supplies application. Currently, the blogs service provider provides only a create blog entry operation. This service provider can be extended easily to accommodate other operations such as retrieving, editing, or deleting blog entries; retrieving, adding, or editing comments to blog entries; and so forth. For the details about these additional operations, refer to the
sample application in the Web Experience Factory wiki.
To allow users to create blog entries, we use REST style calls to publish blog data back to the server. Web Experience Factory provides a REST Service Call builder that makes it easier for you to make such calls without having in depth knowledge about REST APIs. Next, you use the Service Operation builder to provide an operation that creates a blog entry that is available to use by the service consumers. The createBlogEntry service operation calls the addNewEntry action list. This action list invokes the REST call using the data service that is generated by the REST Service Call builder.
The Outline for the Completed Blogs service provider model will look as follows:

Testing the Blogs service provider model
In the same way that you tested the OfficeSuppliesProvider, you can test the BlogsProvider model:
- Right-click on the BlogsProvider model and click Run As --> Run active model.
- Click on the createBlogEntry link.
- Enter a simple Title and short Contents text and click Submit.
- View the Connections Blog.
If you do not observe the results you expect:
- Check the Problems tab in designer for Web Experience Factory.
- Check the log of the WebSphere Community Edition server.
- Check the log for the IBM Connections Server hosting the Blogs application.
- Carefully check the URL value in the REST Service Call builder.
Next step
Now, you can go to the next step of creating the Office Supplies application discussed in
10.4 Office Supplies application.
Note: You can download the sample code from
10.6 The Office Supplies application sample code.
Parent topic:
10.0 IBM Web Experience Factory