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:io.openkit.OKHTTPClient.java
private static StringEntity getJSONString(JSONObject jsonObject) { StringEntity sEntity = null;// w ww. j a v a2s .c o m try { sEntity = new StringEntity(jsonObject.toString(), HTTP.UTF_8); sEntity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); return sEntity; } catch (UnsupportedEncodingException e) { return null; } }
From source file:UserAssetGetTest.java
@Test public void testServerGetAsset() { running(getTestServer(), HTMLUNIT, new Callback<TestBrowser>() { public void invoke(TestBrowser browser) { new AdminAssetCreateTest().serverCreateAsset(); continueOnFail(true);/*from www . j a v a 2 s .c om*/ setHeader(HTTP.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); httpRequest(getURLAddress() + "/" + AdminAssetCreateTest.TEST_ASSET_NAME() + "/data" + "?" + TestConfig.KEY_APPCODE + "=" + TestConfig.VALUE_APPCODE, getMethod()); assertServer("testServerGetAsset", Status.OK, null, true); continueOnFail(false); new AdminAssetCreateTest().serverDeleteAsset(); } }); }
From source file:com.tomgibara.android.veecheck.VeecheckThread.java
private VeecheckResult performRequest(VeecheckVersion version, String uri) throws ClientProtocolException, IOException, IllegalStateException, SAXException { HttpClient client = new DefaultHttpClient(); // TODO ideally it should be possible to adjust these constants HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT); HttpGet request = new HttpGet(version.substitute(uri)); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); try {//from w ww .ja v a 2 s.c o m StatusLine line = response.getStatusLine(); // TODO this is lazy, we should consider other codes here if (line.getStatusCode() != 200) { throw new IOException("Request failed: " + line.getReasonPhrase()); } Header header = response.getFirstHeader(HTTP.CONTENT_TYPE); Encoding encoding = identityEncoding(header); VeecheckResult handler = new VeecheckResult(version); Xml.parse(entity.getContent(), encoding, handler); return handler; } finally { entity.consumeContent(); } }
From source file:org.wso2.carbon.core.transports.util.AbstractWsdlProcessor.java
protected void printWSDL(ConfigurationContext configurationContext, String serviceName, CarbonHttpResponse response, WSDLPrinter wsdlPrinter) throws IOException { AxisConfiguration axisConfig = configurationContext.getAxisConfiguration(); AxisService axisService = axisConfig.getServiceForActivation(serviceName); if (axisService == null) { // Try to see whether the service is available in a tenant axisService = TenantAxisUtils.getAxisService(serviceName, configurationContext); if (axisService != null) { axisConfig = TenantAxisUtils.getTenantAxisConfiguration( TenantAxisUtils.getTenantDomain(serviceName), configurationContext); }/*from ww w. j a va 2 s . c o m*/ } if (GhostDeployerUtils.isGhostService(axisService) && axisConfig != null) { String serviceGroupName = null; if (axisService != null) { if (axisService.getAxisServiceGroup() != null) { serviceGroupName = axisService.getAxisServiceGroup().getServiceGroupName(); } else { serviceGroupName = axisService.getName(); } } if (CarbonUtils.isDepSyncEnabled() && CarbonUtils.isWorkerNode() && GhostDeployerUtils.isPartialUpdateEnabled()) { GhostDispatcherUtils.handleDepSynchUpdate(axisConfig, axisService); } // if the existing service is a ghost service, deploy the actual one axisService = GhostDeployerUtils.deployActualService(axisConfig, axisService); // we have to call the metadata deployer to avoid any qos settings are not // getting applied GhostDispatcherUtils.deployServiceMetaFile(serviceGroupName, axisConfig); } String hideAdminServiceWSDLs = CarbonCoreDataHolder.getInstance().getServerConfigurationService() .getFirstProperty( CarbonConstants.AXIS2_CONFIG_PARAM + "." + CarbonConstants.HIDE_ADMIN_SERVICE_WSDLS); OutputStream outputStream = response.getOutputStream(); if (axisService != null) { if (SystemFilter.isFilteredOutService(axisService) && "true".equals(hideAdminServiceWSDLs)) { response.setError(HttpStatus.SC_FORBIDDEN, "Access to service metadata for service: " + serviceName + " has been forbidden"); return; } if (!RequestProcessorUtil.canExposeServiceMetadata(axisService)) { response.setError(HttpStatus.SC_FORBIDDEN, "Access to service metadata for service: " + serviceName + " has been forbidden"); return; } if (!axisService.isActive()) { response.addHeader(HTTP.CONTENT_TYPE, "text/html"); outputStream .write(("<h4>Service " + serviceName + " is inactive. Cannot display WSDL document.</h4>") .getBytes()); outputStream.flush(); } else { response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); wsdlPrinter.printWSDL(axisService); } } else { response.addHeader(HTTP.CONTENT_TYPE, "text/html"); outputStream.write( ("<h4>Service " + serviceName + " not found. Cannot display WSDL document.</h4>").getBytes()); response.setError(HttpStatus.SC_NOT_FOUND); outputStream.flush(); } }
From source file:cn.isif.util_plus.http.client.multipart.MultipartEntity.java
/** * @param multipartSubtype default "form-data" *///ww w .j av a2s . c o m public void setMultipartSubtype(String multipartSubtype) { this.multipartSubtype = multipartSubtype; this.multipart.setSubType(multipartSubtype); this.contentType = new BasicHeader(HTTP.CONTENT_TYPE, generateContentType(this.boundary, this.charset)); }
From source file:dk.kk.ibikecphlib.util.HttpUtils.java
public static JsonNode postToServer(String urlString, JSONObject objectToPost) { JsonNode ret = null;//from w ww . j av a 2 s . co m LOG.d("POST api request, url = " + urlString + " object = " + objectToPost.toString()); HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT); HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT); HttpClient httpclient = new DefaultHttpClient(myParams); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT); HttpPost httppost = null; URL url = null; try { url = new URL(urlString); httppost = new HttpPost(url.toString()); httppost.setHeader("Content-type", "application/json"); httppost.setHeader("Accept", ACCEPT); httppost.setHeader("LANGUAGE_CODE", IBikeApplication.getLanguageString()); StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);// , HTTP.UTF_8 se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); String serverResponse = EntityUtils.toString(response.getEntity()); LOG.d("API response = " + serverResponse); ret = Util.stringToJsonNode(serverResponse); } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) { LOG.e(e.getLocalizedMessage()); } } return ret; }
From source file:com.googlecode.osde.internal.igoogle.IgHostingUtil.java
/** * Uploads a file to iGoogle.//from ww w . j a v a 2 s .c om * * @throws IgException */ public static void uploadFile(IgCredentials igCredentials, String sourceFileRootPath, String sourceFileRelativePath, String hostingFolder) throws IgException { // Prepare HttpPost. String httpPostUrl = URL_IG_GADGETS_FILE + igCredentials.getPublicId() + hostingFolder + sourceFileRelativePath + "?et=" + igCredentials.getEditToken(); logger.fine("httpPostUrl: " + httpPostUrl); HttpPost httpPost = new HttpPost(httpPostUrl); File sourceFile = new File(sourceFileRootPath, sourceFileRelativePath); String httpContentType = isTextExtensionForGadgetFile(sourceFileRelativePath) ? HTTP_PLAIN_TEXT_TYPE : HTTP.DEFAULT_CONTENT_TYPE; httpPost.setHeader(HTTP.CONTENT_TYPE, httpContentType); FileEntity fileEntity = new FileEntity(sourceFile, httpContentType); logger.fine("fileEntity length: " + fileEntity.getContentLength()); httpPost.setEntity(fileEntity); // Add cookie headers. Cookie PREF must be placed before SID. httpPost.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "PREF=" + igCredentials.getPref()); httpPost.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "SID=" + igCredentials.getSid()); // Execute request. HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpPost); } catch (ClientProtocolException e) { throw new IgException(e); } catch (IOException e) { throw new IgException(e); } // Verify if the file is created. StatusLine statusLine = httpResponse.getStatusLine(); logger.fine("statusLine: " + statusLine); if (HttpStatus.SC_CREATED != statusLine.getStatusCode()) { String response = IgHttpUtil.retrieveHttpResponseAsString(httpClient, httpPost, httpResponse); throw new IgException("Failed file-upload with status line: " + statusLine.toString() + ",\nand response:\n" + response); } }
From source file:com.manning.androidhacks.hack023.net.HttpHelper.java
private static String doGet(String url, String contentType, String requestBodyString, ResponseHandler<String> responseHandler) throws IOException, ClientProtocolException { if (requestBodyString != null) { url += "?" + requestBodyString; }/*from w w w . j a va 2 s .c o m*/ Log.d(TAG, "URL: " + url); HttpGet getRequest = new HttpGet(url); getRequest.setHeader(HTTP.CONTENT_TYPE, contentType); getRequest.setHeader(ACCEPT, contentType); return mHttpClient.execute(getRequest, responseHandler); }
From source file:anhttpclient.impl.HttpWebResponse.java
/** * {@inheritDoc}// w ww .jav a 2 s. com */ public String getContentType() { for (Map.Entry<String, String> entry : responseHeaders.entrySet()) { if (HTTP.CONTENT_TYPE.equalsIgnoreCase(entry.getKey())) { return entry.getValue(); } } return null; }