Test webapp

adriani.webapp.util
Class SimpleHTTPClient

java.lang.Object
  extended by adriani.webapp.util.SimpleHTTPClient

public class SimpleHTTPClient
extends java.lang.Object

Simple java client emulating a web browser. This class allows to invoke a web service using HTTP binding directly from the command line. For training reasons we use this class also in the test_client.jsp JSP page, but in that situation this client is not useful as when launched from the command line (i.e. it's not so useful to emulate a browser inside a real browser).


Field Summary
 java.lang.String action
          SOAP ACTION: NOT USED at the moment (see above)
 java.lang.String end_Tag
           
protected  java.lang.String leadingName
          Beginning of each logging message
 java.lang.String namespace
          DEFAULT VALUES
protected  boolean simple
          If true this client assume the SOAP request contains only one parameter.
protected  java.lang.String soapRequest
          Contains the complete SOAP request for web services expecting multiple input parameters.
 java.lang.String start_Tag
           
static boolean VERBOSE
          CLASS ATTRIBUTES
 
Constructor Summary
SimpleHTTPClient()
           
 
Method Summary
 java.lang.StringBuffer call(java.lang.String server, java.lang.String param)
          Call the web service.
 java.lang.StringBuffer getResponse(java.net.HttpURLConnection connection)
          Read the response from the stream bound to the connection and store it into a StringBuffer object.
 java.lang.StringBuffer getXML(java.lang.String param, boolean text)
          Produce the XML string to be used in the SOAP request message.
 void init(java.lang.String ns, java.lang.String request)
          Call the web service.
 void init(java.lang.String ns, java.lang.String tag_1, java.lang.String tag_2)
          Used to initialize this client when the SOAP request contains only one parameter.
static void main(java.lang.String[] args)
          Main method used to call the SimpleHTTPClient from the command line.
 void printRequest(java.lang.String param)
          Print the SOAP request message on the STOUT (for testing and debug purposes).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

public static boolean VERBOSE
CLASS ATTRIBUTES


namespace

public java.lang.String namespace
DEFAULT VALUES


start_Tag

public java.lang.String start_Tag

end_Tag

public java.lang.String end_Tag

simple

protected boolean simple
If true this client assume the SOAP request contains only one parameter. The parameter should be set to false when this client is run within the Tomcat container (i.e. called from a JSP page). On the opposite, if the client is executed from the command line (e.g. from the run.bat file), this parameter must be set to true!


soapRequest

protected java.lang.String soapRequest
Contains the complete SOAP request for web services expecting multiple input parameters.


leadingName

protected java.lang.String leadingName
Beginning of each logging message


action

public java.lang.String action
SOAP ACTION: NOT USED at the moment (see above)

Constructor Detail

SimpleHTTPClient

public SimpleHTTPClient()
Method Detail

main

public static void main(java.lang.String[] args)
Main method used to call the SimpleHTTPClient from the command line.


init

public void init(java.lang.String ns,
                 java.lang.String tag_1,
                 java.lang.String tag_2)
Used to initialize this client when the SOAP request contains only one parameter. In this case we load the opening and closing XML tags that will wrap around the unique parameter. By this mechanism the call(String server, String param) method will require only the parameter's value.
This method MUST NOT be used if the client must invoke a web service expecting multiple input parameters, in this case use the init(String ns, String request) method instead.

Parameters:
ns - the namespace used to define the XML elements in the service's WSDL.
tag_1 - the opening tag of the input element.
tag_2 - the closing tag of the output element.

init

public void init(java.lang.String ns,
                 java.lang.String request)
Call the web service.

Parameters:
ns - the namespace used to define the XML elements in the service's WSDL.
request - the complete SOAP request, ready to be submitted to the web service.

call

public java.lang.StringBuffer call(java.lang.String server,
                                   java.lang.String param)
Call the web service.

Parameters:
server - the URL of the target server hosting the web service.
param - the string value to be used for the main request element.

getXML

public java.lang.StringBuffer getXML(java.lang.String param,
                                     boolean text)
Produce the XML string to be used in the SOAP request message.
Remark: use \" and not \' to wrap XML attributes, in order to allow the test_client.jsp page to parse the input SOAP request using Javascript.

Parameters:
param - the string value to be used for the main request element.
text - if true the XML string is produced in user-friendly format. Use always false when producing an actual XML SOAP message.

printRequest

public void printRequest(java.lang.String param)
Print the SOAP request message on the STOUT (for testing and debug purposes).

Parameters:
the - input parameter to be wrapped in the SOAP message.

getResponse

public java.lang.StringBuffer getResponse(java.net.HttpURLConnection connection)
Read the response from the stream bound to the connection and store it into a StringBuffer object.


Build 10/01/2013

Morpheus Quality Technologies - making the Zion software
Copyright © 2009-2013 Stefano Adriani. All Rights Reserved