protected String retrieveServerResponse(String text) {
    Request req = Request.Post(getTagMeServiceUrl().toString());

    req.addHeader("Content-Type", "application/x-www-form-urlencoded");
    req.bodyForm(
        Form.form()
            .add("text", text)
            .add("gcube-token", getApiKey())
            .add("lang", getLanguageCode())
            .add("tweet", getIsTweet().toString())
            .add("include_abstract", "false")
            .add("include_categories", "false")
            .add("include_all_spots", "false")
            .add("long_text", "0")
            .add("epsilon", getEpsilon().toString())
            .build(),
        Consts.UTF_8);
    logger.debug("Request is " + req);
    Response res = null;
    try {
      res = req.execute();
    } catch (Exception ex) {
      throw new GateRuntimeException("Problem executing HTTP request: " + req, ex);
    }
    Content cont = null;
    try {
      cont = res.returnContent();
    } catch (Exception ex) {
      throw new GateRuntimeException("Problem getting HTTP response content: " + res, ex);
    }
    String ret = cont.asString();
    logger.debug("TagMe server response " + ret);
    return ret;
  }
예제 #2
0
 private String loginWith(String username, String password) throws IOException {
   return Request.Post("http://localhost:8080/session")
       .bodyForm(Form.form().add("username", username).add("password", password).build())
       .execute()
       .returnContent()
       .asString();
 }
예제 #3
0
 public Object set4(String name, Object value, Boolean unset, Boolean sync)
     throws ClientProtocolException, IOException {
   Form form =
       Form.form().add("name", name).add("sync", sync.toString()).add("session", this.session);
   if (!unset) {
     form.add("value", mapper.writeValueAsString(value));
   }
   String reply =
       Request.Post(urlBase + "/set")
           .addHeader("Authorization", auth)
           .bodyForm(form.build())
           .execute()
           .returnContent()
           .asString();
   if (!reply.equals("ok")) {
     throw new RuntimeException(reply);
   }
   return value;
 }