List of usage examples for org.apache.http.protocol HTTP CONTENT_TYPE
String CONTENT_TYPE
To view the source code for org.apache.http.protocol HTTP CONTENT_TYPE.
Click Source Link
From source file:org.neo4j.ogm.drivers.http.transaction.HttpTransaction.java
@Override public void commit() { try {/* ww w.java 2 s . c o m*/ if (transactionManager.canCommit()) { HttpPost request = new HttpPost(url + "/commit"); request.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8")); request.setHeader(new BasicHeader("X-WRITE", driver.readOnly() ? "0" : "1")); driver.executeHttpRequest(request); } } catch (Exception e) { throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.commit(); // must always be done to keep extension depth correct } }
From source file:com.subgraph.vega.internal.http.proxy.ResponseContentCustom.java
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }//from w w w . ja v a2 s .c o m ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) { response.removeHeaders(HTTP.CONTENT_LEN); response.setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else if (len >= 0) { response.removeHeaders(HTTP.TRANSFER_ENCODING); response.setHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); } // Specify a content type if known if (entity.getContentType() != null && !response.containsHeader(HTTP.CONTENT_TYPE)) { response.addHeader(entity.getContentType()); } // Specify a content encoding if known if (entity.getContentEncoding() != null && !response.containsHeader(HTTP.CONTENT_ENCODING)) { response.addHeader(entity.getContentEncoding()); } } else { int status = response.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED && status != HttpStatus.SC_RESET_CONTENT) { response.setHeader(HTTP.CONTENT_LEN, "0"); } } }
From source file:org.alfresco.utils.HttpUtil.java
/** * Populate HTTP message call with given content. * // w w w. j a va2s. c om * @param json {@link JSONObject} content * @return {@link StringEntity} content. * @throws UnsupportedEncodingException if unsupported */ public static StringEntity setMessageBody(final JSONObject json) throws UnsupportedEncodingException { if (json == null || json.toString().isEmpty()) { throw new IllegalArgumentException("JSON Content is required."); } StringEntity se = setMessageBody(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, MIME_TYPE_JSON)); if (logger.isDebugEnabled()) { logger.debug("Json string value: " + se); } return se; }
From source file:com.scvngr.levelup.core.net.request.factory.LocationCreditRequestFactoryTest.java
/** * Tests building a location credit request. *//*ww w .j a v a 2 s .c om*/ @SmallTest public void testBuildLocationCreditRequest_noToken() throws AbstractRequest.BadRequestException, IOException { final LocationCreditRequestFactory builder = new LocationCreditRequestFactory(getContext(), new MockAccessTokenRetriever(null)); final AbstractRequest request = builder .buildLocationCreditRequest(LocationFixture.getFullModel(LOCATION_ID_FIXTURE)); assertNotNull(request); final URL url = request.getUrl(getContext()); assertTrue("hits /locations/:id/credit endpoint", url.getPath().contains("/locations/")); assertTrue("hits /locations/:id/credit endpoint", url.getPath().contains("/credit")); assertFalse(request.getRequestHeaders(getContext()).containsKey(LevelUpRequest.HEADER_AUTHORIZATION)); assertEquals(RequestUtils.HEADER_CONTENT_TYPE_JSON, request.getRequestHeaders(getContext()).get(HTTP.CONTENT_TYPE)); assertEquals(HttpMethod.GET, request.getMethod()); assertTrue(url.getPath().startsWith("/v15")); }
From source file:org.wso2.carbon.core.transports.util.InfoProcessor.java
public void process(CarbonHttpRequest request, CarbonHttpResponse response, ConfigurationContext configurationContext) throws Exception { String requestURI = request.getRequestURI(); String contextPath = configurationContext.getServiceContextPath(); String serviceName = requestURI.substring(requestURI.indexOf(contextPath) + contextPath.length() + 1); AxisService axisService = configurationContext.getAxisConfiguration().getServiceForActivation(serviceName); if (axisService == null) { // Try to see whether the service is available in a tenant axisService = TenantAxisUtils.getAxisService(serviceName, configurationContext); }/* w ww .j av a 2s .c o m*/ if (!RequestProcessorUtil.canExposeServiceMetadata(axisService)) { response.setError(HttpStatus.SC_FORBIDDEN, "Access to service metadata for service: " + serviceName + " has been forbidden"); return; } String serviceHtml = ServiceHTMLProcessor.printServiceHTML(serviceName, configurationContext); if (serviceHtml != null) { response.setStatus(HttpStatus.SC_OK); response.addHeader(HTTP.CONTENT_TYPE, "text/html"); response.getOutputStream().write(serviceHtml.getBytes()); } }
From source file:com.myfp.httpmime_lib.MultipartEntity.java
public MultipartEntity(HttpMultipartMode mode, String boundary, final Charset charset) { super();/*from ww w .j av a 2 s . c om*/ if (boundary == null) { boundary = generateBoundary(); } this.multipart = new HttpMultipart("form-data", charset, boundary); this.contentType = new BasicHeader(HTTP.CONTENT_TYPE, generateContentType(boundary, charset)); this.dirty = true; if (mode == null) { mode = HttpMultipartMode.STRICT; } this.multipart.setMode(mode); }
From source file:com.sparkplatform.api.core.ConnectionApacheHttp.java
private static void setData(HttpEntityEnclosingRequestBase r, String body) throws SparkAPIClientException { HttpEntity data;//from w w w .j a v a2 s.c o m try { data = new StringEntity(body); ((StringEntity) data).setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); r.setEntity(data); } catch (UnsupportedEncodingException e) { throw new SparkAPIClientException( "Message cannot be sent as the body is encoded in an unsupported format.", e); } }
From source file:com.photon.phresco.nativeapp.eshop.net.HttpRequest.java
/** * Send the JSON data to specified URL and get the httpResponse back * * @param sURL// w ww. j av a 2 s .c o m * @param jObject * @return InputStream * @throws IOException */ public static InputStream post(String sURL, JSONObject jObject) throws IOException { HttpResponse httpResponse = null; InputStream is = null; PhrescoLogger.info(TAG + " post: " + sURL); PhrescoLogger.info(TAG + " jObject: " + jObject); HttpPost httpPostRequest = new HttpPost(sURL); HttpEntity entity; httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader(HTTP.CONTENT_TYPE, "application/json"); httpPostRequest.setEntity(new ByteArrayEntity(jObject.toString().getBytes("UTF-8"))); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = TIME_OUT; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = TIME_OUT; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); httpResponse = httpClient.execute(httpPostRequest); if (httpResponse != null) { entity = httpResponse.getEntity(); is = entity.getContent(); } return is; }
From source file:com.example.testwebservice2.TestWebserviceActivity.java
private void putRequest() { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(URL); try {//from www. jav a 2 s.com byte[] b = beanConvertXml().getBytes("utf-8"); InputStream is = new ByteArrayInputStream(b, 0, b.length); InputStreamEntity re = new InputStreamEntity(is, is.available());//ContentType.create(XmlContentType, WPCharset) re.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, XmlContentType)); httpPost.setEntity(re); HttpResponse response = httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { // getEntity String result = EntityUtils.toString(response.getEntity()); System.out.println("result:" + result); Toast.makeText(TestWebserviceActivity.this, "result:" + response.getStatusLine().getStatusCode() + result, Toast.LENGTH_SHORT).show(); } System.out.println("response " + response.getEntity()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.codice.alliance.nsili.endpoint.requests.FtpDestinationSink.java
@Override public void writeFile(InputStream fileData, long size, String name, String contentType, List<Metacard> metacards) throws IOException { CloseableHttpClient httpClient = null; String urlPath = protocol + "://" + fileLocation.host_name + ":" + port + "/" + fileLocation.path_name + "/" + name;//from w w w .ja v a 2 s .c om LOGGER.debug("Writing ordered file to URL: {}", urlPath); try { HttpPut putMethod = new HttpPut(urlPath); putMethod.addHeader(HTTP.CONTENT_TYPE, contentType); HttpEntity httpEntity = new InputStreamEntity(fileData, size); putMethod.setEntity(httpEntity); if (StringUtils.isNotEmpty(fileLocation.user_name) && fileLocation.password != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(fileLocation.host_name, port), new UsernamePasswordCredentials(fileLocation.user_name, fileLocation.password)); httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); } else { httpClient = HttpClients.createDefault(); } httpClient.execute(putMethod); fileData.close(); putMethod.releaseConnection(); } finally { if (httpClient != null) { httpClient.close(); } } }