Ejemplo n.º 1
0
 /** Close the session. This implies closing any open methods. */
 public synchronized void close() {
   if (this.closed) return; // multiple calls ok
   while (methodList.size() > 0) {
     HTTPMethod m = methodList.get(0);
     m.close(); // forcibly close; will invoke removemethod().
   }
   closed = true;
 }
Ejemplo n.º 2
0
 static String getUrlAsString(String url) throws HTTPException {
   try (HTTPMethod m = HTTPFactory.Get(url); ) {
     int status = m.execute();
     String content = null;
     if (status == 200) {
       content = m.getResponseAsString();
     }
     return content;
   }
 }
Ejemplo n.º 3
0
 static int putUrlAsString(String content, String url) throws HTTPException {
   int status = 0;
   try {
     try (HTTPMethod m = HTTPFactory.Put(url)) {
       m.setRequestContent(
           new StringEntity(content, ContentType.create("application/text", "UTF-8")));
       status = m.execute();
     }
   } catch (UnsupportedCharsetException uce) {
     throw new HTTPException(uce);
   }
   return status;
 }