openrat-java-client

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/openrat-java-client.git
Log | Files | Refs

HttpRequest.java (2797B)


      1 /*
      2 OpenRat Java-Client
      3 Copyright (C) 2009 Jan Dankert
      4  
      5 This library is free software; you can redistribute it and/or
      6 modify it under the terms of the GNU Library General Public
      7 License as published by the Free Software Foundation; either
      8 version 2 of the License, or (at your option) any later version.
      9 
     10 This library is distributed in the hope that it will be useful,
     11 but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13 Library General Public License for more details.
     14 
     15 You should have received a copy of the GNU Library General Public
     16 License along with this library; if not, write to the
     17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
     18 Boston, MA  02110-1301, USA.
     19 
     20  */
     21 package de.openrat.client.util;
     22 
     23 /**
     24  * API-Request to the OpenRat Content Management System. <br>
     25  * <br>
     26  * The call to the CMS server is done via a (non-SSL) HTTP connection.<br>
     27  * <br>
     28  * Before a call you are able to set some key/value-pairs as parameters. After
     29  * calling the CMS a DOM-document is returned, which contains the server
     30  * response.<br>
     31  * Example <br>
     32  * 
     33  * <pre>
     34  * CMSRequest request = new CMSRequest(&quot;your.openrat.example.com&quot;);
     35  * // prints tracing information to stdout.
     36  * request.trace = true;
     37  * try
     38  * {
     39  * 	request.parameter.put(&quot;action&quot;, &quot;index&quot;);
     40  * 	request.parameter.put(&quot;subaction&quot;, &quot;showlogin&quot;); // login page
     41  * 	request.parameter.put(&quot;...&quot;, &quot;...&quot;);
     42  * 	Document response = request.call();
     43  * 	// now traverse through the dom tree and get your information.
     44  * }
     45  * catch (IOException e)
     46  * {
     47  * 	// your error handling.
     48  * }
     49  * </pre>
     50  * 
     51  * @author Jan Dankert
     52  */
     53 public class HttpRequest
     54 {
     55 
     56 	public static enum HttpMethod
     57 	{
     58 
     59 		GET, POST;
     60 	}
     61 
     62 	private HttpHeaderMap requestHeader = new HttpHeaderMap();
     63 	private String payload;
     64 
     65 	/**
     66 	 * HTTP-method, must be "GET" or "POST", default: "GET".
     67 	 */
     68 	private HttpMethod method = HttpMethod.GET;
     69 
     70 	/**
     71 	 * Set the HTTP Method. Default is "GET".
     72 	 * 
     73 	 * @param method
     74 	 *            HTTP-method
     75 	 */
     76 	public void setMethod(HttpMethod method)
     77 	{
     78 
     79 		this.method = method;
     80 	}
     81 
     82 	/**
     83 	 * Inhalt des Feldes <code>payload</code>.
     84 	 * 
     85 	 * @return payload
     86 	 */
     87 	public String getPayload()
     88 	{
     89 		return payload;
     90 	}
     91 
     92 	/**
     93 	 * Setzt das Feld <code>payload</code>.
     94 	 * 
     95 	 * @param payload
     96 	 *            payload
     97 	 */
     98 	public void setPayload(String payload)
     99 	{
    100 		this.payload = payload;
    101 	}
    102 
    103 	/**
    104 	 * Inhalt des Feldes <code>requestHeader</code>.
    105 	 * 
    106 	 * @return requestHeader
    107 	 */
    108 	public HttpHeaderMap getRequestHeader()
    109 	{
    110 		return requestHeader;
    111 	}
    112 
    113 	/**
    114 	 * Inhalt des Feldes <code>method</code>.
    115 	 * 
    116 	 * @return method
    117 	 */
    118 	public HttpMethod getMethod()
    119 	{
    120 		return method;
    121 	}
    122 
    123 }