Example usage for org.apache.http.client.methods HttpPatch setEntity

List of usage examples for org.apache.http.client.methods HttpPatch setEntity

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPatch setEntity.

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

From source file:org.ldp4j.server.frontend.ServerFrontendITest.java

@Test
@Category({ ExceptionPath.class })
@OperateOnDeployment(DEPLOYMENT)//  w  w w  .j  a v  a2 s . c o  m
public void testNoPatchSupport(@ArquillianResource final URL url) throws Exception {
    LOGGER.info("Started {}", testName.getMethodName());
    HELPER.base(url);
    HELPER.setLegacy(false);

    HttpPatch patch = HELPER.newRequest(MyApplication.ROOT_PERSON_CONTAINER_PATH, HttpPatch.class);
    patch.setEntity(new StringEntity(TEST_SUITE_BODY, ContentType.create("text/turtle", "UTF-8")));
    Metadata patchResponse = HELPER.httpRequest(patch);
    assertThat(patchResponse.status, equalTo(HttpStatus.SC_METHOD_NOT_ALLOWED));
    assertThat(patchResponse.body, notNullValue());
    assertThat(patchResponse.contentType, startsWith("text/plain"));
    assertThat(patchResponse.language, equalTo(Locale.ENGLISH));
}

From source file:org.fcrepo.integration.auth.webac.WebACRecipesIT.java

@Test
public void testRegisterNamespace() throws IOException {
    final String testObj = ingestObj("/rest/test_namespace");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/13/acl.ttl", "/acls/13/authorization.ttl");
    linkToAcl(testObj, acl1);/* w w  w. j a va  2s .  c  o m*/

    final String id = "/rest/test_namespace/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user13");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity(
            "PREFIX novel: <info://" + getRandomUniqueId() + ">\n" + "INSERT DATA { <> novel:value 'test' }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}

From source file:org.fcrepo.integration.auth.webac.WebACRecipesIT.java

@Test
public void testRegisterNodeType() throws IOException {
    final String testObj = ingestObj("/rest/test_nodetype");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/14/acl.ttl", "/acls/14/authorization.ttl");
    linkToAcl(testObj, acl1);/*from w  w w  . j  a  v  a 2s .c om*/

    final String id = "/rest/test_nodetype/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user14");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "INSERT DATA { <> rdf:type dc:type }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}

From source file:com.buffalokiwi.api.API.java

/**
 * Perform a patch-based request to some endpoint
 * @param url URL// w ww  .  ja v  a  2  s .  com
 * @param payload Payload to send
 * @param contentLength the length of the payload
 * @param contentType the type of data in payload 
 * @param headers additional headers to send
 * @return response
 * @throws APIException
 */
@Override
public IAPIResponse patch(final String url, final InputStream payload, final long contentLength,
        final ContentType contentType, final Map<String, String> headers) throws APIException {
    //..Create the new patch request
    final HttpPatch patch = (HttpPatch) createRequest(HttpMethod.PUT, url, headers);

    //..Set the patch payload
    patch.setEntity(new InputStreamEntity(payload, contentLength, contentType));

    APILog.trace(LOG, payload);

    //..Execute the request
    return executeRequest(patch);
}

From source file:org.fcrepo.integration.auth.webac.WebACRecipesIT.java

@Test
public void testInvalidAccessControlLink() throws IOException {
    final String id = "/rest/" + getRandomUniqueId();
    ingestObj(id);//from  www  . ja v  a2  s. c om

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "fedoraAdmin");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity(
            "INSERT { <> <" + WEBAC_ACCESS_CONTROL_VALUE + "> \"/rest/acl/badAclLink\" . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));

    final HttpGet getReq = getObjMethod(id);
    setAuth(getReq, "fedoraAdmin");
    assertEquals("Non-URI accessControl property did not throw Exception", HttpStatus.SC_BAD_REQUEST,
            getStatus(getReq));
}

From source file:com.buffalokiwi.api.API.java

/**
 * Perform a patch-based request to some endpoint
 * @param url URL/*from w  ww  .j a  v  a 2s .  com*/
 * @param file file to send 
 * @param headers additional headers 
 * @return response 
 * @throws APIException 
 */
@Override
public IAPIResponse patch(final String url, final PostFile file, Map<String, String> headers)
        throws APIException {
    final FileEntity entity = new FileEntity(file.getFile(), file.getContentType());
    if (file.hasContentEncoding())
        entity.setContentEncoding(file.getContentEncoding());

    //..Create the new patch request
    final HttpPatch patch = (HttpPatch) createRequest(HttpMethod.PUT, url, headers);

    //..Set the patch payload
    patch.setEntity(entity);

    APILog.trace(LOG, entity.toString());

    //..Execute the request
    return executeRequest(patch);

}

From source file:org.fcrepo.integration.auth.webac.WebACRecipesIT.java

@Test
public void testDeletePropertyAsUser() throws IOException {
    final String testObj = ingestObj("/rest/test_delete");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/15/acl.ttl", "/acls/15/authorization.ttl");
    linkToAcl(testObj, acl1);/*from  w w w.j a  v  a  2 s  .c  o  m*/

    final String id = "/rest/test_delete/" + getRandomUniqueId();
    ingestObj(id);

    HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user15");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "INSERT DATA { <> dc:title 'title' . " + "                <> dc:rights 'rights' . }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));

    patchReq = patchObjMethod(id);
    setAuth(patchReq, "user15");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "DELETE { <> dc:title ?any . } WHERE { <> dc:title ?any . }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));

    patchReq = patchObjMethod(id);
    setAuth(patchReq, "notUser15");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "DELETE { <> dc:rights ?any . } WHERE { <> dc:rights ?any . }"));
    assertEquals(HttpStatus.SC_FORBIDDEN, getStatus(patchReq));
}

From source file:com.buffalokiwi.api.API.java

/**
 * Perform a patch-based request to some endpoint
 * @param url URL/*from  w w w  .jav  a  2  s  .co m*/
 * @param payload Payload to send
 * @param headers additional headers to send
 * @return response
 * @throws APIException
 */
@Override
public IAPIResponse patch(final String url, final String payload, final Map<String, String> headers)
        throws APIException {
    //..Create the new patch request
    final HttpPatch patch = (HttpPatch) createRequest(HttpMethod.PATCH, url, headers);

    //..Set the patch payload
    try {
        patch.setEntity(new StringEntity(payload));

        APILog.trace(LOG, payload);

    } catch (UnsupportedEncodingException e) {
        throw new APIException("Unsupported payload encoding, cannot create StringEntity", e);
    }

    //..Execute the request
    return executeRequest(patch);
}

From source file:org.fcrepo.integration.auth.webac.WebACRecipesIT.java

/**
 * Convenience method to link a Resource to a WebACL resource
 *
 * @param protectedResource path of the resource to be protected by the
 * @param aclResource path of the Acl resource
 *//*from  w w  w  .  ja va 2s. c om*/
private void linkToAcl(final String protectedResource, final String aclResource) throws IOException {
    final HttpPatch request = patchObjMethod(protectedResource.replace(serverAddress, ""));
    setAuth(request, "fedoraAdmin");
    request.setHeader("Content-type", "application/sparql-update");
    request.setEntity(new StringEntity(
            "INSERT { <> <" + WEBAC_ACCESS_CONTROL_VALUE + "> <" + aclResource + "> . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(request));
}