List of usage examples for org.apache.http.client.methods HttpPut setEntity
public void setEntity(final HttpEntity entity)
From source file:com.helger.pd.client.jdk6.PDClient.java
@Nonnull public ESuccess addServiceGroupToIndex(@Nonnull final IParticipantIdentifier aParticipantID) { ValueEnforcer.notNull(aParticipantID, "ParticipantID"); final String sParticipantID = IdentifierHelper.getIdentifierURIEncoded(aParticipantID); final HttpPut aPut = new HttpPut(m_sPDIndexerURL); aPut.setEntity(new StringEntity(sParticipantID, CCharset.CHARSET_UTF_8_OBJ)); CloseableHttpResponse aResponse = null; try {//from ww w . j a v a 2s. c o m aResponse = executeRequest(aPut); final String sResponse = _getResponseString(aResponse); // Check result if (aResponse.getStatusLine().getStatusCode() >= 200 && aResponse.getStatusLine().getStatusCode() < 300) { s_aLogger.info("Added service group '" + sParticipantID + "' to PEPPOL Directory index. May take some time until it shows up."); return ESuccess.SUCCESS; } s_aLogger.warn("Unexpected status returned from server for " + aPut.getRequestLine() + ": " + aResponse.getStatusLine() + "\n" + sResponse); } catch (final IOException ex) { s_aLogger.error("Error performing request " + aPut.getRequestLine(), ex); } finally { StreamHelper.close(aResponse); } return ESuccess.FAILURE; }
From source file:org.fashiontec.bodyapps.sync.SyncPic.java
/** * Multipart put request for images./*from w w w .java 2s .c om*/ * @param url * @param path * @return */ public HttpResponse put(String url, String path) { HttpResponse response = null; try { File file = new File(path); HttpClient client = new DefaultHttpClient(); HttpPut post = new HttpPut(url); InputStreamEntity entity = new InputStreamEntity(new FileInputStream(file.getPath()), file.length()); entity.setContentType("image/jpeg"); entity.setChunked(true); post.setEntity(entity); response = client.execute(post); } catch (IOException e) { e.printStackTrace(); } return response; }
From source file:io.fabric8.itests.basic.FabricMavenProxyTest.java
@Test public void testUpload() throws Exception { String featureLocation = System.getProperty("feature.location"); System.out.println("Testing with feature from:" + featureLocation); System.err.println(executeCommand("fabric:create -n")); Set<Container> containers = ContainerBuilder.create(2).withName("maven").withProfiles("fabric") .assertProvisioningResult().build(); try {/*from w w w .jav a2 s.co m*/ List<String> uploadUrls = new ArrayList<String>(); ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class); try { CuratorFramework curator = curatorProxy.getService(); List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload")); for (String child : children) { String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child); uploadUrls.add(uploadeUrl); } } finally { curatorProxy.close(); } //Pick a random maven proxy from the list. Random random = new Random(); int index = random.nextInt(uploadUrls.size()); String targetUrl = uploadUrls.get(index); String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml"; System.out.println("Using URI: " + uploadUrl); DefaultHttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(uploadUrl); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin")); FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml"); put.setEntity(entity); HttpResponse response = client.execute(put); System.err.println("Response:" + response.getStatusLine()); Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202); System.err.println( executeCommand("fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default")); System.err.println(executeCommand("fabric:profile-edit --features example-cbr default")); Provision.containerStatus(containers, PROVISION_TIMEOUT); } finally { ContainerBuilder.destroy(containers); } }
From source file:org.apache.camel.itest.osgi.cxf.blueprint.CxfRsBlueprintRouterTest.java
@Test public void testPutConsumer() throws Exception { HttpPut put = new HttpPut("http://localhost:9000/route/customerservice/customers"); StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1"); entity.setContentType("text/xml; charset=ISO-8859-1"); put.setEntity(entity); HttpClient httpclient = new DefaultHttpClient(); try {/*from w w w .java 2 s . co m*/ HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("", EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:org.ldp4j.server.frontend.JAXRSFrontendITest.java
@Test @Category({ REST.class, PUT.class, ExceptionPath.class }) @OperateOnDeployment(DEPLOYMENT)// w w w . j ava2s. c o m public void testUnsupportedContentTypeException(@ArquillianResource final URL url) throws Exception { String path = "resource/unsupportedContent/mediaType"; CreateEndpoint command = CommandHelper.newCreateEndpointCommand(path, "templateId").modifiable(true) .withContent(EXAMPLE_BODY).build(); HELPER.base(url); HELPER.executeCommand(command); HttpPut action = HELPER.newRequest(path, HttpPut.class); action.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); action.setEntity(DUMMY_ENTITY); HELPER.httpRequest(action); }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.util.TavernaRestAPI.java
public int callPutMethodRC(String xmlString) { int statusCode = 0; try {//from w w w . j a v a 2s.co m //HttpGet method = new HttpGet(url); StringEntity inputKeyspace = new StringEntity(xmlString); Logger.getLogger(TavernaRestAPI.class.getName()).log(Level.INFO, "Connection .. " + url); HttpPut request = new HttpPut(url); request.addHeader("content-type", "application/xml; charset=utf-8"); request.addHeader("Accept", "application/xml, multipart/related"); request.setEntity(inputKeyspace); HttpResponse methodResponse = this.getHttpClient().execute(request); statusCode = methodResponse.getStatusLine().getStatusCode(); Logger.getLogger(TavernaRestAPI.class.getName()).log(Level.INFO, "Status Code: " + statusCode); // System.out.println("Response String: " + result.toString()); } catch (Exception ex) { } return statusCode; }
From source file:com.linkedin.multitenant.db.ProxyDatabase.java
@Override public DatabaseResult doInsert(Query q) { HttpPut put = new HttpPut(m_connStr + q.getKey()); ByteArrayEntity bae = new ByteArrayEntity(q.getValue()); bae.setContentType("octet-stream"); put.setEntity(bae); try {//from w ww .j ava 2 s.c om @SuppressWarnings("unused") String responseBody = m_client.execute(put, m_handler); return DatabaseResult.OK; } catch (Exception e) { m_log.error("Error in executing doInsert", e); return DatabaseResult.FAIL; } }
From source file:com.linkedin.multitenant.db.ProxyDatabase.java
@Override public DatabaseResult doUpdate(Query q) { HttpPut put = new HttpPut(m_connStr + q.getKey()); ByteArrayEntity bae = new ByteArrayEntity(q.getValue()); bae.setContentType("octet-stream"); put.setEntity(bae); try {// ww w. j a v a2s. c o m @SuppressWarnings("unused") String responseBody = m_client.execute(put, m_handler); return DatabaseResult.OK; } catch (Exception e) { m_log.error("Error in executing doUpdate", e); return DatabaseResult.FAIL; } }
From source file:org.apache.nifi.api.client.impl.AbstractNiFiAPIClient.java
/** * Invokes the NiFi PUT REST API commands. * * @param resourceClass/* www . j a v a 2 s . c om*/ * @param nifiApiMethod * @param u * @param <U> * @return */ public <U extends Entity> Object put(Class<? extends ApplicationResource> resourceClass, Method nifiApiMethod, U u) { StringBuilder stringBuilder = new StringBuilder(this.baseUrl); stringBuilder.append(resourceClass.getAnnotation(Path.class).value()); stringBuilder.append("/"); stringBuilder.append(nifiApiMethod.getAnnotation(Path.class).value()); //String fullRequest = replaceUriWithPathParams(stringBuilder.toString(), pathParams); String fullRequest = stringBuilder.toString(); HttpPut request = new HttpPut(fullRequest); try { StringEntity input = new StringEntity(mapper.writeValueAsString(u)); request.setEntity(input); // add request header request.addHeader("Accept", "application/json"); request.setHeader("Content-type", "application/json"); HttpResponse response = client.execute(request); return mapper.readValue(response.getEntity().getContent(), nifiApiMethod.getAnnotation(ApiOperation.class).response()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.sharetask.controller.WorkspaceControllerIT.java
@Test public void testUpdateWorkspace() throws IOException { //given//from w w w . j av a 2 s.c o m final HttpPut httpPut = new HttpPut(URL_WORKSPACE); httpPut.addHeader(new BasicHeader("Content-Type", "application/json")); final StringEntity httpEntity = new StringEntity( "{\"id\":7," + "\"title\":\"Test Title\"," + "\"owner\":{\"username\":\"dev1@shareta.sk\"}" + "}"); httpPut.setEntity(httpEntity); //when final HttpResponse response = getClient().execute(httpPut); //then Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode()); final String responseData = EntityUtils.toString(response.getEntity()); Assert.assertTrue(responseData.contains("\"title\":\"Test Title\"")); }