mev-4.0.01/source/org/tigr/remote/protocol/communication/http/HttpTransport.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: HttpTransport.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.4 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 21:00:01 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.remote.protocol.communication.http;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.io.IOException;
2 26 Feb 07 jari 15 import java.io.InputStream;
2 26 Feb 07 jari 16 import java.io.OutputStream;
2 26 Feb 07 jari 17
2 26 Feb 07 jari 18 import org.tigr.remote.RemoteException;
2 26 Feb 07 jari 19 import org.tigr.remote.protocol.communication.RequestMessage;
2 26 Feb 07 jari 20 import org.tigr.remote.protocol.communication.ResponseMessage;
2 26 Feb 07 jari 21 import org.tigr.remote.protocol.communication.Transport;
2 26 Feb 07 jari 22 import org.tigr.util.ConfMap;
2 26 Feb 07 jari 23
2 26 Feb 07 jari 24 class HttpTransport implements Transport {
2 26 Feb 07 jari 25
2 26 Feb 07 jari 26     /**
2 26 Feb 07 jari 27      * Construct a <code>HttpTransport</code> with specified configuration.
2 26 Feb 07 jari 28      */
2 26 Feb 07 jari 29     public HttpTransport( ConfMap config ) throws RemoteException {
2 26 Feb 07 jari 30         m_config = config;
2 26 Feb 07 jari 31         try {
2 26 Feb 07 jari 32             m_communicator = new HttpCommunicator2(  config  );
2 26 Feb 07 jari 33         } catch (Exception ex) {
2 26 Feb 07 jari 34             throw new RemoteException("HttpTransport: bad server URL ", ex);
2 26 Feb 07 jari 35         }
2 26 Feb 07 jari 36     }
2 26 Feb 07 jari 37
2 26 Feb 07 jari 38     /**
2 26 Feb 07 jari 39      * Send a request message to a server.
2 26 Feb 07 jari 40      */
2 26 Feb 07 jari 41     public RequestMessage sendRequest( RequestMessage msg ) throws RemoteException {
2 26 Feb 07 jari 42         try {
2 26 Feb 07 jari 43             OutputStream out =  m_communicator.send( msg.getProperties() );
2 26 Feb 07 jari 44             msg.setStream( out );
2 26 Feb 07 jari 45             return msg;
2 26 Feb 07 jari 46         } catch (IOException ex) {
2 26 Feb 07 jari 47             throw new RemoteException("HttpTransport: cannot send request: " + ex.toString(), ex);
2 26 Feb 07 jari 48         }
2 26 Feb 07 jari 49     }
2 26 Feb 07 jari 50
2 26 Feb 07 jari 51     /**
2 26 Feb 07 jari 52      * Returns the response message from a server.
2 26 Feb 07 jari 53      */
2 26 Feb 07 jari 54     public ResponseMessage getResponse() throws RemoteException {
2 26 Feb 07 jari 55         try {
2 26 Feb 07 jari 56             InputStream in =  m_communicator.receive();
2 26 Feb 07 jari 57             ResponseMessage msg = new ResponseMessage("Server", "TIGR-MEV", in);
2 26 Feb 07 jari 58             return msg;
2 26 Feb 07 jari 59         } catch (IOException ex) {
2 26 Feb 07 jari 60             throw new RemoteException("HttpTransport: cannot receive response. " + ex.toString(), ex);
2 26 Feb 07 jari 61         }
2 26 Feb 07 jari 62     }
2 26 Feb 07 jari 63
2 26 Feb 07 jari 64     /**
2 26 Feb 07 jari 65      * Clean up used resources after data was sent.
2 26 Feb 07 jari 66      */
2 26 Feb 07 jari 67     public void finalizeSend() throws RemoteException {
2 26 Feb 07 jari 68         try {
2 26 Feb 07 jari 69             m_communicator.cleanupAfterSend();
2 26 Feb 07 jari 70         } catch (IOException ex) {
2 26 Feb 07 jari 71             throw new RemoteException("HttpTransport: Server error. Cannot start job: " + ex.toString(), ex);
2 26 Feb 07 jari 72         }
2 26 Feb 07 jari 73     }
2 26 Feb 07 jari 74
2 26 Feb 07 jari 75     /**
2 26 Feb 07 jari 76      * Clean up resources after data was received.
2 26 Feb 07 jari 77      */
2 26 Feb 07 jari 78     public void finalizeReceive() throws RemoteException {
2 26 Feb 07 jari 79         try {
2 26 Feb 07 jari 80             m_communicator.cleanupAfterReceive();
2 26 Feb 07 jari 81         } catch (IOException ex) {
2 26 Feb 07 jari 82             throw new RemoteException("HttpTransport: cannot finalize receiving: " + ex.toString(), ex);
2 26 Feb 07 jari 83         }
2 26 Feb 07 jari 84     }
2 26 Feb 07 jari 85
2 26 Feb 07 jari 86     protected ConfMap m_config;
2 26 Feb 07 jari 87     protected HttpCommunicator2 m_communicator;
2 26 Feb 07 jari 88 }