You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/08/08 22:52:25 UTC
svn commit: r1155096 -
/incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java
Author: andy
Date: Mon Aug 8 20:52:25 2011
New Revision: 1155096
URL: http://svn.apache.org/viewvc?rev=1155096&view=rev
Log: (empty)
Modified:
incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java
Modified: incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java?rev=1155096&r1=1155095&r2=1155096&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java (original)
+++ incubator/jena/Scratch/AFS/trunk/src/riot/web/HttpOp.java Mon Aug 8 20:52:25 2011
@@ -60,16 +60,21 @@ public class HttpOp
static private Logger log = LoggerFactory.getLogger(HttpOp.class) ;
- private static AtomicLong counter = new AtomicLong(0) ; // help debugging.
+ static private AtomicLong counter = new AtomicLong(0) ;
/** General act-on-HTTP-response */
public static interface HttpResponseHandler { void handle(String contentType, String baseIRI, HttpResponse response) throws IOException ; }
+
/** Act-on-HTTP-response and produce some object */
public static interface HttpCaptureResponse<T> extends HttpOp.HttpResponseHandler { public T get() ; }
- /** Interface for sendign content over HTTP POST */
- public static interface ContentProducer extends org.apache.http.entity.ContentProducer {} ;
- /** GET with unecoded query string */
+ /** Interface for sending content over HTTP POST */
+ public static interface ContentProducer extends org.apache.http.entity.ContentProducer {}
+
+ /** GET with unecoded query string.
+ * See {@link #execHttpGet(String, String, Map)} for additional details.
+ * <p>The query string wil be encoded as needed and appended to the URL, inserting a "?".
+ */
public static void execHttpGet(String url, String queryString, String acceptHeader, Map<String, HttpResponseHandler> handlers)
{
try {
@@ -82,7 +87,13 @@ public class HttpOp
}
}
- /** GET */
+ /** GET
+ * <p>The acceptHeader string is any legal value for HTTP Accept: field.
+ * <p>The handlers are the set of content types (without charset),
+ * used to dispatch the response body for handling.
+ * <p>A Map entry of ("*",....) is used "no handler found".
+ * <p>HTTP responses 400 and 500 become exceptions.
+ */
public static void execHttpGet(String url, String acceptHeader, Map<String, HttpResponseHandler> handlers)
{
try {
@@ -109,15 +120,22 @@ public class HttpOp
}
}
- // TEMP : need to split into setup-content-response or pass in a source
-
- /** POST a string without response body */
+ /** POST a string without response body.
+ * <p>Execute an HTTP POST, with the string as content.
+ * <p>No response content expected or processed.
+ */
+ //TODO Use MediaType
public static void execHttpPost(String url, String contentType, String content)
{
execHttpPost(url, contentType, content, null, null) ;
}
- /** POST without response body */
+ /** POST without response body.
+ * Content read from the the input stream.
+ * <p>Execute an HTTP POST, with the string as content.
+ * <p>No response content expected or processed.
+ */
+ //TODO Use MediaType
public static void execHttpPost(String url, String contentType,
InputStream input, int length)
{
@@ -125,30 +143,34 @@ public class HttpOp
}
- /** POST a string, expect a response body */
+ /** POST a string, expect a response body.*/
public static void execHttpPost(String url,
String contentType, String content,
String acceptType, Map<String, HttpResponseHandler> handlers)
{
- HttpEntity e = null ;
+ StringEntity e = null ;
try
{
e = new StringEntity(content, "UTF-8") ;
- execHttpPost(url, contentType, e, acceptType, handlers) ;
+ execHttpPost(url, e, acceptType, handlers) ;
} catch (UnsupportedEncodingException e1)
{
throw new ARQInternalErrorException("Platform does not support required UTF-8") ;
} finally { closeEntity(e) ; }
}
- /** POST with response body */
+ /** POST with response body.
+ * The input stream is assumed to be UTF-8.
+ */
public static void execHttpPost(String url, String contentType,
InputStream input, int length,
String acceptType, Map<String, HttpResponseHandler> handlers)
{
- HttpEntity e = new InputStreamEntity(input, length) ;
- execHttpPost(url, contentType, e, acceptType, handlers) ;
+ InputStreamEntity e = new InputStreamEntity(input, length) ;
+ e.setContentType(contentType) ;
+ e.setContentEncoding("UTF-8") ;
+ execHttpPost(url, e, acceptType, handlers) ;
}
/** POST with response body */
@@ -156,13 +178,17 @@ public class HttpOp
String contentType, ContentProducer provider,
String acceptType, Map<String, HttpResponseHandler> handlers)
{
- HttpEntity entity = new EntityTemplate(provider);
- execHttpPost(url, contentType, entity, acceptType, handlers) ;
+ EntityTemplate entity = new EntityTemplate(provider) ;
+ entity.setContentType(contentType) ;
+ execHttpPost(url, entity, acceptType, handlers) ;
}
- /** POST with response body */
+ /** POST with response body.
+ * <p>The content for the POST body comes from the HttpEntity.
+ * <p>The response is handled bythe handler map, as per {@link #execHttpGet(String, String, Map)}
+ */
public static void execHttpPost(String url,
- String contentType, HttpEntity provider,
+ HttpEntity provider,
String acceptType, Map<String, HttpResponseHandler> handlers)
{
try {
@@ -174,14 +200,9 @@ public class HttpOp
if ( log.isDebugEnabled() )
log.debug(format("[%d] %s %s",id ,httppost.getMethod(),httppost.getURI().toString())) ;
- if ( contentType != null )
- httppost.setHeader(HttpNames.hContentType, contentType) ;
- else
+ if ( provider.getContentType() == null )
log.debug(format("[%d] No content type")) ;
-// if ( length >= 0 )
-// httppost.setHeader(HttpNames.hContentLengh, Integer.toString(length)) ;
-
// Execute
HttpClient httpclient = new DefaultHttpClient();
httppost.setEntity(provider) ;