This section provides the instructions for creating a custom provider by implementing the Provider interface. The process described here includes creating a sample HelloWorldProvider that prints “Hello World!” on the provider’s channel.
Create a new Java class which implements the Provider interface.
For the sample HelloWorldProvider, create the class file as shown below.
HelloWorldProviderP.java File
package custom; import java.net.URL; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sun.portal.providers.Provider; import com.sun.portal.providers.ProviderException; import com.sun.portal.providers.UnknownEditTypeException; public class HelloWorldProviderP implements Provider { public void init( String name, HttpServletRequest req ) throws ProviderException { } public StringBuffer getContent( HttpServletRequest request, HttpServletResponse response ) throws ProviderException { return new StringBuffer("Hello World!"); } public java.lang.StringBuffer getContent(java.util.Map m) throws ProviderException { return new StringBuffer("Hello, world!"); } public StringBuffer getEdit(HttpServletRequest request, HttpServletResponse response) throws ProviderException { // Get the edit page and return it is as a StringBuffer. return null; } public java.lang.StringBuffer getEdit(java.util.Map m) throws ProviderException { return null; } public int getEditType() throws UnknownEditTypeException { return 0; } public URL processEdit(HttpServletRequest request, HttpServletResponse response) throws ProviderException { return null; } public java.net.URL processEdit(java.util.Map m) throws ProviderException { return null; } public boolean isEditable() throws ProviderException { return false; } public boolean isPresentable() { return true; } public boolean isPresentable(HttpServletRequest req) { return true; } public java.lang.String getTitle() throws ProviderException { return "HelloWorld Channel"; } public java.lang.String getName() { return "HelloWorld!"; } public java.lang.String getDescription() throws ProviderException { return "This is a sample HelloWorld channel"; } public java.net.URL getHelp(javax.servlet.http.HttpServletRequest req) throws ProviderException { return null; } public long getRefreshTime() throws ProviderException { return 0; } public int getWidth() throws ProviderException { return 0; } } |
Compile the class and put it in the user defined class directory.
The default directory for the class file is PortalServer-DataDir/portals/portal-ID/desktop/classes. To compile the HelloWorldProviderP.java file, type:
javac -d PortalServer-DataDir/portals/portal-ID/desktop/classes -classpath PortalServer-base/sdk/desktop/desktopsdk.jar:AccessManager-base/lib/servlet.jar HelloWorldProviderP.java |
Define the new provider and channel definition in a temporary XML file.
The sample HelloWorldProvider provider and channel definitions are in the HelloProviderP.xml and HelloChannelP.xml files.
HelloProviderP.xml File
<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd"> <Provider name="HelloWorldProviderP" class="custom.HelloWorldProviderP"> <Properties> <String name="title" value="Hello World Channel"/> <String name="description">This is a test of the hello world provider</String> <String name="width" value="thin"/> </Properties> </Provider> |
HelloChannelP.xml File
<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd"> <Channel name="HelloWorldP" provider="HelloWorldProviderP"> <Properties> <String name="message" value="Hello World Test!!! - non-localized "/> <Locale language="en" country="US"> <String name="message" value="Hello World - I am speaking English in the United States!!!"/> </Locale> </Properties> </Channel> |
Upload the provider and channel XML fragments using the psadmin add-display-profile command.
For the sample HelloWorldProvider, upload the HelloProviderP.xml and HelloChannelP.xml XML fragments using the psadmin add-display-profile command. See the Sun Java System Portal Server 7 Command-Line Reference for more information on psadmin add-display-profile command.
Access the channel from a browser. To access, type the following URL in your browser:
http://hostname:port/portal/dt?provider=HelloWorldP |