Graph servlet: Dynamic image generator for portal channels

xiaoxiao2021-03-06  136

Graph servlet: Dynamic image generator for portal channels

Author: Paul Lovvik and Beverly Sum

Using the Java Servlet API, you can build a variety of simple and practical utilities for the portal. For example, Graph Servlet dynamically forms data in a custom channel of Sun One Portal Server 6.

This document describes the architecture of Graph Servlet and focuses on its components and implementation. At the same time, the advantages and disadvantages of the installation and deployment process, the main implementation, and the fault diagnosis skills are discussed.

table of Contents

- Architecture - Main Components - Installation and Deployment - Dynamic Images - Cache - Advantages and Disadvantages of Architecture - Troubleshooting - References - About Authors

Architecture

The program contains three main components:

Since the Singleton struct class resides in the system class loader (Java.awt.classLoad, it shares data between Sun One Portal Server and Graph Servlet. Use the page created by JavaServerPages (JSP) in Java technology to generate channel content. Dynamically rendering the java servlet of the pie chart or bar chart.

Figure 1 illustrates the request flow in the architecture.

Figure 1: Request stream

Figure 2 shows the level of the architecture.

Figure 2: Architecture

Users communicate with channels that contain controllers. The view combines moving images with standard HTML tags. This design surrounds the following two main difficulties:

Sun One Portal Server cannot aggregate Java Servlet. The JSP page cannot generate moving images, and these images are essential for graphics utilities. (Use HTML is the only viable option), such as Time-Sheet data, often changing and needs to be continuously upgraded.

Main components

This section describes a combination of primary components-JSP pages and Java classes in the Graph Servlet.

Controller.jsp

Controller.jsp is a controller that collects information from a request, channel class (JSPROVIDER), and user profile (for storage task data). After collecting data, Controller.jsp processes, sorts, and scheders for these data to generate graphics. Specifically, Controller.jsp performs the following tasks:

The request channel name will graphically graphically, and the dimension of the image. See Code Example 1-3.

Code Example 1: Quote JSPPROVIDER

JSPPROVIDER Provider =

(Jspprovider) PageConText.gettribute "jspprovider");

ProviderContext ProviderContext = provider.getProviderContext ();

Code Example 2: Retrieve Collection Attributes from User Profiles

NewNameSandTimes =

ProviderContext.getCollectionProperty (ChannelName, "Activities");

Code Example 3: Retrieve parameters from HTTPSERVLETREQUEST

String ActivityName = (String) Request.getParameter (ChannelName "-Activity");

Note: Sun One Portal Server 6 transmits a request parameter of a channel name to all channels currently displayed. Therefore, when naming, you must use the Channel_Name-Parameter_name naming convention, for example, ActivityChannel-Activity, which can apply only each request only to a channel instead of multiple channels. Place the active data into the HashMap for modification. Place the data into an ActivityElement array for sorting and color designation. Place the data in session and Singleton to access it. Add and delete active data in a timelyly. See Code Example 4 and Code Example 5.

Code Example 4: Place the data into httpsession

Session = Request.getSession (TRUE);

Session.putValue ("Timeesheet", Elements;

Code Example 5: Place data into Singleton

DataFactory.SetData (Request, Elements);

Finally, Controller.jsp will configure the main view or display the graphical view according to the user input, and insert the tab into the generated HTML content.

Main.jsp

Main.jsp shows the following data, that is, the output of the data processed and sorted by Controller.jsp:

Display the active name and duration in the form of a table. Check boxes for selecting and deleting an active. The form used to enter or modify the current active data. Thumbnail of bar charts or pie charts; see Code Example 6.

Code Example 6: Add a thumbnail for the pie shadow

Two buttons, tags are add and delete an HTML link, the label is refresh, used to reload the main view

Graph.jsp

Graph.jsp performs the following tasks:

Determine according to the user's input is a display bar chart or a pie chart. The color object is converted to the red-green-blue (RGB) hex string for HTML. Show the following:

Depending on user input (click any one in two thumbnails in main.jsp) to display larger graphics views. Active color coding table. A label is the HTML link for Back to Main Page.

GraphServlet

GraphServlet, an Java servlet that extends the HTTPSERVLET class to perform the following tasks:

Gets drawing parameters from the URL generated from Controller.jsp: height, width, and styles. Create a framework for graphics. Get relevant data (ActivityElement array) from DataFactory and sends these data to the PIE or BAR object. Encode graphic as a GIF file. Delete Graphics and Frame objects.

Code Example 7: Collecting graphics Data from HTTPSERVLETREQUEST

Public void doget (httpservletRequest Req, httpservletResponse res)

Throws servletexception, ioException {servletoutputstream out = res. maxOutputStream ();

String width = Req.getParameter ("width");

String Height = Req.getParameter ("Height");

String style = req.getParameter ("style");

..}

Note: In UNIX systems, you can choose to start the web container from any shell, so you must grant the user to display access. See troubleshooting. Also, if the server running the portal is executing in Headless mode, you can also start the Web container using the XVFB server software.

PIE object

The PIE object passes the information from Controller.jsp to the DataFactory, and then passes to the graphservlet to present a pie chart indicating the duration of the activity. PIE objects perform two main tasks:

Calculate the duration of the activity. The total time of duration is scaled to 360 degrees using floating point conversion method and division. Specifically, the PIE object performs the following tasks:

Convert duration to integer. If there is an integer round complex error, use a method to fix it. Use a fixed degree and different colors to fill the arc, and use the Graphics method in the abstract window tool kit (java.awt. *) When filling the color. Zoom the pie chart to place it.

Bar object

Similarly, the BAR object passes the information from Controller.jsp to the DataFactory, and then passes to the graphservlet to present a bar chart indicating the duration of the activity. It implements three main tasks:

Determine the longest duration activity. Zoom bar charts make it suitable for the height and width range of the graph. Use the Graphics method in java.awt. * To populate the rectangle, color the bar chart and create a bar chart.

DataFactory object

The DataFactory object resides in the system's class-loaded data for contacting the data from Sun One Portal Server to GraphServlet. In a typical Singleton design, the DataFactory method (SETDATA) enables the data to be stored in the HashMap so that the SUN ONE IDENTITY Server's SSOTOKEN can reference these data in later GetData methods. In this way, the user has exclusive access rights and the only ID matching its data. To match multiple data to a single user, the container for all user data can be reserved in the DataFactory. Whenever DataFactory receives new data, it checks if the data ID already exists in the mapping, if there is no existence, add an entry. Since each user of Sun One Identity Server has a unique ID, the user is exclusive between the user. See Code Example 8.

Code Example 8: Setting data in the system class loader

Public Static void setData (httpservletRequest R, Object obj) {

String uniqueid = getUniqueId (r);

IF (h.get (uniqueid) == NULL) {

Try {

SrsotokenManager tokenManager =

SsotokenManager.getinstance ();

Srsotoken S = TokenManager.createssoken (R); / *

* If The user is logging in for the first time,

* DataFactory Adds a token Listener to Watch for session

* Logouts and timeouts.

* /

S.AddssokenListener (Factory);

} catch (ssoException e) {

D. Error ("SETDATA METHOD COULD NOT GET

SsotokenManager ", e);

}

}

H.PUT (UNIQUEID, OBJ);

}

If you have a large number of users to log in to the system, the performance of Sun One Portal Server may fall. To avoid this problem, simply add an event listener on SSOTOKEN to monitor changes in the session (user logout and session timeout), then delete the associated data from HashMap, enabling clearance of within Hash. See Code Example 9.

Code Example 9: Remove Data from HashMap to optimize performance

Public void ssotokenchanged (ssotokenevent evt) {

Ssotoken token = evt.getToken ();

H.Remove (token.getTokenId (). TOSTRING ());

}

The processing flow is as follows:

The content returned from Controller.jsp contains image tags. Controller.jsp invokes the data in the user profile and sends it to the DataFactory object. The browser parses the label data and requests an image from the GraphServlet, that is, the Sun One Portal Server calls Controller.jsp, and the browser requests an image from the GraphServlet.

Sterr object

The Sterr object uses the MergeSort method to order the object array in alphabetical order.

ActivityElementstringComparator object

The ActivityElementStringComparator object is used to compare the strings in the ActivityElements object array.

NamedColors object

The NamedColors object is created from the /usr/openwin/lib/rgb.txt file. NamedColors stores numerous colors by name to increase graphic code and graphic display. These colors far exceed the colors in java.awt.color to provide many color options for graphics. NamedColors provides two options to get color: static Final class variables and a static lookup method.

ActivityElement object

The ActivityElement object is used as the storage location of the data and the colors of a single activity. Each instance of ActivityElement mainly includes a set and get method. ActivityElement only performs minimum data processing, these processing are:

The setduration method accepts integer or string parameters. Controller.jsp passes the ActivityElement instance array to DataFactory, then passed to the GraphServlet, and finally passed to PIE or BAR to graphically and output.

Installation and deployment

First, download the compressed document and put it in a temporary directory, such as / TMP.

installation

Perform the following steps when installing:

Unzip the compressed document. Go to the graphing directory. Type the following command, import the portal file:% PAR import -p password -r uid - TimeTracker.par DN Channel is here: Password is a password when logging in to the portal. The UID is the name of the system administrator. DN is the name of the channel target.

Table 1 explains how to export the values ​​of the UID and DN and provide examples.

Table 1: Identification Name Name Type Value Example Uid Install_Dir / Sunwam / Lib / Amconfig.Properties File in Com.super.Identity.Authentication.super.user Settings Sun ONE Portal Server 6.0: Uid = Amadmin, Ou = People, O = Sun.com, o = ISPSun One Portal Server 6.1: Uid = Amadmin, Ou = People, DC = Sun, DC = COM DN Install_Dir / Sunwam / LIB / AMCONFIG.PROPERTIES file in the com.iplanet.am.defaultorg Settings Sun ONE Portal Server 6.0: Uid = Amadmin, Ou = People, O = Sun.com, o = ISPSun One Portal 6.1: DC = Sun, DC = COM

Note: The user interface described in the following steps is suitable for Sun One Portal Server 6.0. The UI in Sun One Portal Server 6.1 and 6.2 is slightly different.

Perform these steps to add new channels to the portal desktop:

Log in to Administration Console. Select agencies in the left panel, follow the choice of show: Services, and then click the arrow below the desktop PORTAL Server Configuration. Click Channel and Container Management under the DISPLAY profile of the right panel. In the scroll list under Container Channels, click the container you want to specify for the new channel. To place a new channel in the first tab of the sample desktop, select MyfrontPageTabPanelContainer. Select TimetrackerChannel in the scroll list of the existing channels. Click Add on the left side of the Available and Visible scroll list. Click SAVE under Channel Management. Exit Administration Console. Add the DataFactory class to the system class loader. Execute the following steps:

Create a directory for the DataFactory class:% MKDIR / OPT / DataFactory Copy the JAR file to this directory:% CP DataFactory.jar / Opt / DataFactory adds the JAR file to the ClassPath property of the system class loader. If the portal is running on the Sun One Web server, add JVM.CLASSPATH settings in the JVM12.conf file, this file is located in Install_Dir / Sunwam / Servers / https-hostname / config, the added string is :: / Opt / DataFactory / DataFactory. jar

deploy

Graph servlet resides in the Graph.war file. Deploy Graph Servlet's web apps like deploying other Web Documents (WAR) files. This process may vary depending on a different web container. If you are using the Sun One Web Server and Sun One Portal Server 6.0, run the wdeploy command in a row, as follows:% wdeploy deploy -u / graph -i instance_name -v virtual_server_name-d / opt / graphservlet graph.war, for example:% / opt / sunwam / servers / bin / https / httpadmin / bin / wdeploy deploy-u / graph -v https-gravitywell.sun.com-d / opt / graphservlet graph.war finally restarted Sun One Portal Server. Make sure the $ Display environment setting is correct and has correct access in the shell of the launch portal. Moving image

Graph servlet demonstrates the application of dynamic images in Sun One Portal Server. Sun One Portal Server receives the request to the Controller.jsp for a user request (such as a request for a new image or a revised data). If the request is a style that changes the graph, the controller.jsp will create a style parameter in the URL for main.jsp and graph.jsp. See Code Example 10.

Code Example 10: Create a style parameter

The subsequent process is as follows:

Main.jsp and graph.jsp determine which graphic style requested by the user, such as zoom in or new event. Main.jsp and graph.jsp call the SetData method in DataFactory, and send requests and data to the system class loader for later DataFactory access. DataFactory matches the requested SSOTOKEN ID and data and processes the data as an easy-to-understand object. GraphServlet calls PIE or BAR to render graphics.

The data passed to Graph Servlet is visible in the URL and contains important parameters of graphics, such as width, height, and styles.

Note: NULL value parameters will result in errors. Be sure to set the default value for the parameter.

cache

As a solution to improve performance, cache stores the most recently generated data and for subsequent requests. Graph servlet supports caches, which ensures that the channel's view can be continuous, even after refresh or after the user returns from the other content.

Advantages and disadvantages of architecture

Software solutions contain multiple tasks. Which solution is specifically adopted, depending on the "simpleness" of the code - the smaller the program is clear, the solution is getting stronger. For example, Graph servlet uses only one servlet to generate pie-shaped charts and bar charts. If you use two servlets, you will make the deployment process complicate and increase your implementation. Below is the advantages and disadvantages of graph servlet design:

JSPROVIDER Create desktop content using the JSP page with other content providers JSPROVIDER. Due to the following two main advantages, JSPPROVIDER provides a more efficient development cycle relative to other content providers (such as ProfileProvideradapter: JSPProvider provides standard scenarios from representing layer separation logic layers: JSP page files contain representations; large Most logical layers reside in the Java code of the separated class. JSPROVIDER can update the JSP page without having to restart the web server. Data and session data in the system class loader You cannot access the portal's session object, and the separated web application cannot share the same session. Re-call the session to share data between different web applications, you can store these data in the Singleton class loaded from the system class loader. Depth Integration and Shallow Integration In the architecture using shallow integrated architecture, click link to open a new browser window for the target location. The Graph Servlet uses depth integration, ie the remaining procedures are within its own channel. Therefore, when you click on the link in the Graph Servlet channel, the views within the channel change, resulting in saving of the screen content. Depth integration requires more complex implementation. However, many of its advantages can be accessed on the same desktop without having to pay additional efforts. These advantages include reducing the number of pop-ups and more stable integration of security remote access to additional products. For most Sun ONE Portal Server channels, deep integration provides a more robust user interface. Sharing data through the URL and other schemes because the graphservlet uses the parameters in the HTTPServletRequest object to receive information. This scheme is not only a simple shared data solution, but also reveals whether the data is passed correctly from one component to another component - this is the most useful clue when debugging. The advantage of using this scenario is that the user can modify the parameters in the URL, which can clearly see the URL in the browser.

Troubleshooting

You can find the clues to solve the problem in the system console or web server log. You can also start the debug process to solve the problem, the method is as follows:

Log in as root, modify /opt/sunwam/lib/amconfig.properties file. Set it to the level you need to activate debugging: Error, Warning, Message or ALL. Insert the debug statement in the debug class of the com.iplanet.am.util. *. save Changes.

Table 2 describes public error conditions and suggestions for solving problems.

Table 2: Error condition and troubleshooting skill error troubleshooting skill image cannot be displayed

See the AWT error of the web server log. If there is, it may be that the Display environment variable setting is incorrect. Check if Display is set in the terminal of the same shell or restart the web server. If there is no existence, in the terminal executed by the shell command line or the web server, type:% setENV Display Hostname: 0.0 In the default, the X server only grants the display image to the user. Make sure the root user has this permission, typing:% XHOST HOSTNAME in the shell command line or host terminal Type the following command:% xterm If the extended terminal is displayed, the permissions are correct. Verify that the URL and the image are correct. To test an image, open a new browser window and click on the image in this window instead of Sun ONE Portal Server. The graphical view destroys other portal channels that may not specify the channel name in the URL, which will cause the Sun ONE Portal Server 6 to send the request to all channels. When defining a URL (for example, the view you choose) variable, make sure the channel name is completely correct. Here is a correct URL example: 转载请注明原文地址:https://www.9cbs.com/read-127045.html


New Post(0)