de.cbse.jeasy
Class JEHttpClient

java.lang.Object
  extended by de.cbse.jeasy.JEHttpClient
All Implemented Interfaces:
java.lang.Runnable

public class JEHttpClient
extends java.lang.Object
implements java.lang.Runnable

The JEHttpClient is the client component of the communication with the servlet JEHttpConnector.
This communication always calls a given method at the server with one parameter.
This parameter is an XML structure holding all data used for the method. To transfer binary data you may define an attachment. Crypting and compressing data is configurable at the server.

Author:
Harry Pfohl

Field Summary
(package private)  boolean attachFlag
           
(package private)  boolean compress
           
(package private)  boolean compressFlag
           
(package private)  boolean continuedFlag
           
(package private)  boolean crypt
           
(package private)  boolean cryptFlag
           
(package private)  javax.crypto.Cipher dc
           
(package private)  javax.crypto.Cipher ec
           
(package private)  java.lang.Object httpConnector
           
(package private)  java.lang.StringBuffer httpSb
           
(package private)  java.io.InputStream in
           
(package private)  JECallBack jeClient
           
(package private)  java.security.Key k
           
(package private)  java.lang.String methodName
           
(package private)  java.io.OutputStream os
           
(package private)  java.lang.String request
           
(package private)  java.lang.String service
           
(package private)  java.lang.String session
           
(package private)  boolean simulate
           
(package private)  java.lang.String surl
           
(package private)  java.lang.String sXml
           
(package private)  java.net.URL url
           
 
Constructor Summary
JEHttpClient()
           
 
Method Summary
 java.lang.String callAndWait()
          Use this method to call the server and wait for a return.
 java.lang.String getSessionId()
          Gets the sessionId created by calling setSession();.
 java.net.URL getURL()
          Gets the URL of the server.
 boolean isAlive()
          Test if the session to to server is just alive.
 void run()
          When running as a thread this method is called when the client starts the thread.
 java.lang.String sendAttachment(java.lang.String name, java.io.ByteArrayOutputStream baos)
          Transfers bytes out of an ByteArrayOutputStream to the server and calls the service.
 java.lang.String sendAttachment(java.lang.String fileName, java.io.InputStream attachment)
          Transfers byte out of an InputStream to the server and calls the service Use this method to call the server and wait for a return.
 void setParameters(JECallBack o, java.lang.String service, java.lang.String sXml)
          Because the JEHttpClient may be run as a thread, the parameters are to be set here.
 void setParameters(JECallBack o, java.lang.String service, java.lang.String sXml, java.io.OutputStream os)
          Because the JEHttpClient is running as a thread, the parameters are to be set here.
 boolean setSession(boolean b)
          If b is true the method requests a session id from the JEHttpConnector, who will instantiate a JEDispatcher object at the server.
 void setSimulate(boolean simulate)
          Simulates the connection to JEHttpConnector by instantiating a local JEHttpConnector.
 void setSimulateParams(java.lang.String JEHttpConnectorClass, java.lang.String JEDispatcherClass, java.lang.String property)
          Sets the parameters for the server classes for simulation.
 void setURL(java.lang.String URL)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

methodName

java.lang.String methodName

service

java.lang.String service

sXml

java.lang.String sXml

surl

java.lang.String surl

request

java.lang.String request

os

java.io.OutputStream os

in

java.io.InputStream in

url

java.net.URL url

jeClient

JECallBack jeClient

session

java.lang.String session

simulate

boolean simulate

httpConnector

java.lang.Object httpConnector

httpSb

java.lang.StringBuffer httpSb

compress

boolean compress

crypt

boolean crypt

compressFlag

boolean compressFlag

cryptFlag

boolean cryptFlag

attachFlag

boolean attachFlag

continuedFlag

boolean continuedFlag

ec

javax.crypto.Cipher ec

dc

javax.crypto.Cipher dc

k

java.security.Key k
Constructor Detail

JEHttpClient

public JEHttpClient()
Method Detail

setURL

public void setURL(java.lang.String URL)
Parameters:
URL -

setSimulate

public void setSimulate(boolean simulate)
Simulates the connection to JEHttpConnector by instantiating a local JEHttpConnector. It is useful during development, because it is easy to debug the sourcecode of the server classes.

Parameters:
simulate -

setSimulateParams

public void setSimulateParams(java.lang.String JEHttpConnectorClass,
                              java.lang.String JEDispatcherClass,
                              java.lang.String property)
Sets the parameters for the server classes for simulation.

Parameters:
JEHttpConnectorClass -
JEDispatcherClass -
property -

getURL

public java.net.URL getURL()
Gets the URL of the server.

Returns:

setParameters

public void setParameters(JECallBack o,
                          java.lang.String service,
                          java.lang.String sXml)
Because the JEHttpClient may be run as a thread, the parameters are to be set here.

Parameters:
o - the JECallBack object (your JEasy client class) who's callBackInvoke method is called with the return string of the JEDispatcher
service - the service id the JEDispatcher performs. In general it is a method of JEDispatcher.
sXml - an XML string holding all parameters you need for this service. The JEDispatcher has to read XML and has to know about the tagnames

setParameters

public void setParameters(JECallBack o,
                          java.lang.String service,
                          java.lang.String sXml,
                          java.io.OutputStream os)
Because the JEHttpClient is running as a thread, the parameters are to be set here.

Parameters:
o - the JECallBack object (your JEasy client class) who's callBackInvoke method is called with the return string of the JEDispatcher
service - the service id the JEDispatcher performs. In general it is a method of JEDispatcher.
sXml - an XML string holding all parameters you need for this service. The JEDispatcher has to read XML and has to know about the tagnames
os - OutputStream to receive the attachment

isAlive

public boolean isAlive()
Test if the session to to server is just alive. After a configurable time the sessions will be closed at the server automatically.

Returns:
false if no connection to the server

setSession

public boolean setSession(boolean b)
If b is true the method requests a session id from the JEHttpConnector, who will instantiate a JEDispatcher object at the server. If b is false the session is released at the client and the server.

Parameters:
b -
Returns:
false if no connection to the server

run

public void run()
When running as a thread this method is called when the client starts the thread. The parameter service and XML are send to the JEHttpConnector who transfers them to the JEDispatcher. The response is send to the clients method callBackInvoke.

Specified by:
run in interface java.lang.Runnable

callAndWait

public java.lang.String callAndWait()
                             throws java.lang.Exception
Use this method to call the server and wait for a return. The parameter service and XML are send to the JEHttpConnector who transfers them to the JEDispatcher. The response is returned to the caller.

Returns:
Throws:
java.lang.Exception

sendAttachment

public java.lang.String sendAttachment(java.lang.String fileName,
                                       java.io.InputStream attachment)
                                throws java.lang.Exception
Transfers byte out of an InputStream to the server and calls the service Use this method to call the server and wait for a return. The parameter service and XML are send to the JEHttpConnector who transfers them to the JEDispatcher. The response is returned to the caller.

Parameters:
fileName -
attachment -
Returns:
Throws:
java.lang.Exception

sendAttachment

public java.lang.String sendAttachment(java.lang.String name,
                                       java.io.ByteArrayOutputStream baos)
                                throws java.lang.Exception
Transfers bytes out of an ByteArrayOutputStream to the server and calls the service. Use this method to call the server and wait for a return. The parameter service and XML are send to the JEHttpConnector who transfers them to the JEDispatcher. The response is returned to the caller.

Parameters:
name - name to store at the server
baos -
Returns:
name stored at the server
Throws:
java.lang.Exception

getSessionId

public java.lang.String getSessionId()
Gets the sessionId created by calling setSession();.

Returns: