/** * Constructor. */ public HttpTransport(ApplicationProxy appProxy, String strCommand) { this(); this.init(appProxy, strCommand); } /**
/** * Constructor. */ public MessageTransport(ApplicationProxy appProxy, String strCommand) { this(); this.init(appProxy, strCommand); } /**
/** * Constructor. */ public void init(ApplicationProxy appProxy, String strCommand) { super.init(appProxy, strCommand); } /**
/** * Get the URL connection's output stream (to send params to). * @return The (object) output stream. */ public ObjectOutputStream getObjectStream() { if (m_out == null) { try { URL url = this.getProxyURL(); m_servlet = new HttpMessage(url); OutputStream out = m_servlet.startMessage(m_properties); m_out = new ObjectOutputStream(out); } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } return m_out; } /**
public static final void main(String[] args) { try { MessageTransport transport = new MessageTransport(); transport.sendMessageAndGetReply(); } catch (RemoteException e) { e.printStackTrace(); } } }
this.getObjectStream(); // If there are no params in this message. InputStream in = m_servlet.endMessage(); InputStreamReader reader = new InputStreamReader(in); BufferedReader buffReader = new BufferedReader(reader);
/** * Add this method param to the param list. * (By default, uses the property method... override this to use an app specific method). * NOTE: The param name DOES NOT need to be saved, as params are always added and retrieved in order. * @param strParam The param name. * @param strValue The param value. */ public void addParam(String strParam, String strValue) { if (strValue == null) strValue = NULL; try { this.getObjectStream().writeUTF(strValue); } catch (IOException ex) { ex.printStackTrace(); } } /**
/** * Convert this java object to a String. * @param obj The java object to convert. * @return The object represented as a string. */ public String objectToString(Object obj) { String string = super.objectToString(obj); string = PropertiesTransport.encode(string); return string; } /**
/** * Convert this encoded string back to a Java Object. * @param string The string to convert. * @return The java object. */ public Object stringToObject(String string) { string = PropertiesTransport.decode(string); Object obj = super.stringToObject(string); return obj; } /**
/** * Send the request using POST. Return the input stream with the * response if the request succeeds. * @param args the arguments to send to the servlet * @exception IOException if error sending request * @return the response from the servlet to this message */ public OutputStream startMessage(Properties args) throws IOException { URL url = new URL(servlet.toExternalForm() + "?" + toEncodedString(args)); System.out.println("Open URL: " + url.toString()); m_conn = servlet.openConnection(); m_conn.setDoOutput(true); m_conn.setUseCaches(false); // POST the request data (html form encoded) return m_out = m_conn.getOutputStream(); } protected URLConnection m_conn = null;
/** * Constructor. */ public PropertiesTransport(ApplicationProxy appProxy, String strCommand) { this(); this.init(appProxy, strCommand); } /**