List of usage examples for org.apache.http.entity FileEntity FileEntity
public FileEntity(File file)
From source file:org.xmlsh.internal.commands.http.java
HttpEntity getInputEntity(Options opts) throws IOException, CoreException { AbstractHttpEntity entity = null;/*from w ww . ja v a2 s. c om*/ InputPort in = getStdin(); if (in.isFile()) entity = new FileEntity(in.getFile()); else { byte[] data = Util.readBytes(in.asInputStream(getSerializeOpts())); entity = new ByteArrayEntity(data); } // return new InputStreamEntity( in.asInputStream(mSerializeOpts),-1); if (opts.hasOpt("contentType")) entity.setContentType(opts.getOptString("contentType", "text/xml")); return entity; }
From source file:org.jmonkey.external.bintray.BintrayApiClient.java
public boolean uploadPackage(PotentialAsset potentialAsset, Asset asset, AssetVersion assetVersion) throws IOException { try (CloseableHttpClient httpClient = this.createAuthenticatedClient()) { FileEntity fileEntity = new FileEntity(new File(potentialAsset.getAssetFile())); HttpUriRequest request = RequestBuilder.put() .setUri("https://api.bintray.com/content/" + config.getSubject() + "/" + config.getRepo() + "/" + asset.getPackageName() + "/" + assetVersion.getVersion() + "/" + asset.getPackageName() + ".jar?publish=1") .setEntity(fileEntity).build(); try (CloseableHttpResponse httpResponse = httpClient.execute(request)) { if (httpResponse.getStatusLine().getStatusCode() >= 400) { return false; }/* w w w. j a v a2 s .c o m*/ return true; } } }
From source file:zswi.protocols.communication.core.HTTPSConnection.java
/** This method provides adding VCard to contacts. @param file file containing VCard/* w w w . j a va 2s . com*/ @return true if adding was successful, otherwise return false */ public boolean addVCard(File file) throws URISyntaxException, IOException { FileEntity fe = new FileEntity(file); fe.setContentType(TYPE_VCARD); return this.addVCard(fe, defaultContactsPath); }
From source file:org.dashbuilder.dataprovider.backend.elasticsearch.ElasticSearchDataSetTestBase.java
/** * <p>Index documents in bulk mode into EL server.</p> *///from w w w. j a va 2 s .co m protected static void addDocuments(CloseableHttpClient httpClient, File dataContentFile) throws Exception { HttpPost httpPost2 = new HttpPost(urlBuilder.getBulk()); FileEntity inputData = new FileEntity(dataContentFile); inputData.setContentType(CONTENTTYPE_JSON); httpPost2.addHeader(HEADER_ACCEPT, CONTENTTYPE_JSON); httpPost2.addHeader(HEADER_CONTENTTYPE, CONTENTTYPE_JSON); httpPost2.setEntity(inputData); CloseableHttpResponse dataResponse = httpClient.execute(httpPost2); if (dataResponse.getStatusLine().getStatusCode() != EL_REST_RESPONSE_OK) { System.out.println("Error response body:"); System.out.println(responseAsString(dataResponse)); } httpPost2.completed(); Assert.assertEquals(dataResponse.getStatusLine().getStatusCode(), EL_REST_RESPONSE_OK); }
From source file:com.flurry.proguard.UploadMapping.java
/** * Upload the archive to Flurry/* w w w .j a v a2 s . co m*/ * * @param file the archive to send * @param projectId the project's id * @param uploadId the the upload's id * @param token the Flurry auth token */ private static void sendToUploadService(File file, String projectId, String uploadId, String token) throws IOException { String uploadServiceUrl = String.format("%s/upload/%s/%s", UPLOAD_BASE, projectId, uploadId); List<Header> requestHeaders = getUploadServiceHeaders(file.length(), token); HttpPost postRequest = new HttpPost(uploadServiceUrl); postRequest.setEntity(new FileEntity(file)); try (CloseableHttpResponse response = executeHttpRequest(postRequest, requestHeaders)) { expectStatus(response, HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED); } finally { postRequest.releaseConnection(); } }
From source file:test.gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.selfassociation.MemberO2OUSResourceTest.java
public void testPost() throws Exception { try {//www . java 2 s . c o m DefaultHttpClient httpClient = new DefaultHttpClient(); String url = baseURL + "/rest/MemberO2OUS"; WebClient client = WebClient.create(url); HttpPost postRequest = new HttpPost(url); File myFile = new File("MemberO2OUS" + "XML.xml"); if (!myFile.exists()) { testGet(); myFile = new File("MemberO2OUS" + "XML.xml"); if (!myFile.exists()) return; } FileEntity input = new FileEntity(myFile); input.setContentType("application/xml"); System.out.println("input: " + myFile); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.onetomany.unidirectional.selfassociation.MemberO2MUSResourceTest.java
public void testPost() throws Exception { try {//www . jav a2 s .c o m DefaultHttpClient httpClient = new DefaultHttpClient(); String url = baseURL + "/rest/MemberO2MUS"; WebClient client = WebClient.create(url); HttpPost postRequest = new HttpPost(url); File myFile = new File("MemberO2MUS" + "XML.xml"); if (!myFile.exists()) { testGet(); myFile = new File("MemberO2MUS" + "XML.xml"); if (!myFile.exists()) return; } FileEntity input = new FileEntity(myFile); input.setContentType("application/xml"); System.out.println("input: " + myFile); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.operations.SpecimenCollectionGroupResourceTest.java
public void testPost() throws Exception { try {//from w ww . j a va2 s. co m DefaultHttpClient httpClient = new DefaultHttpClient(); String url = baseURL + "/rest/SpecimenCollectionGroup"; WebClient client = WebClient.create(url); HttpPost postRequest = new HttpPost(url); File myFile = new File("SpecimenCollectionGroup" + "XML.xml"); if (!myFile.exists()) { testGet(); myFile = new File("SpecimenCollectionGroup" + "XML.xml"); if (!myFile.exists()) return; } FileEntity input = new FileEntity(myFile); input.setContentType("application/xml"); System.out.println("input: " + myFile); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.selfassociation.MemberO2OUSResourceTest.java
public void testPut() throws Exception { try {//w w w . j av a 2 s.co m DefaultHttpClient httpClient = new DefaultHttpClient(); String url = baseURL + "/rest/MemberO2OUS"; HttpPut putRequest = new HttpPut(url); File myFile = new File("MemberO2OUS" + "XML.xml"); if (!myFile.exists()) { testGet(); myFile = new File("MemberO2OUS" + "XML.xml"); if (!myFile.exists()) return; } FileEntity input = new FileEntity(myFile); input.setContentType("application/xml"); putRequest.setEntity(input); HttpResponse response = httpClient.execute(putRequest); if (response.getEntity() != null) { BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:test.gov.nih.nci.cacoresdk.domain.onetomany.unidirectional.selfassociation.MemberO2MUSResourceTest.java
public void testPut() throws Exception { try {//w ww. ja v a 2 s . c om DefaultHttpClient httpClient = new DefaultHttpClient(); String url = baseURL + "/rest/MemberO2MUS"; HttpPut putRequest = new HttpPut(url); File myFile = new File("MemberO2MUS" + "XML.xml"); if (!myFile.exists()) { testGet(); myFile = new File("MemberO2MUS" + "XML.xml"); if (!myFile.exists()) return; } FileEntity input = new FileEntity(myFile); input.setContentType("application/xml"); putRequest.setEntity(input); HttpResponse response = httpClient.execute(putRequest); if (response.getEntity() != null) { BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } } httpClient.getConnectionManager().shutdown(); } catch (Exception e) { e.printStackTrace(); throw e; } }