Oracle WebCenter Interaction Web Service Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using the Oracle WebCenter Interaction Activity Stream API

To add a new story to a user's Activity Stream, send a POST request containing the necessary data to the story server URL.

The post must use the following syntax:
POST http://${STORY_SERVER_URL}/api/story/v1/activities/${USER_ID_TYPE}/${USER_ID_PREFIX}/${USER_ID_SUFFIX}

<soc:activity xmlns:soc="">
Variable Description
STORY_SERVER_URL The URL to the story server, typically, %HOSTNAME%:21030/activityservice.
USER_ID_TYPE The type of user identifier that follows; acceptable values are: username (login name), UUID, & ID (portal object integer ID).
Note: These strings must be lowercase.
USER_ID_PREFIX The identifier of the user that the story is about; in the case of domain qualified names, this is the domain name. (For example, bea\jking will be represented as .../username/bea/jking in the post URL.)
USER_ID_SUFFIX (Optional.) In the case of domain qualified names, this is the username; omitted in all other cases.
EVENT The story itself (the CDATA envelope is optional if the story does not include any markup).
Note: The Activity Stream API is protected by Oracle WebCenter Interaction security. Access is restricted to portal users by login token verification or basic authentication. For details, see tsk_ali_activitystreamapi_configuring.html.
The response will include one of the following HTTP codes:
  • 201 // story successfully created
  • 401 // authorization failed
  • 404 // story user not found
  • 400 // other error, including XML syntax errors
The response body uses the following syntax:
<soc:activity xmlns:soc="">
    <body>post content</body>
    <senderFullName>Joe King</senderName>
    <userFullName>Joe King</userFullName>
The post can be implemented in many ways, as shown in the examples that follow.

HTML/JavaScript Example

The simple HTML/JavaScript example below posts a story entered by the user.
<script type="text/javascript">
	// Get the gatewayed URL - This will give us authentication and prevent cross domain POST errors.
	var activitystreamBaseURL = "<pt:common.url xmlns:pt='' pt:href=''/>";
	// Get the sender's full name.
	var senderName = "<pt:common.userinfo pt:info='FullName' xmlns:pt=''/>";
	var portalURL = "";

	function sendStory() {
		var to = document.getElementById('to').value;
		var message = linkedName() + ' wrote: '
				+ document.getElementById('message').value;

				activitystreamBaseURL + 'username/' + to,
				'<?xml version="1.0" encoding="UTF-8"?>'
						+ '<soc:activity xmlns:soc="">'
						+ '<body><![CDATA[' + message + ']]></body>'
						+ '</soc:activity>');

	function doRestCall(requestType, postURL, xml) {
		var xmlhttp;
		// Get the XMLHttpRequest object -- needs to work for IE and non-IE browsers
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
		// Set the callback as an anonymous funcion
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				var str = '<div>';
				// We should get 201 CREATED on successful POST
				if (xmlhttp.status == 201) {
					str = str + 'Message sent!';
				} else {
					str = str + 'ERROR: ' + xmlhttp.status + '</div><div>'
							+ xmlhttp.responseText + '</div>';
				document.getElementById('output').innerHTML = str;
		}, postURL, true);
		xmlhttp.setRequestHeader("Content-Type", "text/xml");

	function linkedName() {
		// This function returns viewing userÕs name hyperlinked to their homepage.
		var nameurl = senderName.replace(" ", "_");
		nameurl = nameurl.toLowerCase();
		var link = '<a href="' + portalURL + '/user/' + nameurl + '">'
				+ senderName + '</a>';
		return link;
<div>Send a message to: <input id="to" type="text" size="30"/></div>
<div>Message: <input id="message" type="text" size="40" /></div>
<div><a href="#" onclick="sendStory();"> send it! </a></div>
<div id="output"></div>

Java Example

The Java example below sends the message “Check out the <a href=\"\">BEA</a> home page!”.
package bea.sample.activitystream;


import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.*;

public class ActivityStreamUtil {

	public static HttpClient CreateAuthenticatedClient(String username,
			String password) {
		HttpClient client = new HttpClient();

		// This is promiscuous be careful
				new UsernamePasswordCredentials(username, password));
		// Send credentials with request without waiting for challenge

		return client;

	public static PostMethod CreateActivityStreamPost(String url, String body) {
		PostMethod postMethod = new PostMethod(url);
		RequestEntity requestEntity = null;
		try {
			requestEntity = new StringRequestEntity("<activity><body><![CDATA["
					+ body + "]]></body></activity>", "text/xml", "UTF-8");
		} catch (UnsupportedEncodingException e) {
		return postMethod;
package bea.sample.activitystream;


import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;

public class ActivityStreamPost {
	public static final String ACT_USERNAME = "username";
	public static final String ACT_ID = "id";
	public static final String ACT_UUID = "uuid";

	public static void main(String[] args) {
		// Post to the guest user by name from the administrator account.
		String host = "localhost:21030";
		String userIDType = ACT_USERNAME;
		String userID = "guest";
		String username = "administrator";
		String password = "admin";
		String url = "http://" + host
				+ "/activityservice/api/story/v1/activities/" + userIDType
				+ "/" + userID;
		String message = "Check out the <a href=\"\">BEA</a> home page!";
		HttpClient client = ActivityStreamUtil.CreateAuthenticatedClient(
				username, password);
		PostMethod post = ActivityStreamUtil.CreateActivityStreamPost(url,
		try {
			int status = client.executeMethod(post);
			if (status == HttpStatus.SC_CREATED) {
				System.out.println("Post successful");
			} else {
				System.err.println("Method failed: " + post.getStatusLine());
		} catch (HttpException e) {
			System.err.println("Fatal protocol violation: " + e.getMessage());
		} catch (IOException e) {
			System.err.println("Fatal transport error: " + e.getMessage());
		} finally {

.NET Example

The .NET (C#) example below sends the message ’Greetings from .NET!”.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace ActivityServiceTest
    class Program
        static void Main(string[] args)
            string url = "http://localhost:8090/activityservice/api/story/v1/activities/username/bea/nsuravar";
            string username = "test";
            string password = "plumtree";
            string data = "<soc:activity xmlns:soc=\"\"><body>Greetings from .NET!</body></soc:activity>";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.Credentials = new NetworkCredential(username, password);
            request.ContentLength = data.Length;
            request.KeepAlive = false;
            System.Net.ServicePointManager.Expect100Continue = false;
            Uri uri = new Uri(url);
            NetworkCredential Credentials = request.Credentials.GetCredential(uri, "Basic");
            request.ContentType = "text/xml;charset=UTF-8";
            if (Credentials != null)
                byte[] credentialBuffer = new UTF8Encoding().GetBytes(
                    Credentials.UserName + ":" +
                request.Headers["Authorization"] =
                    "Basic " + Convert.ToBase64String(credentialBuffer);
            StreamWriter writer = new StreamWriter(request.GetRequestStream());
                WebResponse response = request.GetResponse();

                 byte[] ByteArray = response.Headers.ToByteArray();
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    while (reader.Peek() != -1)
            catch (Exception ex)

  Back to Top      Previous Next