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:com.nebkat.plugin.cm.CMPlugin.java
@EventHandler @CommandFilter("download") public void onDownloadCommand(CommandEvent e) { if (e.getParams().length < 1) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + DOWNLOAD_URL); } else {/*from www .j a v a2s . c om*/ Config.Device device = null; for (List<Config.Device> devices : mConfig.devices.values()) { for (Config.Device d : devices) { if (d.code.equalsIgnoreCase(e.getParams()[0])) { device = d; break; } } } if (device == null) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Unknown device " + e.getParams()[0]); return; } HttpPost post = new HttpPost(DOWNLOAD_API_URL); GetCMApiRequest request = new GetCMApiRequest(e.getParams()[0]); StringEntity json; try { json = new StringEntity(new Gson().toJson(request)); } catch (UnsupportedEncodingException uee) { Log.wtf(TAG, uee); return; } json.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(json); // Execute the request HttpContext context = new BasicHttpContext(); HttpResponse response; try { response = ConnectionManager.getHttpClient().execute(post, context); } catch (IOException ex) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error fetching data"); return; } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error fetching data"); post.abort(); return; } try (BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent()))) { GetCMApiResults results = mGson.fromJson(reader, GetCMApiResults.class); if (results.result.size() > 0) { GetCMApiResults.Result latest = results.result.get(0); Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Latest build (" + latest.channel + ") for " + device.name + ": " + latest.url + " [" + latest.md5sum.substring(0, 6) + "]"); } else { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": No builds for " + device.name); } } catch (IOException ioe) { Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": Error fetching data"); } } }
From source file:com.dalaran.async.task.http.AbstractHTTPService.java
protected String callPostRemoteService(String url, String json) throws IOException { SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 2008)); HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(json); se.setContentEncoding(HTTP.UTF_8);//from w w w. ja v a2s . c o m // httpPost.setHeader(HTTP.USER_AGENT, URLs.USER_AGENT); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader(HTTP.CONTENT_TYPE, "application/json"); SingleClientConnManager cm = new SingleClientConnManager(httpPost.getParams(), schReg); httpPost.setEntity(se); HttpClient client = new DefaultHttpClient(); HttpResponse response = null; try { response = client.execute(httpPost); HttpEntity entity = response.getEntity(); return responseToBuffer(client, entity); } catch (Exception e) { return null; } }
From source file:com.nextgis.uikobserver.HttpSendData.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { String sPostBody = urls[0]; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://gis-lab.info:8090/"); HttpParams params = httppost.getParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); HttpContext localContext = new BasicHttpContext(); try {/*from w w w . j a v a 2s . c o m*/ StringEntity se = new StringEntity(sPostBody, "UTF8"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); httppost.setHeader("Content-type", "application/json"); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost, localContext); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean("error", false); } else { bundle.putBoolean("error", true); } bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean("error", true); bundle.putString("err_msq", mContext.getString(R.string.sNetworkUnreach)); bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }
From source file:AdminAssetCreateTest.java
@Test public void testServerCreateSimpleAsset() { running(getTestServer(), HTMLUNIT, new Callback<TestBrowser>() { public void invoke(TestBrowser browser) { serverCreateAsset();/* ww w. ja v a 2 s . c o m*/ continueOnFail(true); setHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE); setHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC); setHeader(HTTP.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); httpRequest(getURLAddress(), getMethod(), mParametersSimple); assertServer("testServerCreateSimpleAsset. Already extists", Status.BAD_REQUEST, TestConfig.MSG_ASSET_ALREADY_EXISTS, true); setHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE); setHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC); setHeader(HTTP.CONTENT_TYPE, MediaType.APPLICATION_JSON); httpRequest(getURLAddress(), getMethod(), mParametersSimple); assertServer("testServerCreateSimpleAsset. wrong media type", Status.BAD_REQUEST, null, false); continueOnFail(false); serverDeleteAsset(); } }); }
From source file:com.hujiang.restvolley.webapi.request.SimpleMultipartEntity.java
private byte[] createContentType(String type) { String result = HTTP.CONTENT_TYPE + ": " + normalizeContentType(type) + STR_CR_LF; return result.getBytes(); }
From source file:com.t2.drupalsdk.ServicesClient.java
public void post(String url, JSONObject params, AsyncHttpResponseHandler responseHandler) { StringEntity se = null;/*from ww w. j a v a2 s. c om*/ try { se = new StringEntity(params.toString()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); Log.d(TAG, "url = " + getAbsoluteUrl(url)); // Log.d(TAG, "mAsyncHttpClient = " + mAsyncHttpClient); // // TODO: change to debug - it's at error now simply for readability // HttpContext context = mAsyncHttpClient.getHttpContext(); // CookieStore store1 = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE); // Log.e(TAG, "Cookies for AsyncClient = " + store1.getCookies().toString()); mAsyncHttpClient.post(null, getAbsoluteUrl(url), se, "application/json", responseHandler); }
From source file:ch.cyberduck.core.sds.SDSWriteFeature.java
@Override public HttpResponseOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final CreateFileUploadRequest body = new CreateFileUploadRequest(); body.setParentId(Long.parseLong( new SDSNodeIdProvider(session).getFileid(file.getParent(), new DisabledListProgressListener()))); body.setName(file.getName());//from w w w.ja va 2 s .co m body.classification(DEFAULT_CLASSIFICATION); try { final CreateFileUploadResponse response = new NodesApi(session.getClient()) .createFileUpload(StringUtils.EMPTY, body); final String uploadId = response.getUploadId(); final DelayedHttpMultipartEntity entity = new DelayedHttpMultipartEntity(file.getName(), status); final DelayedHttpEntityCallable<VersionId> command = new DelayedHttpEntityCallable<VersionId>() { @Override public VersionId call(final AbstractHttpEntity entity) throws BackgroundException { try { final SDSApiClient client = session.getClient(); final HttpPost request = new HttpPost( String.format("%s/nodes/files/uploads/%s", client.getBasePath(), uploadId)); request.setEntity(entity); request.setHeader(SDSSession.SDS_AUTH_TOKEN_HEADER, StringUtils.EMPTY); request.setHeader(HTTP.CONTENT_TYPE, String.format("multipart/form-data; boundary=%s", DelayedHttpMultipartEntity.DEFAULT_BOUNDARY)); final HttpResponse response = client.getClient().execute(request); try { // Validate response switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_CREATED: // Upload complete break; default: EntityUtils.updateEntity(response, new BufferedHttpEntity(response.getEntity())); throw new SDSExceptionMappingService() .map(new ApiException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), Collections.emptyMap(), EntityUtils.toString(response.getEntity()))); } } finally { EntityUtils.consume(response.getEntity()); } final CompleteUploadRequest body = new CompleteUploadRequest(); if (status.isExists()) { body.setResolutionStrategy(CompleteUploadRequest.ResolutionStrategyEnum.OVERWRITE); } if (status.getFilekey() != null) { final ObjectReader reader = session.getClient().getJSON().getContext(null) .readerFor(FileKey.class); final FileKey fileKey = reader.readValue(status.getFilekey().array()); final EncryptedFileKey encryptFileKey = Crypto.encryptFileKey( TripleCryptConverter.toCryptoPlainFileKey(fileKey), TripleCryptConverter .toCryptoUserPublicKey(session.keyPair().getPublicKeyContainer())); body.setFileKey(TripleCryptConverter.toSwaggerFileKey(encryptFileKey)); } final Node upload = new NodesApi(client).completeFileUpload(StringUtils.EMPTY, uploadId, null, body); return new VersionId(String.valueOf(upload.getId())); } catch (IOException e) { throw new HttpExceptionMappingService().map("Upload {0} failed", e, file); } catch (ApiException e) { throw new SDSExceptionMappingService().map("Upload {0} failed", e, file); } catch (CryptoSystemException | InvalidFileKeyException | InvalidKeyPairException e) { throw new CryptoExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return entity.getContentLength(); } }; return this.write(file, status, command, entity); } catch (ApiException e) { throw new SDSExceptionMappingService().map("Upload {0} failed", e, file); } }
From source file:emcewen.websms.services.C2DMRegistrationService.java
private void registerForPush(String regID, String username) { Log.d(TAG, "Register with WebApp!"); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://sms.evanmcewen.ca/devices"); JSONObject json = new JSONObject(); TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE); try {/* w w w. j a v a 2 s . co m*/ // Add your data json.put("username", username); json.put("reg_id", regID); json.put("device_id", telephonyManager.getDeviceId()); json.put("nickname", ""); StringEntity se = new StringEntity(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); // Execute HTTP Post Request ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = httpclient.execute(httppost, responseHandler); if (response != null) { Intent successIntent = new Intent(WebSMSActivity.PUSH_SUCCESS); super.sendBroadcast(successIntent); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.neo4j.ogm.session.transaction.TransactionManager.java
private String newTransactionEndpointUrl() { logger.debug("POST {}", url); HttpPost request = new HttpPost(url); request.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8")); HttpResponse response = executeRequest(request); Header location = response.getHeaders("Location")[0]; return location.getValue(); }
From source file:UserAssetGetTest.java
@Test public void testServerDownloadAsset() { running(getTestServer(), HTMLUNIT, new Callback<TestBrowser>() { public void invoke(TestBrowser browser) { new AdminAssetCreateTest().serverCreateFileAsset(); continueOnFail(true);/*from w ww . j a va 2s . c o m*/ setHeader(HTTP.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); httpRequest(getURLAddress() + "/" + AdminAssetCreateTest.TEST_FILE_ASSET_NAME() + "/download" + "?" + TestConfig.KEY_APPCODE + "=" + TestConfig.VALUE_APPCODE, getMethod()); assertServer("testServerGetAsset", Status.OK, null, false); continueOnFail(false); new AdminAssetCreateTest().serverDeleteFileAsset(); } }); }