List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java
/** This method should be used for sending files back to AppVet. */ public static boolean sendInNewHttpRequest(String appId, String reportFilePath, ToolStatus reportStatus) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 30000); HttpConnectionParams.setSoTimeout(httpParameters, 1200000); HttpClient httpClient = new DefaultHttpClient(httpParameters); httpClient = SSLWrapper.wrapClient(httpClient); try {/*from w ww . ja va 2 s . com*/ /* * To send reports back to AppVet, the following parameters must be * sent: - command: SUBMIT_REPORT - username: AppVet username - * password: AppVet password - appid: The app ID - toolid: The ID of * this tool - toolrisk: The risk assessment (LOW, MODERATE, HIGH, * ERROR) - report: The report file. */ MultipartEntity entity = new MultipartEntity(); entity.addPart("command", new StringBody("SUBMIT_REPORT", Charset.forName("UTF-8"))); entity.addPart("username", new StringBody(Properties.appvetUsername, Charset.forName("UTF-8"))); entity.addPart("password", new StringBody(Properties.appvetPassword, Charset.forName("UTF-8"))); entity.addPart("appid", new StringBody(appId, Charset.forName("UTF-8"))); entity.addPart("toolid", new StringBody(Properties.toolId, Charset.forName("UTF-8"))); entity.addPart("toolrisk", new StringBody(reportStatus.name(), Charset.forName("UTF-8"))); File report = new File(reportFilePath); FileBody fileBody = new FileBody(report); entity.addPart("file", fileBody); HttpPost httpPost = new HttpPost(Properties.appvetUrl); httpPost.setEntity(entity); // Send the report to AppVet log.debug("Sending report file to AppVet"); final HttpResponse response = httpClient.execute(httpPost); log.debug("Received from AppVet: " + response.getStatusLine()); HttpEntity httpEntity = response.getEntity(); InputStream is = httpEntity.getContent(); String result = IOUtils.toString(is, "UTF-8"); log.info(result); // Clean up httpPost = null; return true; } catch (Exception e) { log.error(e.toString()); return false; } }
From source file:com.book.jtm.chap03.HttpClientDemo.java
private static HttpParams defaultHttpParams() { HttpParams mDefaultParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(mDefaultParams, 10000); HttpConnectionParams.setSoTimeout(mDefaultParams, 15000); HttpConnectionParams.setTcpNoDelay(mDefaultParams, true); // ?false// w w w . j a v a 2s . co m HttpConnectionParams.setStaleCheckingEnabled(mDefaultParams, false); // ??? HttpProtocolParams.setVersion(mDefaultParams, HttpVersion.HTTP_1_1); // ?? HttpProtocolParams.setUseExpectContinue(mDefaultParams, true); return mDefaultParams; }
From source file:com.geeksville.location.LeonardoUpload.java
/** * Upload a flight to Leonardo//w w w .j a v a 2 s . c om * * @param username * @param password * @param postURL * @param shortFilename * @param igcFile * we will take care of closing this stram * @return null for success, otherwise a string description of the problem * @throws IOException */ public static String upload(String username, String password, String postURL, int competitionClass, String shortFilename, String igcFile, int connectionTimeout, int operationTimeout) throws IOException { // Strip off extension (leonado docs say they don't want it int i = shortFilename.lastIndexOf('.'); if (i >= 1) shortFilename = shortFilename.substring(0, i); String sCompetitionClass = String.valueOf(competitionClass); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeout); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, operationTimeout); HttpClient httpclient = new DefaultHttpClient(httpParameters); httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); HttpPost httppost = new HttpPost(postURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("user", username)); nameValuePairs.add(new BasicNameValuePair("pass", password)); nameValuePairs.add(new BasicNameValuePair("igcfn", shortFilename)); nameValuePairs.add(new BasicNameValuePair("Klasse", sCompetitionClass)); nameValuePairs.add(new BasicNameValuePair("IGCigcIGC", igcFile)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); String resp = EntityUtils.toString(entity); // An error looks like: // <html><body>problem<br>This is not a valid .igc // file</body></html> // Check for success if (resp.contains("flight scored")) resp = null; else { int bodLoc = resp.indexOf("<body>"); if (bodLoc >= 0) resp = resp.substring(bodLoc + 6); int probLoc = resp.indexOf("problem"); if (probLoc >= 0) resp = resp.substring(probLoc + 7); if (resp.startsWith("<br>")) resp = resp.substring(4); int markLoc = resp.indexOf('<'); if (markLoc >= 0) resp = resp.substring(0, markLoc); resp = resp.trim(); } return resp; }
From source file:org.odk.voice.storage.InstanceUploader.java
public int uploadInstance(int instanceId) { // configure connection HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT); HttpClientParams.setRedirecting(params, false); // setup client DefaultHttpClient httpclient = new DefaultHttpClient(params); HttpPost httppost = new HttpPost(serverUrl); MultipartEntity entity = new MultipartEntity(); // using file storage // // get instance file // File instanceDir = new File(instancePath); ////w ww. j a v a 2s . c o m // // find all files in parent directory // File[] files = instanceDir.listFiles(); // if (files == null) { // log.warn("No files to upload in " + instancePath); // } // mime post // for (int j = 0; j < files.length; j++) { // File f = files[j]; // if (f.getName().endsWith(".xml")) { // // uploading xml file // entity.addPart("xml_submission_file", new FileBody(f,"text/xml")); // log.info("added xml file " + f.getName()); // } else if (f.getName().endsWith(".wav")) { // // upload audio file // entity.addPart(f.getName(), new FileBody(f, "audio/wav")); // log.info("added audio file" + f.getName()); // } else { // log.info("unsupported file type, not adding file: " + f.getName()); // } // } // using database storage DbAdapter dba = null; try { dba = new DbAdapter(); byte[] xml = dba.getInstanceXml(instanceId); if (xml == null) { log.error("No XML for instanceId " + instanceId); return STATUS_ERROR; } entity.addPart("xml_submission_file", new InputStreamBody(new ByteArrayInputStream(xml), "text/xml")); List<InstanceBinary> binaries = dba.getBinariesForInstance(instanceId); for (InstanceBinary b : binaries) { entity.addPart(b.name, new InputStreamBody(new ByteArrayInputStream(b.binary), b.mimeType, b.name)); } } catch (SQLException e) { log.error("SQLException uploading instance", e); return STATUS_ERROR; } finally { dba.close(); } httppost.setEntity(entity); // prepare response and return uploaded HttpResponse response = null; try { response = httpclient.execute(httppost); } catch (ClientProtocolException e) { log.error(e); return STATUS_ERROR; } catch (IOException e) { log.error(e); return STATUS_ERROR; } catch (IllegalStateException e) { log.error(e); return STATUS_ERROR; } // check response. // TODO: This isn't handled correctly. String responseUrl = null; Header[] h = response.getHeaders("Location"); if (h != null && h.length > 0) { responseUrl = h[0].getValue(); } else { log.error("Location header was absent"); return STATUS_ERROR; } int responseCode = response.getStatusLine().getStatusCode(); log.info("Response code:" + responseCode); // verify that your response came from a known server if (responseUrl != null && serverUrl.contains(responseUrl) && responseCode == 201) { return STATUS_OK; } return STATUS_ERROR; }
From source file:net.swas.explorer.httpprofile.Profile.java
/** * @param fileName fileName of HTTP dump file * @param context context is for capturing the knowledge base configuration. * @return boolean/*from w ww . ja v a2s . c o m*/ * @throws IOException * @throws HttpException * @throws SQLException */ public static boolean parseRequestByFile(String fileName, ServletContext context) throws IOException, HttpException, SQLException { log.info("In Parse Request by file"); boolean check = false; HttpMessageParser requestParser; List<HttpRequest> request = new ArrayList<HttpRequest>(); @SuppressWarnings("resource") BufferedReader br = new BufferedReader(new FileReader(fileName)); List<String> requestList = new ArrayList<String>(); String requestString = ""; String line = ""; line = br.readLine(); int i = 0; while (line != null) { if (line.startsWith("GET") || line.startsWith("POST")) { if (i == 0) { i = 1; } else { requestList.add(requestString); } requestString = ""; requestString = " " + requestString + line + "\r\n"; } else { if (line.contains(":")) { requestString = requestString + line + "\r\n"; } else if (!line.equals("")) { requestString = requestString + "SSRG: " + line + "\r\n"; } } line = br.readLine(); } for (String string : requestList) { SessionInputBuffer inbuffer = new FileInputBuffer(string, 1024, new BasicHttpParams()); requestParser = HttpRequestParser.createRequestParser(inbuffer, new DefaultHttpRequestFactory(), new BasicHttpParams()); HttpRequest httpRequest = HttpRequestParser.receiveRequestHeaderByFile(requestParser); request.add(httpRequest); } ArrayList<String> urls = null; DOProfile profile = new DOProfile(context); profile.insertRequest(request); log.info("Rquest Inserted"); urls = (ArrayList<String>) profile.getUrl(); if (urls.size() > 0) { check = true; profile.insertPairs(urls); } else { check = false; } log.info("Pairs inserted"); return check; }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static HttpClient getHttpClient() { HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 28000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 28000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); return new DefaultHttpClient(httpParameters); }
From source file:com.makotosan.vimeodroid.ApplicationEx.java
private HttpClient createHttpClient() { // Log.d(TAG, "createHttpClient()..."); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpProtocolParams.setUserAgent(params, "Vimeo Droid"); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); }
From source file:com.dimasdanz.kendalipintu.util.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { try {//www.j av a 2 s. com HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParameters, so_timeout); HttpConnectionParams.setConnectionTimeout(httpParameters, co_timeout); if (method == "POST") { DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (SocketTimeoutException e) { Log.e("SocketTimeoutException", "SocketTimeoutException"); e.printStackTrace(); return null; } catch (UnsupportedEncodingException e) { Log.e("UnsupportedEncodingException", "UnsupportedEncodingException"); e.printStackTrace(); return null; } catch (ClientProtocolException e) { Log.e("ClientProtocolException", "ClientProtocolException"); e.printStackTrace(); return null; } catch (IOException e) { Log.e("IOException", "IOException"); e.printStackTrace(); return null; } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Buffer Error : " + e.toString()); return null; } try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); return null; } return jObj; }
From source file:com.vinaysshenoy.easyoauth.http.HttpManager.java
private void initHttpClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUserAgent(params, mHttpConfig.userAgent); HttpProtocolParams.setVersion(params, mHttpConfig.httpVersion); HttpProtocolParams.setContentCharset(params, mHttpConfig.contentCharset); HttpConnectionParams.setStaleCheckingEnabled(params, mHttpConfig.enableStaleChecking); HttpConnectionParams.setConnectionTimeout(params, mHttpConfig.connectionTimeout); HttpConnectionParams.setSoTimeout(params, mHttpConfig.socketTimeout); HttpConnectionParams.setSocketBufferSize(params, mHttpConfig.socketBufferSize); HttpClientParams.setRedirecting(params, mHttpConfig.isRedirecting); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(/* w ww. j av a 2s. c o m*/ new Scheme(HttpConfig.KEY_HTTP, PlainSocketFactory.getSocketFactory(), mHttpConfig.httpPort)); schemeRegistry.register( new Scheme(HttpConfig.KEY_HTTPS, SSLSocketFactory.getSocketFactory(), mHttpConfig.httpsPort)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); mHttpClient = new DefaultHttpClient(manager, params); }
From source file:edu.syr.bytecast.githubcampfire.CampfirePost.java
public CampfirePostReply post(String message) { //see: http://stackoverflow.com/questions/2603691/android-httpclient-and-https try {/*from w ww . j ava 2s . c o m*/ String xml_message = "<message><type>TextMessage</type><body>" + message + "</body></message>"; SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); BasicSchemeFactory factory = new BasicSchemeFactory(); HttpParams params = new BasicHttpParams(); params.setParameter("realm", "https://trifort.campfirenow.com/"); SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient client = new DefaultHttpClient(mgr, params); String url = "https://trifort.campfirenow.com/room/" + m_room + "/speak.xml"; HttpPost post = new HttpPost(url); post.setHeader("Content-type", "application/xml"); AuthScheme scheme = factory.newInstance(params); Header header = scheme.authenticate(new UsernamePasswordCredentials(m_apiKey), post); HttpEntity entity = new StringEntity(xml_message); post.setEntity(entity); post.setHeader(header); HttpResponse response = client.execute(post); return new CampfirePostReply(response); } catch (Exception ex) {//post.setEntity; ex.printStackTrace(); return null; } }