Difference between revisions of "Developing Portlets with GWT"

From Gcube Wiki
Jump to: navigation, search
 
(119 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
[[Category:TO BE REMOVED]]
 +
 
How to write a portlet with the aim of GWT.
 
How to write a portlet with the aim of GWT.
  
== Pre-development Installation ==
+
== Pre-development Actions==
===Modifying Tomcat===
+
===Modifying Gridpshere Home===
# Replace ''$CATALINA_HOME/webapps/gridsphere/WEB-INF/CustomPortal/layouts/TemplateLayout.xml'' with the corresponding one found [http://dlib.sns.it/bscw/bscw.cgi/0/55048 here].
+
If you want you can also apply the respective changes to gridsphere's home directory.
# Include the gwt.js and script.html files found [http://dlib.sns.it/bscw/bscw.cgi/0/55048 here] in ''$CATALINA_HOME/webapps/gridsphere/html'' directory.
+
This can be useful if, for some reason, you want to redeploy gridsphere.
  
==== The Service resource ====
+
===Installing GWT===
 +
#Download the latest version of GWT from [http://code.google.com/webtoolkit/ here].
 +
#Uzip the file.
 +
#Set environmntal variable: ''GWT_HOME=<the name of the folder where you unpacked gwt files>''
  
Usually, a ''Service'' is defined as a software system that delivers functionalities. In DILIGENT, a Service is a not-empty set of related [[Profile_Specification#PackageList_section| Packages]] (connected through dependencies) forming an unique logical entity. A Package is the smallest installable unit of software that can be deployed on a DHN (e.g. a JAR o a GAR archive). Packages are the way in which the software needed to set up a DL has to prepared in order to be used and stored in the system.  
+
==Creating a gwt-portlet==
Once the service components have been developed, they must be described by compiling the service profile.
+
===Creating a gwt project===
 +
In order to create a gwt project, you must execute:
 +
<br>
 +
<br>
 +
<source lang="bash">
 +
cd $GRIDPSHERE_HOME/projects
 +
mkdir <module_dir_name>
 +
cd <module_dir_name>
 +
$GWT_HOME/projectCreator -eclipse MyProject
 +
$GWT_HOME/applicationCreator -eclipse MyProject org.gcube.<whatever>.client.<ModuleName>
 +
</source>
  
===== Package types =====
+
Now you can develop your gwt project as you wish by using eclipse!<br>
  
 +
===Writing a gwt application===
 +
You can find useful information about how to write a gwt application on the '''G'''oogle '''W'''eb '''T'''oolkit's official site: [http://code.google.com/webtoolkit/ http://code.google.com/webtoolkit/].<br>
 +
<br>
 +
====<span style="color:red;">! IMPORTANT INFO</span>====
 +
In the entrypoint-class, in the onModuleLoad() method:
 +
When you are about to add your widget in the main page,<br>
 +
instead of writing:
 +
<source lang="java5">RootPanel.get().add(<your widget>);
 +
</source>
 +
you must write:
 +
<source lang="java5">RootPanel.get(<a unique id for the DIV>).add(<your widget>);
 +
</source>
  
Concretely, a Package is a “piece of software” that can be deployed on a DHN. A Package can be:
+
So, the generated html will be placed in the predefined ''div'' instead of being placed in an unspecified location.
* a ''[[Profile_Specification#WSRFService|WSRFService]]'', representing a package that once deployed produces a WSRF Service (a service able to manage stateful resources following the WS-Resource patterns);
+
* a ''[[Profile_Specification#Portlet|Portlet]]'', representing a package that once deployed produces a portlet (Web components, managed by a portlet container, that process requests and generate dynamic GUI content) that can be hosted in a DILIGENT Portal;
+
* a ''[[Profile_Specification#GridJob|GridJob]]'', representing a package containing the code and the related information needed to run a certain job on the grid infrastructure;
+
* a ''[[Profile_Specification#Library|Library]]'', representing a software library (typically a JAR) that can be hosted on a DHN. There are three types of library:
+
** ''Shared'' Library, software library offering functionality of common utility, e.g. an XML parser library or a mathematical support library;
+
** ''Stub'' Library, software library offering functionality for interacting with WSRF Services.
+
** ''External'' Library, a thirdy party library available on the ETICS Repository that can be dynamically deployed.
+
* ''[[Profile_Specification#Software|Software]]'', a thirdy party software distributed with the service that can be dynamically deployed;
+
* ''[[Profile_Specification#ExternalSoftware|ExternalSoftware]]'', a thirdy party software available on the ETICS repository that can be dynamically deployed.
+
  
About how to define a package of any type above, see the [[Profile_Specification#PackageList_section| PackageList section]].
+
===Creating a jsr 168 portlet===
===== Composition =====
+
In oder to create an empty portlet project, you must execute:
The set of Packages forming a Service is composed by:
+
<br><br>
# one and only one Package of [[Profile_Specification#WSRFService|WSRFService]] or [[Profile_Specification#Portlet|Portlet]] type (the main package)
+
<div style="color:green;">
# an arbitrary number of other Packages of different type logically related (even if not used) to it.
+
>cd $GRIDPSHERE_HOME/<br>
 +
>ant new-project<br>
 +
* insert: &lt;Portlet's Title&gt;<br>
 +
* insert: &lt;module_dir_name&gt;  -- This must be the same as in gwt project<br>
 +
* insert: jsr<br>
 +
</div><br>
  
The "main" part of a Service is, of course, the WSRFService package from which the related Running Instance resource is generated. The other packages can be
+
Now, if you refresh the eclipse project, you can see that the "portlet-files" are generated.
* helper modules developed and used by the WSRFService
+
* thirdy parties software used by the WSRFService
+
* helper modules developed and distributed with the WSRFService in order to be used by other Services to interact with a Running Instance of the Service.
+
  
===== How to specify dependencies =====
+
====Creating the portlet class====
A package, once deployed, can rely on other software to perform its activities. Let's see how to specify these dependencies by distinguishing among:
+
* Create a class named: '''''org.gcube.<whatever>.portlets.<portletClassName>'''''.
* software developed within this service (this is the case of a stub library, for instance)
+
* Add the following content to the class:
*:&rarr; the software has to be declared as [[Profile_Specification#Library|Library]] and the dependency is specified as [[Profile_Specification#Dependencies|package Dependency]]
+
<source lang="java5">
* software developed and distributed within other DILIGENT services
+
*:&rarr; the dependency is specified as [[Profile_Specification#Dependencies|package Dependency]] against a package defined in another Service profile
+
* thirdy party deployable software used only by this service
+
*:&rarr; the software has to be declared as [[Profile_Specification#Software|Software]] or [[Profile_Specification#Library|Library]] (it depends on the nature of the software) and the dependency is specified as [[Profile_Specification#Dependencies|package Dependency]]
+
* thirdy party deployable software used by other services
+
*:&rarr; the software has to be uploaded in the ETICS repository, the package has to be declared as  [[Profile_Specification#ExternalSoftware|ExternalSoftware]] and the dependency is specified as [[Profile_Specification#Dependencies|package Dependency]]
+
* thirdy party software that is not dynamically deployable
+
*:&rarr; the software has to be manually installed, the label has to be manually declared in the DHN profile (by the DHN owner) and the dependency is specified as [[Profile_Specification#DHNRequirements|DHN Requirement]]
+
  
== How to compile the profile ==
+
    // JSP folder name
 +
    public static final String JSP_FOLDER = "/jsp";
 +
    // JSP file name to be rendered on the view mode
 +
    public static final String VIEW_JSP = JSP_FOLDER + "/<a_name_for_the_jsp_page>.jsp";
 +
 +
 +
    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException{
 +
// ------------------------------------------------------------
 +
// Note: The portlet is just diplaying a JSP for the AJAX Lab.
 +
// It does absolutely nothing else.
 +
// ------------------------------------------------------------
  
The following example shows the common elements that compose the Service profile. The Package-specific sections are explained apart later.
+
<pre>
+
<DILIGENTResource xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
            request.getPortletSession().setAttribute("username", request.getRemoteUser(), PortletSession.APPLICATION_SCOPE);
<UniqueID/>
+
<ResourceType>Service</ResourceType>
+
<AuthorizationPolicies>
+
[...]
+
</AuthorizationPolicies>
+
<Profile>
+
<Class>MetadataManagement</Class>
+
<Name>MetadataCatalog</Name>
+
<DescriptiveParameters>
+
<DescParameter/>
+
</DescriptiveParameters>
+
<QoS/>
+
<DeploymentInfo>
+
<Deployable value="true"/>
+
</DeploymentInfo>
+
<DLDependencies>
+
<DLComponent>
+
<Class>MetadataManagement</Class>
+
<Name>XMLIndexer</Name>
+
<DescriptiveParametersValue/>
+
</DLComponent>
+
<DLComponent>
+
<Class>ContentManagement</Class>
+
<Name>StorageManagementService</Name>
+
<DescriptiveParametersValue/>
+
</DLComponent>
+
<DLComponent>
+
<Class>ContentManagement</Class>
+
<Name>CollectionManagementService</Name>
+
<DescriptiveParametersValue/>
+
</DLComponent>
+
</DLDependencies>
+
<SpecificData/>
+
<PackagesList>
+
                [...]
+
</PackagesList>
+
</Profile>
+
</DILIGENTResource>
+
</pre>
+
  
=== Common elements ===
+
// Invoke the JSP to render:
 +
      PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
 +
rd.include(request,response);           
 +
    }
  
==== Class ====
+
</source>
The class of a service is it's functional area. The following values are accepted as service classes:
+
* InformationSystem
+
* Keeper
+
* VDLGenerator
+
* BMM
+
* DVOS
+
* Search
+
* Index
+
* DataFusion
+
* CSD
+
* CSS
+
* ProcessManagement
+
* Annotation
+
* FeatureExtraction
+
* Personalisation
+
* ContentSecurity
+
* ContentManagement
+
* MetadataManagement
+
* Portal
+
  
==== Name ====
+
====Creating the jsp page====
The Name is an arbitrary string that uniquely identifies the service within a service class.
+
  
==== DescriptiveParameters ====
+
*Create a file in the ''webapp/jsp'' directory named: '''''<a_name_for_the_jsp_page>.jsp'''''.
  
==== QoS ====
+
*In this file you place the following content:
 +
<source lang="asp">
 +
<%@ page contentType="text/html" %>
 +
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
  
==== DeploymentInfo ====
+
<!--                                          -->
 +
<!-- The module reference below is the link    -->
 +
<!-- between html and your Web Toolkit module  -->
 +
<!--                                          -->
 +
<script src='<%=request.getContextPath()%>/html/org.gcube.<whatever>.<ModuleName>.nocache.js'></script>
  
==== DLDependencies  ====
 
A DILIGENT service is part of a complex system and it makes use of other services. At VDL definition time, firstly, it is compiled the list of services that satisfy the VDL definition criteria and, then, such a list is completed with the other services that allow the first ones to work properly. Therefore it is needed that a service declares which other services it will need to be available in order to do its work once it is deployed.
 
Specify a DL dependency here means that if this service is deployed in a DL, also the service identified by the Service Class and Name has to be deployed in the DL. (The DescriptiveParametersValue sintax still needs to be defined)
 
  
==== PackagesList section ====
+
<div id="<a unique id for the DIV>">
This element groups an unbounded sequence of Package elements. Each element describes a package that belongs the service. The structure of a Package element includes an initial common part and a package-specific part rooted by an element named as the service type ([[Profile_Specification#WSRFService|WSRFService]], [[Profile_Specification#Library|Library]], [[Profile_Specification#Portlet|Portlet]], [[Profile_Specification#GridJob|GridJob]], [[Profile_Specification#Software|Software]], [[Profile_Specification#ExternalSoftware|ExternalSoftware]]).
+
</div>
The only constraint is that one and only one WSRFService element is accepted in the list.
+
 
+
</source>
===== Common elements =====
+
 
 +
I should mention here that the '''''org.gcube.<whatever>.<ModuleName>''''' is the one you defined when you created the gwt application.<br>
 +
Additionally, the id for the div is the one you used in the RootPanel.get() method.
 +
 
 +
===Configuring the portlet===
 +
* Modify the ''webapp/WEB-INF/portlet.xml'' file as following:
 +
Instead of:
 +
<source lang="xml">
 +
        <!-- place portlet description here -->
 +
        <description xml:lang="en">This Portlet is a sample</description>
 +
        <description xml:lang="de">Diese Portlet ist ein sample</description>
 +
        <!-- place unique portlet name here -->
 +
        <portlet-name>SamplePortlet</portlet-name>
 +
        <display-name xml:lang="en">A sample Portlet</display-name>
 +
        <display-name xml:lang="de">Ein sample Portlet</display-name>
 +
        <!-- place your portlet class name here -->
 +
        <portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class>
 +
</source>
 +
Write:
 +
<source lang="xml">
 +
        <!-- place portlet description here -->
 +
        <description xml:lang="en">Your Portlet description</description>
 +
        <!-- place unique portlet name here -->
 +
        <portlet-name>UniquePorltetName</portlet-name>
 +
        <display-name xml:lang="en">Portlet's Title</display-name>
 +
        <!-- place your portlet class name here -->
 +
        <portlet-class>>org.diligentproject.<whatever>.portlets.<portletClassName></portlet-class>
 +
</source>
 +
 
 +
==Deploying the gwt-portlet==
 +
In order to deploy the gwt-portlet you need to create a file in the main directory of your eclipse project which will contain the following:
 +
<source lang="bash">#!/bin/bash
 +
#This bash script compiles and deploys the gwt-portlet.
 +
 
 +
# Delete files from previous compilation / deployment:
 +
rm -rf webapp/html
 +
rm -rf webapp/WEB-INF/classes/org
 +
rm -rf .gwt-cache/
 +
rm -rf ./www/org.gcube*
 +
ant clean
 +
 
 +
#Stop Tomcat:
 +
$CATALINA_HOME/bin/shutdown.sh
 +
 
 +
#Compile the gwt project:
 +
./<ModuleName>-compile -out www/  ##### Replace the <ModuleName> with the actual one.
 +
 
 +
# Copy files from gwt project to portlet public place:
 +
mkdir webapp/html/
 +
cp -r ./www/org.gcube*/* webapp/html/
 +
 
 +
 
 +
ant compile
 +
cp -r ./build/classes/org/ webapp/WEB-INF/classes/
 +
 
 +
# Install the porltet on Tomcat:
 +
ant install
 +
 
 +
#Start Tomcat:
 +
$CATALINA_HOME/bin/startup.sh
 +
</source>
 +
 
 +
Finally, just execute this script, and the portlet will be deployed!!!
 +
<br>
 +
<br>
 +
 
 +
==Authors==
 +
[http://ddwiki.di.uoa.gr/mediawiki/index.php/User:Valia Valia Tsagkalidou]
 +
 
 +
[http://www.asidev.com/asidev/charter_members/luca_frosini.html Luca Frosini]
 +
<br>
 +
<br>
 +
 
 +
----
 +
--[[User:Valia|Valia]] 17:32, 1 March 2007 (EET)

Latest revision as of 18:04, 6 July 2016


How to write a portlet with the aim of GWT.

Pre-development Actions

Modifying Gridpshere Home

If you want you can also apply the respective changes to gridsphere's home directory. This can be useful if, for some reason, you want to redeploy gridsphere.

Installing GWT

  1. Download the latest version of GWT from here.
  2. Uzip the file.
  3. Set environmntal variable: GWT_HOME=<the name of the folder where you unpacked gwt files>

Creating a gwt-portlet

Creating a gwt project

In order to create a gwt project, you must execute:

cd $GRIDPSHERE_HOME/projects
mkdir <module_dir_name>
cd <module_dir_name>
$GWT_HOME/projectCreator -eclipse MyProject
$GWT_HOME/applicationCreator -eclipse MyProject org.gcube.<whatever>.client.<ModuleName>

Now you can develop your gwt project as you wish by using eclipse!

Writing a gwt application

You can find useful information about how to write a gwt application on the Google Web Toolkit's official site: http://code.google.com/webtoolkit/.

! IMPORTANT INFO

In the entrypoint-class, in the onModuleLoad() method: When you are about to add your widget in the main page,
instead of writing:

RootPanel.get().add(<your widget>);

you must write:

RootPanel.get(<a unique id for the DIV>).add(<your widget>);

So, the generated html will be placed in the predefined div instead of being placed in an unspecified location.

Creating a jsr 168 portlet

In oder to create an empty portlet project, you must execute:

>cd $GRIDPSHERE_HOME/
>ant new-project

  • insert: <Portlet's Title>
  • insert: <module_dir_name> -- This must be the same as in gwt project
  • insert: jsr

Now, if you refresh the eclipse project, you can see that the "portlet-files" are generated.

Creating the portlet class

  • Create a class named: org.gcube.<whatever>.portlets.<portletClassName>.
  • Add the following content to the class:
    // 	JSP folder name
    public static final String JSP_FOLDER = "/jsp";
    //	 JSP file name to be rendered on the view mode
    public static final String VIEW_JSP = JSP_FOLDER + "/<a_name_for_the_jsp_page>.jsp";
 
 
    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException{
		// ------------------------------------------------------------
		// Note: The portlet is just diplaying a JSP for the AJAX Lab.
		// It does absolutely nothing else.
		// ------------------------------------------------------------
 
 
 
    	        request.getPortletSession().setAttribute("username", request.getRemoteUser(), PortletSession.APPLICATION_SCOPE);
 
		// Invoke the JSP to render:
       		PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);
		rd.include(request,response);            
    }

Creating the jsp page

  • Create a file in the webapp/jsp directory named: <a_name_for_the_jsp_page>.jsp.
  • In this file you place the following content:
<%@ page contentType="text/html" %>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
 
<!--                                           -->
<!-- The module reference below is the link    -->
<!-- between html and your Web Toolkit module  -->		
<!--                                           -->
<script src='<%=request.getContextPath()%>/html/org.gcube.<whatever>.<ModuleName>.nocache.js'></script>
 
 
<div id="<a unique id for the DIV>">
</div>

I should mention here that the org.gcube.<whatever>.<ModuleName> is the one you defined when you created the gwt application.
Additionally, the id for the div is the one you used in the RootPanel.get() method.

Configuring the portlet

  • Modify the webapp/WEB-INF/portlet.xml file as following:

Instead of:

        <!-- place portlet description here -->
        <description xml:lang="en">This Portlet is a sample</description>
        <description xml:lang="de">Diese Portlet ist ein sample</description>
        <!-- place unique portlet name here -->
        <portlet-name>SamplePortlet</portlet-name>
        <display-name xml:lang="en">A sample Portlet</display-name>
        <display-name xml:lang="de">Ein sample Portlet</display-name>
        <!-- place your portlet class name here -->
        <portlet-class>org.gridlab.gridsphere.portlets.SamplePortlet</portlet-class>

Write:

        <!-- place portlet description here -->
        <description xml:lang="en">Your Portlet description</description>
        <!-- place unique portlet name here -->
        <portlet-name>UniquePorltetName</portlet-name>
        <display-name xml:lang="en">Portlet's Title</display-name>
        <!-- place your portlet class name here -->
        <portlet-class>>org.diligentproject.<whatever>.portlets.<portletClassName></portlet-class>

Deploying the gwt-portlet

In order to deploy the gwt-portlet you need to create a file in the main directory of your eclipse project which will contain the following:

#!/bin/bash
#This bash script compiles and deploys the gwt-portlet.
 
# Delete files from previous compilation / deployment:
rm -rf webapp/html
rm -rf webapp/WEB-INF/classes/org
rm -rf .gwt-cache/
rm -rf ./www/org.gcube*
ant clean
 
#Stop Tomcat:
$CATALINA_HOME/bin/shutdown.sh
 
#Compile the gwt project:
./<ModuleName>-compile -out www/  ##### Replace the <ModuleName> with the actual one.
 
# Copy files from gwt project to portlet public place:
mkdir webapp/html/
cp -r ./www/org.gcube*/* webapp/html/
 
 
ant compile
cp -r ./build/classes/org/ webapp/WEB-INF/classes/
 
# Install the porltet on Tomcat:
ant install
 
#Start Tomcat:
$CATALINA_HOME/bin/startup.sh

Finally, just execute this script, and the portlet will be deployed!!!

Authors

Valia Tsagkalidou

Luca Frosini


--Valia 17:32, 1 March 2007 (EET)