Sybase Business Intelligence Solutions - Database Management, Data Warehousing Software, Mobile Enterprise Applications and Messaging
Sybase Brand Color Bar
delete

Search for    in all of Sybase.com
view all search results right arrow
  blank
 
 
 
 
 
 
 
 
 
 
Support > Technical Documents > Document Types > Technote > Using the Google™ Search Web Service with PowerBui...

Using the Google™ Search Web Service with PowerBuilder 9 JSPs

This technical document provides the steps needed to access the Google™ Web APIs service from a Java Server Page built with PowerBuilder 9.
 
RSS Feed
 
 
 

Step 1. Download the Google Web APIs from http://www.google.com/apis/.

The API kit includes the GoogleSearch.wsdl file (also included in the ZIP file accompanying this document), which provides the input when executing the JSP Web Service Proxy Wizard within PowerBuilder. You will also need to register with Google to obtain a license key entitling you to 1000 queries of the service per day.

Step 2. Edit the user.encoding.props found in the Shared\PowerBuilder directory (e.g., C:\Program Files\Sybase\Shared\PowerBuilder\WEB-INF\classes directory).

This user.encoding.props file is used to expose user-defined (complex) datatypes to the Sybase Universal Proxy client that is, in turn, used by the PowerBuilder-generated JSP. To supply a user-defined datatype to the Universal Proxy the following information must be provided as comma separated elements of the soap.user.encodings property:

  • The fully qualified class name of the datatype.
  • The fully qualified class name of the serializer class.
  • The fully qualified class name of the deserializer class.
  • The URI of the encoding style being used for the type.
  • The URI of the schema defining the serialization rules for the type.
The specific format of the property is:
soap.user.encodings=<datatype-class-name>,<serializer-class-name>,<deserializer-class-name>,<encoding-style-URI>,<serialization-rules-URI>

Each of the five elements of a given user-defined datatype in the soap.user.encodings property is separated by a comma (,). Additionally, the property value must contain no spaces, and if more than one datatype is specified, a semi-colon (;) is required to separate the datatype information.

Below are the various values for the specific complex types defined for the GoogleSearch API:

DirectoryCategory complex type
Datatype class nameDirectoryCategory
Serializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Deserializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Encoding style URIurn:GoogleSearch
Serialization rules URIhttp://schemas.xmlsoap.org/soap/encoding/

GoogleSearchResult complex type
Datatype class nameGoogleSearchResult
Serializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Deserializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Encoding style URIurn:GoogleSearch
Serialization rules URIhttp://schemas.xmlsoap.org/soap/encoding/

ResultElement complex type
Datatype class nameResultElement
Serializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Deserializer class namecom.sybase.esdweb.soap.encoding.BeanSerializer
Encoding style URIurn:GoogleSearch
Serialization rules URIhttp://schemas.xmlsoap.org/soap/encoding/

When specified within the user.encoding.props file, these values should appear on one line as :

soap.user.encodings= DirectoryCategory,com.sybase.esdweb.soap.encoding.BeanSerializer,com.sybase.esdweb.soap.encoding.BeanSerializer, urn:GoogleSearch,http://schemas.xmlsoap.org/soap/encoding/; GoogleSearchResult,com.sybase.esdweb.soap.encoding.BeanSerializer,com.sybase.esdweb.soap.encoding.BeanSerializer, urn:GoogleSearch,http://schemas.xmlsoap.org/soap/encoding/; ResultElement,com.sybase.esdweb.soap.encoding.BeanSerializer,com.sybase.esdweb.soap.encoding.BeanSerializer, urn:GoogleSearch,http://schemas.xmlsoap.org/soap/encoding/

Step 3. Create the Java class files corresponding to the user-defined datatypes.

These classes contain the fields of the complex datatype as private class variables as well as accessor ("getter") and mutator ("setter") methods for those class variables. The class ResultElement is shown below, and all three class files can be found in the ZIP file associated with this technical document.

public class ResultElement
{
	// Fields
	private String summary;
	private String URL;
	private String snippet;
	private String title;
	private String cachedSize;
	private boolean relatedInformationPresent;
	private String hostName;
	private DirectoryCategory directoryCategory;
	private String directoryTitle;

	// getter methods
	public String getSummary() {return summary;}
	public String getURL() {return URL;}
	public String getSnippet() {return snippet;}
	public String getTitle() {return title;}
	public String getCachedSize() {return cachedSize;}
	public boolean getRelatedInformationPresent() {return relatedInformationPresent;}
	public String getHostName() {return hostName;}
	public DirectoryCategory getDirectoryCategory() {return directoryCategory;}
	public String getDirectoryTitle() {return directoryTitle;}

	// setter methods
	public void setSummary(String x) {summary = x;}
	public void setURL(String x) {URL = x;}
	public void setSnippet(String x) {snippet = x;}
	public void setTitle(String x) {title = x;}
	public void setCachedSize(String x) {cachedSize = x;}
	public void setRelatedInformationPresent(boolean x) {relatedInformationPresent = x;}
	public void setHostName(String x) {hostName = x;}
	public void setDirectoryCategory(DirectoryCategory x) {directoryCategory = x;}
	public void setDirectoryTitle(String x) {directoryTitle = x;}
}

These classes should be placed in the C:\Program Files\Sybase\Shared\PowerBuilder\WEB-INF\classes directory so that can be located by the JSP Web Service Proxy Wizard.

Step 4. Create a PowerBuilder 9 JSP Web Target.

Use the JSP Target wizard from the File->New dialog in PowerBuilder to create a new JSP Target and provide the appropriate deployment information for the J2EE server to which the target will be deployed.

Step 5. Generate the proxy for the GoogleSearch Web Service.

Use the JSP Web Service Proxy Wizard from Web tab of the File->New dialog in PowerBuilder to generate the proxies for the GoogleSearch.wsdl file downloaded in Step 1 above. You can browse directly to the file as shown in Figure 1.


Figure 1. Specifying the GoogleSearch.wsdl file.

The next screen of the wizard (Figure 2) indicates that a single service, GoogleSearchService, is exposed by this WSDL document.


Figure 2. Service exposed by the Google Web Service.

The subsequent wizard page (Figure 3) presents the three methods available on this service:

  • doGetCachedPage
  • doSpellingSuggestion
  • doGoogleSearch

Figure 3. Methods available on the Google Web Service.

You can select those methods you wish to use from this dialog. In the sample JSP page included in this example, only doGoogleSearch is used. The next screen of the wizard (Figure 4) allows you modify the names of the return value and output variables that you will be using within your JSP code. For this example, make no modifications.


Figure 4. Return value variable name.

Next, a screen presenting the possible ports to access the service is provided (Figure 5). In this case, only one port exists; however, other Web Services may expose additional ports.


Figure 5. Ports available for invoking the Google Web Service.

The final entry screen of the wizard (Figure 6) specifies the location and name of of the JSP tag-library that is generated as the output of the wizard. You can elect to automatically include the library and the implementation classes in the PowerBuilder CLASSPATH (accessible from the Tools->System Options dialog) to support further development within the JSP editor.


Figure 6. Tag-library specifications.

Step 6. Import the user-defined datatype classes to the WEB-INF/classes directory of the Web Target

Import the three classes defined in Step 3, namely ResultElement.class, DirectoryCategory.class, and GoogleSearchResult.class, into the WEB-INF/classes directory of the JSP target within the PowerBuilder development environment. This will ensure that upon deployment the classes will be copied to the JSP server and available for use by the JSP.

Step 7. Code the JSP that accesses the GoogleSearch Web Service.

Alternatively, you can import the google.jsp file recreated below (and included in the ZIP file for this example) into your JSP Web Target. Note that you will have to enter your own license key that you received from api-support@google.com; set the declaration of key below to this value.

<%@ page import="GoogleSearchResult"   %>
<%@ page import="ResultElement"   %>
<%@ page import="DirectoryCategory"   %>
<%@ taglib uri="WEB-INF/tlds/GoogleSearchService.tld" prefix="google" %>

<HTML>
<HEAD>
    <TITLE>Google Search Example</TITLE>
</HEAD>
<BODY>
<%

        String key = "<license-key>";
        String q = "PowerBuilder 9";
        Integer start = new Integer(0);
        Integer maxResults = new Integer(10);
        Boolean filter = new Boolean(true);
        String restrict = "yes";
        Boolean safeSearch = new Boolean(true);
        String lr = "";
        String ie = "latin1";
        String oe = "latin1";


%>
<google:doGoogleSearch lr="<%= lr %>" oe="<%= oe %>" restrict="<%= restrict %>" filter="<%= filter %>"
key="<%= key %>" q="<%= q %>" maxResults="<%= maxResults %>" ie="<%= ie %>" start="<%= start %>"
safeSearch="<%= safeSearch %>" />
<%
GoogleSearchResult test = (GoogleSearchResult)GoogleSearchService_doGoogleSearch_returnValue;

        if( test != null ) {
%>
<H2>Google Search Results for "<%= q %>"</H2>
<%
            ResultElement[] details = test.getResultElements();
%>
<p><%= details.length %> items found (maximum items was set to <%= maxResults %>)</p>
<%
            for( int ndx=0; ndx < details.length; ndx++ ) {
%>
<p><B><A HREF=<%= details[ndx].getURL() %>><%= details[ndx].getTitle() %></A></B><BR>
<%= details[ndx].getSnippet() %><BR>
Size: <%= details[ndx].getCachedSize() %></p>
<%
            }
        }
%>
</BODY>
</HTML>

Step 8. Deploy the JSP Web Target to the the application server.

Use the Deploy option of the Web Target context menu in the PowerBuilder System Tree to deploy the web application to the desired J2EE server.

Step 9. Browse to the google.jsp page!

You should see a result similar to Figure 7.


Figure 7. Google JSP Web Service output.

Troubleshooting

Issue: Error when using the JSP Web Service Proxy Wizard, specifically no operations appearing for the selected service.

Possible resolution: For any extended datatypes present in the WSDL file the user.encoding.props file must be edited as defined in Step 2 above. Additionally, for the classes to be found by PowerBuilder in the development environment, make sure the classes are copied into the C:\Program Files\Sybase\Shared\PowerBuilder\WEB-INF\classes directory.

Issue: Error 500 Servlet jspservlet: unable to service request: Unable to compile class for JSPimport GoogleSearchResult; ^ import ResultElement; ^ import DirectoryCategory; ^ 3 errors

Possible resolution: Ensure that the class files to support extended datatypes have been created and compiled and can be found in the CLASSPATH for the web application. You should make sure to import these classes into the WEB-INF/classes subdirectory of your JSP Web Target within the PowerBuilder development environment before deploying the web application.

Issue: Error 500 Servlet jspservlet: unable to service request: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found.

Possible resolution: This error occurs when the xerces.jar file is not found in the web application's CLASSPATH. If your J2EE server does not include this file by default, import the file into the WEB-INF/lib directory of your JSP Web Target within the PowerBuilder development environment before deploying the web application.


For more information...

Additional information is contained in Chapter 8, Working with JSP Targets, in the Working with Web Targets manual as well as Lesson 14 from the Getting Started manual.


 

DOCUMENT ATTRIBUTES
Last Revised: Mar 31, 2003
Product: EAServer, PowerBuilder
Hardware Platform: Windows x86
Technical Topics: Java, Application Servers, Internet Application Development
  
Business or Technical: Technical
Content Id: 1024338
Infotype: Technote
 
 
 

© Copyright 2014, Sybase Inc. - v 7.6 Home / Contact Us / Help / Jobs / Legal / Privacy / Code of Ethics