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.apache.manifoldcf.agents.output.solr.ModifiedMultipartEntity.java
/** * Creates an instance using the specified parameters * @param mode the mode to use, may be {@code null}, in which case {@link HttpMultipartMode#STRICT} is used * @param boundary the boundary string, may be {@code null}, in which case {@link #generateBoundary()} is invoked to create the string * @param charset the character set to use, may be {@code null}, in which case {@link MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used. *//*from www.j av a 2 s . c o m*/ public ModifiedMultipartEntity(HttpMultipartMode mode, String boundary, Charset charset) { super(); if (boundary == null) { boundary = generateBoundary(); } if (mode == null) { mode = HttpMultipartMode.STRICT; } this.multipart = new ModifiedHttpMultipart("form-data", charset, boundary, mode); this.contentType = new BasicHeader(HTTP.CONTENT_TYPE, generateContentType(boundary, charset)); this.dirty = true; }
From source file:com.googlecode.osde.internal.igoogle.IgCredentials.java
private IgCredentials(String username, String password) throws IgException { // Retrieve sid. // TODO: Support captcha. sid = retrieveSid(username, password, null, null); validateSid();/* ww w.j av a2s . c o m*/ // Retrieve publidId. publicId = retrievePublicId(sid); validatePublicId(); // Prepare HttpGet for retrieving pref and editToken. HttpGet httpGet = new HttpGet(URL_IG_PREF_EDIT_TOKEN); httpGet.setHeader(HTTP.CONTENT_TYPE, HTTP.PLAIN_TEXT_TYPE); httpGet.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "SID=" + sid); HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpGet); } catch (ClientProtocolException e) { throw new IgException(e); } catch (IOException e) { throw new IgException(e); } logger.fine("status line: " + httpResponse.getStatusLine()); // Retrieve pref from headers. pref = retrievePref(httpResponse); validatePref(); // Retrieve editToken from response content. editToken = retrieveEditToken(httpClient, httpGet, httpResponse); validateEditToken(); }
From source file:org.opendaylight.alto.manager.AltoManager.java
protected boolean httpPut(String url, String data) throws IOException { HttpPut httpPut = new HttpPut(url); httpPut.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE); httpPut.setEntity(new StringEntity(data)); logHttpRequest("HTTP PUT:", url, data); HttpResponse response = httpClient.execute(httpPut); return handleResponse(response); }
From source file:org.neo4j.ogm.session.transaction.TransactionManager.java
public void commit(Transaction tx) { String url = tx.url() + "/commit"; logger.debug("POST {}", url); HttpPost request = new HttpPost(url); request.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8")); executeRequest(request);/*from ww w. j a v a 2 s. c o m*/ }
From source file:com.osamashabrez.clientserver.json.ClientServerJSONActivity.java
/** Called when the activity is first created. */ @Override/*w w w . jav a 2 s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); buildref = (EditText) findViewById(R.id.editTextbuild); buildref.setFocusable(false); buildref.setClickable(false); recvdref = (EditText) findViewById(R.id.editTextrecvd); recvdref.setFocusable(false); recvdref.setClickable(false); JSONObject jsonobj; // declared locally so that it destroys after serving its purpose jsonobj = new JSONObject(); try { // adding some keys jsonobj.put("key", "value"); jsonobj.put("weburl", "hashincludetechnology.com"); // lets add some headers (nested headers) JSONObject header = new JSONObject(); header.put("devicemodel", android.os.Build.MODEL); // Device model header.put("deviceVersion", android.os.Build.VERSION.RELEASE); // Device OS version header.put("language", Locale.getDefault().getISO3Language()); // Language jsonobj.put("header", header); // Display the contents of the JSON objects buildref.setText(jsonobj.toString(2)); } catch (JSONException ex) { buildref.setText("Error Occurred while building JSON"); ex.printStackTrace(); } // Now lets begin with the server part try { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppostreq = new HttpPost(wurl); StringEntity se = new StringEntity(jsonobj.toString()); //se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); se.setContentType("application/json;charset=UTF-8"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8")); httppostreq.setEntity(se); // httppostreq.setHeader("Accept", "application/json"); // httppostreq.setHeader("Content-type", "application/json"); // httppostreq.setHeader("User-Agent", "android"); HttpResponse httpresponse = httpclient.execute(httppostreq); HttpEntity resultentity = httpresponse.getEntity(); if (resultentity != null) { InputStream inputstream = resultentity.getContent(); Header contentencoding = httpresponse.getFirstHeader("Content-Encoding"); if (contentencoding != null && contentencoding.getValue().equalsIgnoreCase("gzip")) { inputstream = new GZIPInputStream(inputstream); } String resultstring = convertStreamToString(inputstream); inputstream.close(); resultstring = resultstring.substring(1, resultstring.length() - 1); recvdref.setText(resultstring + "\n\n" + httppostreq.toString().getBytes()); // JSONObject recvdjson = new JSONObject(resultstring); // recvdref.setText(recvdjson.toString(2)); } } catch (Exception e) { recvdref.setText("Error Occurred while processing JSON"); recvdref.setText(e.getMessage()); } }
From source file:ch.cyberduck.core.http.AbstractHttpWriteFeature.java
public HttpResponseOutputStream<T> write(final Path file, final TransferStatus status, final DelayedHttpEntityCallable<T> command, final DelayedHttpEntity entity) throws BackgroundException { // Signal on enter streaming final CountDownLatch entry = entity.getEntry(); final CountDownLatch exit = new CountDownLatch(1); try {/*from w w w. j av a 2 s . c om*/ if (StringUtils.isNotBlank(status.getMime())) { entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, status.getMime())); } else { entity.setContentType(MimeTypeService.DEFAULT_CONTENT_TYPE); } final FutureHttpResponse target = new FutureHttpResponse() { @Override public void run() { try { if (status.isCanceled()) { throw new ConnectionCanceledException(); } response = command.call(entity); } catch (BackgroundException e) { exception = e; } finally { // For zero byte files #writeTo is never called and the entry latch not triggered entry.countDown(); // Continue reading the response exit.countDown(); } } }; final ThreadFactory factory = new NamedThreadFactory(String.format("http-%s", file.getName())); final Thread t = factory.newThread(target); t.start(); // Wait for output stream to become available entry.await(); if (null != target.getException()) { if (target.getException() instanceof BackgroundException) { throw (BackgroundException) target.getException(); } throw new DefaultExceptionMappingService().map(target.getException()); } final OutputStream stream = entity.getStream(); return new HttpResponseOutputStream<T>(stream) { @Override public void flush() throws IOException { stream.flush(); } /** * Only available after this stream is closed. * @return Response from server for upload */ @Override public T getStatus() throws BackgroundException { try { if (status.isCanceled()) { throw new ConnectionCanceledException(); } // Block the calling thread until after the full response from the server // has been consumed. exit.await(); } catch (InterruptedException e) { throw new DefaultExceptionMappingService().map(e); } if (null != target.getException()) { if (target.getException() instanceof BackgroundException) { throw (BackgroundException) target.getException(); } throw new DefaultExceptionMappingService().map(target.getException()); } return target.getResponse(); } }; } catch (InterruptedException e) { log.warn(String.format("Error waiting for output stream for %s", file)); throw new DefaultExceptionMappingService().map(e); } }
From source file:ch.cyberduck.core.googledrive.DriveReadFeature.java
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try {/* ww w . ja v a2s. c o m*/ if (file.getType().contains(Path.Type.placeholder)) { final DescriptiveUrl link = new DriveUrlProvider().toUrl(file).find(DescriptiveUrl.Type.http); if (DescriptiveUrl.EMPTY.equals(link)) { log.warn(String.format("Missing web link for file %s", file)); return new NullInputStream(file.attributes().getSize()); } // Write web link file return IOUtils.toInputStream(UrlFileWriterFactory.get().write(link), Charset.defaultCharset()); } else { final String base = session.getClient().getRootUrl(); final HttpUriRequest request = new HttpGet(String.format( String.format("%%s/drive/v3/files/%%s?alt=media&supportsTeamDrives=%s", PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")), base, new DriveFileidProvider(session).getFileid(file, new DisabledListProgressListener()))); request.addHeader(HTTP.CONTENT_TYPE, MEDIA_TYPE); if (status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if (-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if (log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } request.addHeader(new BasicHeader(HttpHeaders.RANGE, header)); // Disable compression request.addHeader(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } final HttpClient client = session.getHttpClient(); final HttpResponse response = client.execute(request); switch (response.getStatusLine().getStatusCode()) { case HttpStatus.SC_OK: case HttpStatus.SC_PARTIAL_CONTENT: return new HttpMethodReleaseInputStream(response); default: throw new DriveExceptionMappingService().map(new HttpResponseException( response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase())); } } } catch (IOException e) { throw new DriveExceptionMappingService().map("Download {0} failed", e, file); } }
From source file:fi.mikuz.boarder.connection.ConnectionManager.java
public ConnectionManager(ConnectionListener connectionListener, final String url, final HashMap<String, String> sendList) { this.connectionListener = connectionListener; Thread t = new Thread() { public void run() { JSONObject json = new JSONObject(); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); if (sendList != null) { for (String key : sendList.keySet()) { json.put(key, sendList.get(key)); }/*w w w. java 2 s . co m*/ } json.put(InternetMenu.HTML_FILTER, false); StringEntity se = new StringEntity(json.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Sending to " + url + ": " + json.toString()); HttpResponse response = httpclient.execute(httppost); InputStream in = response.getEntity().getContent(); //Get the data in the entity String result = convertStreamToString(in); try { if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Got from " + url + ": " + result); else Log.v(TAG, "Got answer from " + url); connectionSuccessfulResponse = new ConnectionSuccessfulResponse(new JSONObject(result), ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionSuccessful); } catch (JSONException e) { Log.e(TAG, "Couldn't convert to JSON object", e); connectionErrorResponse = new ConnectionErrorResponse(Html.fromHtml(result).toString(), url); mHandler.post(connectionError); } } catch (Exception e) { String error = "Cannot establish connection"; Log.e(TAG, error); connectionErrorResponse = new ConnectionErrorResponse(error, ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionError); } } }; t.start(); }