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

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

Introduction

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

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

From source file:org.qucosa.camel.component.fcrepo3.Fcrepo3APIAccess.java

public void modifyDatastream(String pid, String dsid, Boolean versionable, InputStream content)
        throws IOException {
    HttpResponse response = null;//ww  w .jav  a  2  s  .c o m
    try {
        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setContent(content);
        // Entity needs to be buffered because Fedora might reply in a way
        // forces resubmitting the entity
        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);

        URIBuilder uriBuilder = new URIBuilder(
                format(FEDORA_DATASTREAM_MODIFICATION_URI_PATTERN, host, port, pid, dsid));
        if (versionable != null) {
            uriBuilder.addParameter("versionable", String.valueOf(versionable));
        }
        URI uri = uriBuilder.build();

        HttpPut put = new HttpPut(uri);
        put.setEntity(bufferedHttpEntity);
        response = httpClient.execute(put);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException(format("Cannot modify datastream %s of object %s. Server responded: %s", dsid,
                    pid, response.getStatusLine()));
        }
    } catch (URISyntaxException e) {
        throw new IOException("Cannot ", e);
    } finally {
        consumeResponseEntity(response);
    }
}

From source file:org.eclipse.jgit.lfs.server.fs.LfsServerTest.java

protected AnyLongObjectId putContent(AnyLongObjectId id, String s) throws ClientProtocolException, IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        HttpEntity entity = new StringEntity(s, ContentType.APPLICATION_OCTET_STREAM);
        String hexId = id.name();
        HttpPut request = new HttpPut(server.getURI() + "/lfs/objects/" + hexId);
        request.setEntity(entity);
        try (CloseableHttpResponse response = client.execute(request)) {
            StatusLine statusLine = response.getStatusLine();
            int status = statusLine.getStatusCode();
            if (status >= 400) {
                throw new RuntimeException("Status: " + status + ". " + statusLine.getReasonPhrase());
            }//from  ww  w  .j av  a  2  s  .  co m
        }
        return id;
    }
}

From source file:org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerIndex.java

public OpenSearchServerIndex(HttpClient client, String documentURI, OpenSearchServerConfig config,
        RepositoryDocument document, String authorityNameString, IOutputAddActivity activities)
        throws ManifoldCFException {
    super(client, config);

    Acls acls = new Acls();
    Iterator<String> a = document.securityTypesIterator();
    if (a != null) {
        while (a.hasNext()) {
            String securityType = a.next();
            String[] convertedAcls = convertACL(document.getSecurityACL(securityType), authorityNameString,
                    activities);//from w w  w. j ava  2s. co m
            String[] convertedDenyAcls = convertACL(document.getSecurityDenyACL(securityType),
                    authorityNameString, activities);
            if (securityType.equals(RepositoryDocument.SECURITY_TYPE_DOCUMENT)) {
                acls.setDocument(convertedAcls, convertedDenyAcls);
            } else if (securityType.equals(RepositoryDocument.SECURITY_TYPE_SHARE)) {
                acls.setShare(convertedAcls, convertedDenyAcls);
            } else {
                // Don't know how to deal with it
                setResult(activities.UNKNOWN_SECURITY, Result.ERROR,
                        "Unhandled security type: " + securityType);
                return;
            }
        }
    }

    StringBuffer url = getApiUrl("update");
    HttpPut put = new HttpPut(url.toString());
    put.setEntity(new IndexRequestEntity(documentURI, document, acls));
    call(put);
    if ("OK".equals(checkXPath(xPathStatus)))
        return;
    String error = checkXPath(xPathException);
    setResult("XPATHEXCEPTION", Result.ERROR, error);
    throw new ManifoldCFException("Error, unexpected response: " + error);
}

From source file:org.apache.stratos.mock.iaas.client.rest.RestClient.java

public HttpResponse doPut(URI resourcePath, String jsonParamString) throws Exception {

    HttpPut putRequest = null;
    try {/*from ww w.  j av  a  2  s  .  c  o m*/
        putRequest = new HttpPut(resourcePath);

        StringEntity input = new StringEntity(jsonParamString);
        input.setContentType("application/json");
        putRequest.setEntity(input);

        return httpClient.execute(putRequest, new HttpResponseHandler());
    } finally {
        releaseConnection(putRequest);
    }
}

From source file:com.momock.service.HttpService.java

@Override
public HttpSession put(String url, Header[] headers, HttpEntity entity) {
    HttpPut httpPut = new HttpPut(url);
    if (entity != null)
        httpPut.setEntity(entity);
    if (headers != null)
        httpPut.setHeaders(headers);/* w ww.j  a va  2  s  .  com*/
    return new HttpSession(httpClient, httpPut, uiTaskService, asyncTaskService);
}

From source file:org.apache.stratos.kubernetes.client.rest.RestClient.java

public KubernetesResponse doPut(URI resourcePath, String jsonParamString) throws Exception {

    HttpPut putRequest = null;
    try {//w w w .j  a v  a  2s. co m
        putRequest = new HttpPut(resourcePath);

        StringEntity input = new StringEntity(jsonParamString);
        input.setContentType("application/json");
        putRequest.setEntity(input);

        return httpClient.execute(putRequest, new KubernetesResponseHandler());
    } finally {
        releaseConnection(putRequest);
    }
}

From source file:cn.com.zzwfang.http.HttpExecuter.java

@Override
public HttpResponse put(String url, RequestParams params, Header[] headers) {
    if (url == null) {
        return null;
    }// w  ww .  ja  va2  s .co m
    HttpPut httpPut = new HttpPut(url);
    if (params != null) {
        HttpEntity entity = params.getEntity();
        httpPut.setEntity(entity);
    }
    if (headers != null) {
        httpPut.setHeaders(headers);
    }
    return execute(httpPut);
}

From source file:org.eclipse.jgit.lfs.server.fs.LfsServerTest.java

protected LongObjectId putContent(Path f) throws FileNotFoundException, IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        LongObjectId id1, id2;//from   w  ww .  ja  va  2  s.  co m
        String hexId1, hexId2;
        try (DigestInputStream in = new DigestInputStream(new BufferedInputStream(Files.newInputStream(f)),
                Constants.newMessageDigest())) {
            InputStreamEntity entity = new InputStreamEntity(in, Files.size(f),
                    ContentType.APPLICATION_OCTET_STREAM);
            id1 = LongObjectIdTestUtils.hash(f);
            hexId1 = id1.name();
            HttpPut request = new HttpPut(server.getURI() + "/lfs/objects/" + hexId1);
            request.setEntity(entity);
            HttpResponse response = client.execute(request);
            checkResponseStatus(response);
            id2 = LongObjectId.fromRaw(in.getMessageDigest().digest());
            hexId2 = id2.name();
            assertEquals(hexId1, hexId2);
        }
        return id1;
    }
}

From source file:org.activiti.rest.service.api.identity.UserPictureResourceTest.java

public void testUpdatePicture() throws Exception {
    User savedUser = null;/* w ww  .  ja  va  2  s.c o m*/
    try {
        User newUser = identityService.newUser("testuser");
        newUser.setFirstName("Fred");
        newUser.setLastName("McDonald");
        newUser.setEmail("no-reply@activiti.org");
        identityService.saveUser(newUser);
        savedUser = newUser;

        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX
                + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_PICTURE, newUser.getId()));
        httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("myPicture.png", "image/png",
                new ByteArrayInputStream("this is the picture raw byte stream".getBytes()), null));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));

        Picture picture = identityService.getUserPicture(newUser.getId());
        assertNotNull(picture);
        assertEquals("image/png", picture.getMimeType());
        assertEquals("this is the picture raw byte stream", new String(picture.getBytes()));

    } finally {

        // Delete user after test passes or fails
        if (savedUser != null) {
            identityService.deleteUser(savedUser.getId());
        }
    }
}

From source file:eu.scapeproject.fcrepo.integration.PlanIT.java

private void putPlanAndAssertCreated(String planId, InputStream src, long length) throws IOException {
    /* create and ingest a test plan */
    HttpPut put = new HttpPut(SCAPE_URL + "/plan/" + planId);
    put.setEntity(new InputStreamEntity(src, length));
    HttpResponse resp = this.client.execute(put);
    assertEquals(201, resp.getStatusLine().getStatusCode());
    put.releaseConnection();/*from   ww  w. j a v a2  s.  c o m*/
}