Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Stardust/Knowledge Base/Integration/UI/UIMashup"

 
(14 intermediate revisions by 2 users not shown)
Line 19: Line 19:
 
#Mention the Input & Output parameters.
 
#Mention the Input & Output parameters.
  
*Do In/Out data mapping for the activity.<br>
+
*Do In/Out data mapping for the activity. Stardust to Web Application, along with the process model,&nbsp;[http://wiki.eclipse.org/images/0/04/Stardust_Integration_UIMashUp.zip Download Here]
  
This is the model for one of the sample applications. It is an example to send &amp; receive both primitive &amp; structured data from IPP to Web Application.MashUp.xpdl
+
a). Enter Name Activity
  
<br>
+
This is a manual activity. The user is asked to enter User Name which Stardust will store in a primitive data type (here username). Also user is asked to enter Name, Age &amp; Salary which will be stored in a structured data type (here PersonRequestData) in Stardust.&nbsp;&nbsp;&nbsp; <br>
 +
 
 +
b). Call WebApplication Activity
 +
 
 +
&nbsp;Call Web Application is an application activity. Username &amp; PersonRequestData are the inputs for this activity.<br>This model uses a sample External Web Application (here HelloWorld Application). This application will be called when Call Web Application activity is performed.<br>The model has responsedata &amp; PersonReponseData which are the response from External Web Application and it will be displayed in the Stardust screen. responsedata is a primitive data type while PersonReponseData is a structured data type of type Person(which has Name, Age &amp; Salary).<br>The modeler would require to enter the URL &amp; Input/Output parameter for HelloWorld Application. Please refer to the attached model to see how these configurations are done. <br>Also the modeler would require to provide all the In/Out mapping for activity Call Web Application. Please see the attached screen shot for one of the sample mapping. Please refer to the model to see the mapping for all the parameters. &nbsp;&nbsp;&nbsp; <br>
 +
 
 +
c). Display Response Activity <br> &nbsp;&nbsp;&nbsp;&nbsp; This activity is used to display the response received from the HelloWorld Application<br>
 +
 
 +
==== Code changes at External Web Application End<br>  ====
 +
 
 +
It would require to write some code to retrieve the parameters (sent from Stardust) inside the External Web Application. Also Web Application would require some code to send back some data to Stardust from Web Application.<br>HelloServlet is a servlet inside HelloWorld Application. The request is made to this servlet from Stardust when Call WebApplication activity is performed.<br>
 +
 
 +
Please refer to sample code inside the servlet. It has proper comments with the code which will helps in understanding how data can be retrieved inside Web Application. Similarly it explains as how data can be sent back to Stardust from this Web Application.<br>The code snippet to retrieve the data inside Web Application:<br>
 +
 
 +
<source lang="java">
 +
 
 +
        /**
 +
* This method is used to retrieve the request data inside the web application(data sent from Stardust)
 +
* @param request
 +
* @param dataName : data to be retrieved
 +
* @return data in the format of String
 +
*/
 +
 +
private String getRequestData(HttpServletRequest request, String dataName){
 +
String value = null;
 +
int statusCode = 0;
 +
 +
HttpClient client = new HttpClient();
 +
 +
String ippInteractionUri = request.getParameter("ippInteractionUri");
 +
System.out.println("ippInteractionUri :: " +ippInteractionUri);
 +
 +
GetMethod get = new GetMethod(ippInteractionUri+"/inData/" +dataName);
 +
 +
if(ippInteractionUri != null){
 +
try {
 +
statusCode=client.executeMethod(get);
 +
if(statusCode==200){
 +
value  =get.getResponseBodyAsString();
 +
}
 +
} catch (HttpException e) {
 +
e.printStackTrace();
 +
} catch (IOException e) {
 +
e.printStackTrace();
 +
}
 +
}
 +
return value;
 +
}
 +
 
 +
</source>
 +
 
 +
The code snippet to send the data to Stardust from the External Web Application.<br> <source lang="java">
 +
 
 +
        /**
 +
* This method is used to put the data in request to send it back to Stardust
 +
* @param request
 +
*/
 +
private void putResponseData(HttpServletRequest request){
 +
 +
String ippInteractionUri = request.getParameter("ippInteractionUri");
 +
 +
// here 'responsedata' is a primitive data to be sent
 +
PutMethod put = new PutMethod(ippInteractionUri+"/outData/responsedata");
 +
 +
HttpClient client= new HttpClient(); 
 +
 +
// form the RequestEntity object(with primitive value) and set in into PutMethod object
 +
RequestEntity entity;
 +
try {
 +
entity = new StringRequestEntity("Response from Web Application.",null,null);
 +
put.setRequestEntity(entity);
 +
 +
} catch (UnsupportedEncodingException e1) {
 +
e1.printStackTrace();
 +
}
 +
 +
try {
 +
int statusCode = client.executeMethod(put);
 +
String resData = put.getResponseBodyAsString();
 +
 +
} catch (HttpException e) {
 +
e.printStackTrace();
 +
} catch (IOException e) {
 +
e.printStackTrace();
 +
}
 +
 +
// here 'PersonResponseData' is a structured data to be sent
 +
PutMethod putPerson = new PutMethod(ippInteractionUri+"/outData/PersonResponseData");
 +
 +
RequestEntity personentity;
 +
try {
 +
 +
/* Note that the value of the  Structured Data will be a XML in the form of String.
 +
Its upto the Web Application to parse this XML String and form the Java data objects
 +
and perform application specific functionality. Same is true when we want to send back the response
 +
to Stardust. We would require to form a XML String in proper format.
 +
*/
 +
 
 +
// form the String in form of the XML
 +
String str = "XXXXX352345789";
 +
 +
personentity = new StringRequestEntity(str,"application/xml","ISO-8859-1");
 +
putPerson.setRequestEntity(personentity);
 +
 +
} catch (UnsupportedEncodingException e1) {
 +
 +
e1.printStackTrace();
 +
}
 +
 +
try {
 +
int statusCode = client.executeMethod(putPerson);
 +
 +
String resData = put.getResponseBodyAsString();
 +
 +
} catch (HttpException e) {
 +
 +
e.printStackTrace();
 +
} catch (IOException e) {
 +
 +
e.printStackTrace();
 +
}
 +
}
 +
 
 +
</source>
 +
 
 +
====== Implementing work item scope<br>  ======
 +
 
 +
Note that the Stardust Portal uses tabs to display several open work items at once. When two work items of the same kind (same activity) are opened, the same external page that is associated with the activity in the process model might be opened multiple times, each time displaying a separate activity instance. If the external page needs to implement a persistence mechanism to keep data in the HTTP session, it is imperative to implement a way to separate the work item scope, because otherwise the state of another work item could be overwritten. This is typically done by implementing a context-aware storage (e.g. a HashMap) within the session that uses the unique object ID of the activity instance as a key.<br>
 +
 
 +
There is an easy way to get to the activity instance OID by decoding the Interaction URI with a Base64 decoder:<br>
 +
 
 +
Interaction URI: "NTc1MDJ8MTM1MzM0MzQ0MTY0Ng=="<br>Base64 decoded: "57502|1353343441646"<br>The activity OID is "57502", i.e. the part before the pipe symbol '|'. Use this OID as the key to the work item session context into which state can be saved per activity instance.<br><br>

Latest revision as of 05:14, 28 June 2013

Purpose

The standard UI technologies available in the modeling environment are:

  • JSF
  • JSP
  • JFC

Any existing web-based UI components potentially residing in different web application can be displayed and used as inside the Stardust Process Portal when successful integrations with other web-based UI technologies exist, e.g Struts, Grails..etc

Calling an External Web Application

Following are the steps to be performed:

  • Create an Application Activity
  • Map this activity with external web application.
  1. Mention the URL of the Web Application.
  2. Mention the Input & Output parameters.
  • Do In/Out data mapping for the activity. Stardust to Web Application, along with the process model, Download Here

a). Enter Name Activity

This is a manual activity. The user is asked to enter User Name which Stardust will store in a primitive data type (here username). Also user is asked to enter Name, Age & Salary which will be stored in a structured data type (here PersonRequestData) in Stardust.   

b). Call WebApplication Activity

 Call Web Application is an application activity. Username & PersonRequestData are the inputs for this activity.
This model uses a sample External Web Application (here HelloWorld Application). This application will be called when Call Web Application activity is performed.
The model has responsedata & PersonReponseData which are the response from External Web Application and it will be displayed in the Stardust screen. responsedata is a primitive data type while PersonReponseData is a structured data type of type Person(which has Name, Age & Salary).
The modeler would require to enter the URL & Input/Output parameter for HelloWorld Application. Please refer to the attached model to see how these configurations are done.
Also the modeler would require to provide all the In/Out mapping for activity Call Web Application. Please see the attached screen shot for one of the sample mapping. Please refer to the model to see the mapping for all the parameters.    

c). Display Response Activity
     This activity is used to display the response received from the HelloWorld Application

Code changes at External Web Application End

It would require to write some code to retrieve the parameters (sent from Stardust) inside the External Web Application. Also Web Application would require some code to send back some data to Stardust from Web Application.
HelloServlet is a servlet inside HelloWorld Application. The request is made to this servlet from Stardust when Call WebApplication activity is performed.

Please refer to sample code inside the servlet. It has proper comments with the code which will helps in understanding how data can be retrieved inside Web Application. Similarly it explains as how data can be sent back to Stardust from this Web Application.
The code snippet to retrieve the data inside Web Application:

        /**
	 * This method is used to retrieve the request data inside the web application(data sent from Stardust) 
	 * @param request
	 * @param dataName : data to be retrieved
	 * @return data in the format of String
	 */
 
private String getRequestData(HttpServletRequest request, String dataName){
		String value = null;
		int statusCode = 0;
 
		HttpClient client = new HttpClient();
 
		String ippInteractionUri = request.getParameter("ippInteractionUri");		
		System.out.println("ippInteractionUri :: " +ippInteractionUri);
 
		GetMethod get = new GetMethod(ippInteractionUri+"/inData/" +dataName);
 
		if(ippInteractionUri != null){
			try {				
				statusCode=client.executeMethod(get);				
				if(statusCode==200){							
					value  =get.getResponseBodyAsString();										
				}				
			} catch (HttpException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} 			
		}
		return value;
}
The code snippet to send the data to Stardust from the External Web Application.
        /**
	 * This method is used to put the data in request to send it back to Stardust
	 * @param request
	 */
	private void putResponseData(HttpServletRequest request){
 
		String ippInteractionUri = request.getParameter("ippInteractionUri");
 
		// here 'responsedata' is a primitive data to be sent
		PutMethod put = new PutMethod(ippInteractionUri+"/outData/responsedata");
 
		HttpClient client= new HttpClient();   
 
		// form the RequestEntity object(with primitive value) and set in into PutMethod object
		RequestEntity entity;
		try {
			entity = new StringRequestEntity("Response from Web Application.",null,null);
			put.setRequestEntity(entity);
 
		} catch (UnsupportedEncodingException e1) {			
			e1.printStackTrace();
		}
 
		try {
			int statusCode = client.executeMethod(put);			
			String resData = put.getResponseBodyAsString();
 
		} catch (HttpException e) {			
			e.printStackTrace();
		} catch (IOException e) {		
			e.printStackTrace();
		} 		
 
		// here 'PersonResponseData' is a structured data to be sent
		PutMethod putPerson = new PutMethod(ippInteractionUri+"/outData/PersonResponseData");
 
		RequestEntity personentity;
		try {
 
		/* Note that the value of the  Structured Data will be a XML in the form of String. 
		Its upto the Web Application to parse this XML String and form the Java data objects 
		and perform application specific functionality. Same is true when we want to send back the response
		to Stardust. We would require to form a XML String in proper format. 		
		*/
 
		// form the String in form of the XML
		String str = "XXXXX352345789";
 
			personentity = new StringRequestEntity(str,"application/xml","ISO-8859-1");
			putPerson.setRequestEntity(personentity);
 
		} catch (UnsupportedEncodingException e1) {
 
			e1.printStackTrace();
		}
 
		try {
			int statusCode = client.executeMethod(putPerson);
 
			String resData = put.getResponseBodyAsString();
 
		} catch (HttpException e) {
 
			e.printStackTrace();
		} catch (IOException e) {
 
			e.printStackTrace();
		} 
	}
Implementing work item scope

Note that the Stardust Portal uses tabs to display several open work items at once. When two work items of the same kind (same activity) are opened, the same external page that is associated with the activity in the process model might be opened multiple times, each time displaying a separate activity instance. If the external page needs to implement a persistence mechanism to keep data in the HTTP session, it is imperative to implement a way to separate the work item scope, because otherwise the state of another work item could be overwritten. This is typically done by implementing a context-aware storage (e.g. a HashMap) within the session that uses the unique object ID of the activity instance as a key.

There is an easy way to get to the activity instance OID by decoding the Interaction URI with a Base64 decoder:

Interaction URI: "NTc1MDJ8MTM1MzM0MzQ0MTY0Ng=="
Base64 decoded: "57502|1353343441646"
The activity OID is "57502", i.e. the part before the pipe symbol '|'. Use this OID as the key to the work item session context into which state can be saved per activity instance.

Back to the top