Java Code Examples for com.google.api.client.http.HttpHeaders#setCookie()

The following examples show how to use com.google.api.client.http.HttpHeaders#setCookie() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolidUtilities.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
/** Posts an RDF model to a Solid server. **/
public String postContent(
    String url,
    String slug,
    String type,
    Model model)
    throws IOException {
  StringWriter stringWriter = new StringWriter();
  model.write(stringWriter, "TURTLE");
  HttpContent content = new ByteArrayContent("text/turtle", stringWriter.toString().getBytes());

  HttpRequest postRequest = factory.buildPostRequest(
      new GenericUrl(url), content);
  HttpHeaders headers = new HttpHeaders();
  headers.setCookie(authCookie);
  headers.set("Link", "<" + type + ">; rel=\"type\"");
  headers.set("Slug", slug);
  postRequest.setHeaders(headers);

  HttpResponse response = postRequest.execute();

  validateResponse(response, 201);
  return response.getHeaders().getLocation();
}
 
Example 2
Source File: SolidUtilities.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private void delete(String url)  {
  HttpHeaders headers = new HttpHeaders();
  headers.setAccept("text/turtle");
  headers.setCookie(authCookie);

  try {
    HttpRequest deleteRequest = factory.buildDeleteRequest(new GenericUrl(url))
        .setThrowExceptionOnExecuteError(false);
    deleteRequest.setHeaders(headers);

    validateResponse(deleteRequest.execute(), 200);
    logger.debug("Deleted: %s", url);
  } catch (IOException e) {
    throw new IllegalStateException("Couldn't delete: " + url, e);
  }
}
 
Example 3
Source File: SolidUtilities.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the contents of a URL to produce an RDF model.
 */
public Model getModel(String url) throws IOException {
  HttpRequestFactory factory = TRANSPORT.createRequestFactory();

  HttpRequest rootGetRequest = factory.buildGetRequest(
      new GenericUrl(url));
  HttpHeaders headers = new HttpHeaders();
  headers.setCookie(authCookie);
  headers.setAccept("text/turtle");
  rootGetRequest.setHeaders(headers);

  HttpResponse response = rootGetRequest.execute();
  if (response.getStatusCode() != 200) {
    throw new IOException("Unexpected return code: "
        + response.getStatusCode()
        + "\nMessage:\n"
        + response.getStatusMessage());

  }
  StringWriter writer = new StringWriter();
  IOUtils.copy(response.getContent(), writer, "UTF-8");
  String fixedString = fixProblematicPeriods(writer.toString());
  Model defaultModel = ModelFactory.createDefaultModel();
  return defaultModel.read(
      new StringReader(fixedString),
      url,
      "TURTLE");
}