CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN (Graphic web design)

CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN 349 } catch (IOException e) { System.out.println( “oop error (” + e.getMessage() + “)”); } The type NameValuePair defines an array of key value pairs that are assembled and URL- encoded into a query string. The method setQueryString converts the array into a query string. To execute the HTTP request, the method executeMethod is called. If the return code is 200, the request was successful. Because the HTTP request was successful does not mean that the response will contain any data. To know if there are any results, a parser will need to inspect the response. The undefined method processResults converts the response from an XML stream into a result that is added to the controller (further details of this method are beyond the scope of this chapter). The method getQueryIdentifieris used to identify which query identifier the result is associated with. The query identifier is part of the Persistent Communications pattern and is used to identify which query a result belongs to. Using Google to Search for Something Google allows outside developers to access their search engine technologies by using the SOAP web service API. In the example, the Java-based Axis 1.x engine was used to convert a Web Services Description Language (WSDL) file into a client stub. The client stub performs an automatic serialization of the XML data. In essence, a WSDL file does the same thing as an XML schema file used to generate a serialization stub. The serialization stub contains a number of types that are used to serialize and deserialize XML. For reference purposes, a WSDL file does contain an XML schema file. The following source code illustrates how to call the Google search engine web service: String queryIdentifier = _parent.getQueryIdentifier(); GoogleSearch searchRequest = new GoogleSearch(); if( _endPoint.length() > 0) { searchRequest.setSoapServiceURL( _endPoint); } searchRequest.setKey( _key); searchRequest.setQueryString( _request.getQueryString()); try { GoogleSearchResult searchResult = searchRequest.doSearch(); if( searchResult != null) { GoogleSearchResultElement[] results = searchResult.getResultElements(); for( int c1 = 0; c1 < results.length; c1 ++) { _parent.addResult( new SearchResult( results[ c1].getURL(), results[ c1].getTitle(), results[ c1].getSnippet(), transactionIdentifier)); } } } catch (GoogleSearchFault e) { return; }
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Leave a Reply