org.apache.http.params.CoreProtocolPNames Java Examples

The following examples show how to use org.apache.http.params.CoreProtocolPNames. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamClientImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION,
        requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
        );
    }

    return new DefaultedHttpParams(localParams, globalParams);
}
 
Example #2
Source File: ImportUsagePoint.java    From OpenESPI-DataCustodian-java with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (args.length == 2) {
        try {
            String filename = args[0];
            String url = args[1];

            DefaultHttpClient client = new DefaultHttpClient();
            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            upload(filename, url, client);
            client.getConnectionManager().shutdown();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Usage: import_usage_point.sh filename url");
        System.out.println("");
        System.out.println("Example:");
        System.out.println("");
        System.out.println("  import_usage_point.sh etc/usage_point.xml http://localhost:8080/custodian/retailcustomers/1/upload");
    }
}
 
Example #3
Source File: HttpComponentsHelper.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * prepare for the https connection
 * call this in the constructor of the class that does the connection if
 * it's used multiple times
 */
private void setup() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // set the user credentials for our site "example.com"
    credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere"));
    clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    context = new BasicHttpContext();
    context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}
 
Example #4
Source File: GoogleAnalytics.java    From h2o-2 with Apache License 2.0 6 votes vote down vote up
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) {
  ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
  connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

  BasicHttpParams params = new BasicHttpParams();

  if (isNotEmpty(config.getUserAgent())) {
    params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());
  }

  if (isNotEmpty(config.getProxyHost())) {
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort()));
  }

  DefaultHttpClient client = new DefaultHttpClient(connManager, params);

  if (isNotEmpty(config.getProxyUserName())) {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
    client.setCredentialsProvider(credentialsProvider);
  }

  return client;
}
 
Example #5
Source File: Wo2bAsyncHttpClient.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 全局唯一的AsyncHttpClient对象
 * 
 * @return
 */
public static AsyncHttpClient newAsyncHttpClient()
{
	String userAgent = null;
	if (RockySdk.getInstance().getClientInfo() != null)
	{
		userAgent = RockySdk.getInstance().getClientInfo().getUserAgent();
	}
	if (userAgent == null)
	{
		userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; GT-I9300 Build/JSS15J) "
				+ "AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.3022";
	}

	asyncHttpClient.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent + ".10");

	return asyncHttpClient;
}
 
Example #6
Source File: HttpClientUtil.java    From AndroidRobot with Apache License 2.0 6 votes vote down vote up
/** 
 * 获取DefaultHttpClient对象 
 *  
 * @param charset 
 *            字符编码 
 * @return DefaultHttpClient对象 
 */  
private static DefaultHttpClient getDefaultHttpClient(final String charset) {  
    DefaultHttpClient httpclient = new DefaultHttpClient();  
    // 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题  
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,  
            USER_AGENT);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.HTTP_CONTENT_CHARSET,  
            charset == null ? CHARSET_ENCODING : charset);  
      
    // 浏览器兼容性  
    httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,  
            CookiePolicy.BROWSER_COMPATIBILITY);  
    // 定义重试策略  
    httpclient.setHttpRequestRetryHandler(requestRetryHandler);  
      
    return httpclient;  
}
 
Example #7
Source File: StreamClientImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION,
        requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
        );
    }

    return new DefaultedHttpParams(localParams, globalParams);
}
 
Example #8
Source File: MediaFireUploadPlugin.java    From neembuu-uploader with GNU General Public License v3.0 6 votes vote down vote up
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(postURL);
    File file = new File("d:/hai.html");
    System.out.println(ukeycookie);
    httppost.setHeader("Cookie", ukeycookie + ";" + skeycookie + ";" + usercookie);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into mediafire...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println("Getting upload response key value..........");
        uploadresponsekey = EntityUtils.toString(resEntity);
        getUploadResponseKey();
        System.out.println("upload resoponse key " + uploadresponsekey);
    }
}
 
Example #9
Source File: WuploadUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 6 votes vote down vote up
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    file = new File("/home/vigneshwaran/dinesh.txt");
    HttpPost httppost = new HttpPost(postURL);
    httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";");
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("files[]", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into wupload...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    System.out.println(response.getStatusLine());
    if (response.getStatusLine().getStatusCode() == 302
            && response.getFirstHeader("Location").getValue().contains("upload/done/")) {

        System.out.println("Upload successful :)");
    } else {
        System.out.println("Upload failed :(");
    }

}
 
Example #10
Source File: SocketFactoryHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
      return true;
    }
  };

  final SchemeRegistry registry = new SchemeRegistry();
  try {
    final SSLSocketFactory ssf =
            new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }

  final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
 
Example #11
Source File: ZohoDocsUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 6 votes vote down vote up
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\GeDotttUploaderPlugin.java");
        HttpPost httppost = new HttpPost("https://docs.zoho.com/uploadsingle.do?isUploadStatus=false&folderId=0&refFileElementId=refFileElement0");
        httppost.setHeader("Cookie", cookies.toString());
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("multiupload_file", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into zoho docs...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
//            System.out.println(tmp);
            if(tmp.contains("File Uploaded Successfully"))
                System.out.println("File Uploaded Successfully");

        }
        //    uploadresponse = response.getLastHeader("Location").getValue();
        //  System.out.println("Upload response : " + uploadresponse);
    }
 
Example #12
Source File: GigaSizeUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("/media/backup/Projects/NU/NeembuuUploader/test/neembuuuploader/test/plugins/RapidShareUploaderPlugin.java");
//        file = new File("e:\\dinesh.txt");
        HttpPost httppost = new HttpPost("http://www.gigasize.com/uploadie");
        httppost.setHeader("Cookie", cookies.toString());
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("UPLOAD_IDENTIFIER", new StringBody(uploadid));
        mpEntity.addPart("sid", new StringBody(sid));
        mpEntity.addPart("fileUpload1", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into Gigasize...........................");
        System.out.println("Now executing......." + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            sid = "";
            sid = EntityUtils.toString(resEntity);
            System.out.println("After upload sid value : " + sid);

        }
        //    uploadresponse = response.getLastHeader("Location").getValue();
        //  System.out.println("Upload response : " + uploadresponse);
    }
 
Example #13
Source File: MegaUploadUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    file = new File("H:\\c programs.doc");
    filelength = file.length();
    if (!username.isEmpty() && !password.isEmpty()) {
        postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength;
    } else {
        postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&" + usercookie + "&s=" + filelength;
    }
    HttpPost httppost = new HttpPost(postURL);
    httppost.setHeader("Cookie", usercookie);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into megaupload...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {

        downloadlink = EntityUtils.toString(resEntity);


    }
}
 
Example #14
Source File: OronUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("H:\\Dinesh.java");
        HttpPost httppost = new HttpPost(oronlink);
        if (login) {

            httppost.setHeader("Cookie", logincookie + ";" + xfsscookie);
        }
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upload_type", new StringBody("file"));
        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (login) {
            mpEntity.addPart("sess_id", new StringBody(xfsscookie.substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver));
        mpEntity.addPart("file_0", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into oron...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            System.out.println("Upload response : " + tmp);

            fnvalue = parseResponse(tmp, "name='fn' value='", "'");
            System.out.println("fn value : " + fnvalue);

        }
//        uploadresponse = response.getLastHeader("Location").getValue();
//        System.out.println("Upload response : " + uploadresponse);
    }
 
Example #15
Source File: SimpleNonBlockingServerTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Test
public void sendHttpOneZeroRequest() throws IOException {
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        get.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Header[] header = result.getHeaders("MyHeader");
        Assert.assertEquals("MyValue", header[0].getValue());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
Example #16
Source File: GrUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void fileUpload() throws IOException {





        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\GrUploaderPlugin.java");
        HttpPost httppost = new HttpPost(gruploadlink);
        if (login) {

            httppost.setHeader("Cookie", logincookie + ";" + xfsscookie);
        }
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("upload_type", new StringBody("file"));
//        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (login) {
            mpEntity.addPart("sess_id", new StringBody(xfsscookie.substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver + "/tmp"));
        mpEntity.addPart("file_0", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into grupload...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            System.out.println("Upload response : " + tmp);

            fnvalue = parseResponse(tmp, "name='fn'>", "<");
            System.out.println("fn value : " + fnvalue);

        }
//        uploadresponse = response.getLastHeader("Location").getValue();
//        System.out.println("Upload response : " + uploadresponse);
    }
 
Example #17
Source File: ParametersHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final DefaultHttpClient httpClient = super.create(method, uri);

  httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
  httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

  final int timeout = 1000;
  HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), timeout);
  HttpConnectionParams.setSoTimeout(httpClient.getParams(), timeout);

  return httpClient;
}
 
Example #18
Source File: CustomConnectionsHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final DefaultHttpClient httpClient = new DefaultHttpClient(new MyClientConnManager());
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
 
Example #19
Source File: ParametersHttpUriRequestFactory.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public HttpUriRequest create(final HttpMethod method, final URI uri) {
  final HttpUriRequest request = super.create(method, uri);

  request.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
  request.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

  final int timeout = 1000;
  HttpConnectionParams.setConnectionTimeout(request.getParams(), timeout);
  HttpConnectionParams.setSoTimeout(request.getParams(), timeout);

  return request;
}
 
Example #20
Source File: ApiServer.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ListenerThread(final ApiServer requestHandler, final int port) {
    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing api server", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
    .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
    .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
    .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
    .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
Example #21
Source File: ClusterServiceServletContainer.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ListenerThread(HttpRequestHandler requestHandler, int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
        .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
        .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
        .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
        .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
Example #22
Source File: StreamClientImpl.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
            requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Let's add the user-agent header on every request
    HttpProtocolParams.setUserAgent(localParams, getConfiguration()
            .getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion()));

    return new DefaultedHttpParams(localParams, globalParams);
}
 
Example #23
Source File: RapidShareUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("/home/vigneshwaran/VIGNESH/dinesh.txt");
        HttpPost httppost = new HttpPost(postURL);
        //httppost.setHeader("Cookie", usercookie);
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("sub", new StringBody("upload"));
        mpEntity.addPart("cookie", new StringBody(cookie));
        mpEntity.addPart("folder", new StringBody("0"));
        mpEntity.addPart("filecontent", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into rs...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            uploadresponse = EntityUtils.toString(resEntity);
            System.out.println("Actual response : " + uploadresponse);
            uploadresponse = uploadresponse.replace("COMPLETE\n", "");

//            downloadid=uploadresponse.substring(uploadresponse.indexOf("E")+1);
            downloadid = uploadresponse.substring(0, uploadresponse.indexOf(","));
            uploadresponse = uploadresponse.replace(downloadid + ",", "");
            filename = uploadresponse.substring(0, uploadresponse.indexOf(","));
            System.out.println("download id : " + downloadid);
//            filename=uploadresponse.substring(uploadresponse.indexOf(","));
//            filename=uploadresponse.substring(0, uploadresponse.indexOf(","));
            System.out.println("File name : " + filename);
            downloadlink = "http://rapidshare.com/files/" + downloadid + "/" + filename;
            System.out.println("Download Link :" + downloadlink);
        }
    }
 
Example #24
Source File: ApiServer.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public ListenerThread(final ApiServer requestHandler, final int port) {
    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing api server", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
           .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
           .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
           .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
           .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
Example #25
Source File: ClusterServiceServletContainer.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
    _executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));

    try {
        _serverSocket = new ServerSocket(port);
    } catch (final IOException ioex) {
        s_logger.error("error initializing cluster service servlet container", ioex);
        return;
    }

    _params = new BasicHttpParams();
    _params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
           .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
           .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
           .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
           .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("/clusterservice", requestHandler);

    // Set up the HTTP service
    _httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    _httpService.setParams(_params);
    _httpService.setHandlerResolver(reqistry);
}
 
Example #26
Source File: SimpleUrlFetcher.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public String getUrl(String url) throws Exception {
    String response_content = "";

    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Macintosh;) SeldonBot/1.0");
    httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, httpGetTimeout);
    httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, httpGetTimeout);
    
    try {
        HttpGet httpget = new HttpGet( url );
        httpget.addHeader("Connection", "close");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            ContentType contentType = ContentType.getOrDefault(entity);
            logger.info("Response contentType: "+contentType);
            
            String contentCharSet = EntityUtils.getContentCharSet(entity);              
            logger.info("Response contentCharSet: "+contentCharSet);
            
            response_content = EntityUtils.toString(entity);
            EntityUtils.consume(entity);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        httpclient.getConnectionManager().closeExpiredConnections();
        httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
        httpclient.getConnectionManager().shutdown();
    }
    
    return response_content;
}
 
Example #27
Source File: GRupload.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public void fileUpload() throws Exception {

        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpPost httppost = new HttpPost(gruploadlink);
        if (gruploadAccount.loginsuccessful) {

            httppost.setHeader("Cookie", GRuploadAccount.getLogincookie() + ";" + GRuploadAccount.getXfsscookie());
        }
        MultipartEntity mpEntity = new MultipartEntity();
        mpEntity.addPart("upload_type", new StringBody("file"));
//        mpEntity.addPart("srv_id", new StringBody(serverID));
        if (gruploadAccount.loginsuccessful) {
            mpEntity.addPart("sess_id", new StringBody(GRuploadAccount.getXfsscookie().substring(5)));
        }
        mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver + "/tmp"));
        mpEntity.addPart("file_0", createMonitoredFileBody());
        httppost.setEntity(mpEntity);
        NULogger.getLogger().info("Now uploading your file into grupload...........................");
        uploading();
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            NULogger.getLogger().log(Level.INFO, "Upload response : {0}", tmp);

            fnvalue = StringUtils.stringBetweenTwoStrings(tmp, "name='fn'>", "<");
            NULogger.getLogger().log(Level.INFO, "fn value : {0}", fnvalue);

        } else {
            throw new Exception("There might be a problem with your internet connection or server error. Please try again some after time. :(");
        }
    }
 
Example #28
Source File: FileSonic.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public void fileUpload() throws Exception {


        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        HttpPost httppost = new HttpPost(postURL);

        httppost.setHeader("Cookie", FileSonicAccount.getLangcookie() + ";" + FileSonicAccount.getSessioncookie() + ";" + FileSonicAccount.getMailcookie() + ";" + FileSonicAccount.getNamecookie() + ";" + FileSonicAccount.getRolecookie() + ";");

        MultipartEntity mpEntity = new MultipartEntity();
        //ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("files[]", createMonitoredFileBody());
        httppost.setEntity(mpEntity);
        uploading();
        NULogger.getLogger().info("Now uploading your file into filesonic...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        NULogger.getLogger().info(response.getStatusLine().toString());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
            //NULogger.getLogger().info("response : " + tmp);

        }
        uploadresponse = response.getLastHeader("Location").getValue();
        NULogger.getLogger().log(Level.INFO, "Upload response URL : {0}", uploadresponse);

        uploadresponse = getData(uploadresponse);
        if (uploadresponse.contains("File was successfully uploaded")) {
            NULogger.getLogger().info("File was successfully uploaded :)");

            uploadFinished();
        } else {
            throw new Exception("There might be a problem with your internet connecivity or server error. Please try after some time. :(");
        }

    }
 
Example #29
Source File: Oron.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public void fileUpload() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(oronlink);
    if (oronAccount.loginsuccessful) {

        httppost.setHeader("Cookie", OronAccount.getLogincookie() + ";" + OronAccount.getXfsscookie());
    }
    MultipartEntity mpEntity = new MultipartEntity();
    mpEntity.addPart("upload_type", new StringBody("file"));
    mpEntity.addPart("srv_id", new StringBody(serverID));
    if (oronAccount.loginsuccessful) {
        mpEntity.addPart("sess_id", new StringBody(OronAccount.getXfsscookie().substring(5)));
    }
    mpEntity.addPart("srv_tmp_url", new StringBody(tmpserver));
    mpEntity.addPart("file_0", createMonitoredFileBody());
    httppost.setEntity(mpEntity);
    NULogger.getLogger().info("Now uploading your file into oron...........................");
    uploading();
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    NULogger.getLogger().info(response.getStatusLine().toString());
    if (resEntity != null) {

        String tmp = EntityUtils.toString(resEntity);
        NULogger.getLogger().log(Level.INFO, "Upload response : {0}", tmp);

        fnvalue = StringUtils.stringBetweenTwoStrings(tmp, "name='fn' value='", "'");
        NULogger.getLogger().log(Level.INFO, "fn value : {0}", fnvalue);

    } else {
        throw new Exception("There might be a problem with your internet connection or server problem. Please try again after some time. :(");
    }


}
 
Example #30
Source File: AccessLogFileTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleLogMessageToFile() throws IOException, InterruptedException {
    // issue the request with a specific HTTP protocol version, so that we can then verify
    // the protocol value logged in the access log file
    final RestAssuredConfig http10Config = RestAssured.config().httpClient(
            new HttpClientConfig().setParam(CoreProtocolPNames.PROTOCOL_VERSION, new ProtocolVersion("HTTP", 1, 0)));
    final RequestSpecification requestSpec = new RequestSpecBuilder().setConfig(http10Config).build();
    final String paramValue = UUID.randomUUID().toString();
    RestAssured.given(requestSpec).get("/does-not-exist?foo=" + paramValue);

    Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS)
            .atMost(10, TimeUnit.SECONDS)
            .untilAsserted(new ThrowingRunnable() {
                @Override
                public void run() throws Throwable {
                    try (Stream<Path> files = Files.list(logDirectory)) {
                        Assertions.assertEquals(1, (int) files.count());
                    }
                    Path path = logDirectory.resolve("server.log");
                    Assertions.assertTrue(Files.exists(path));
                    String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
                    Assertions.assertTrue(data.contains("404"));
                    Assertions.assertTrue(data.contains("/does-not-exist"));
                    Assertions.assertTrue(data.contains("?foo=" + paramValue),
                            "access log is missing query params");
                    Assertions.assertFalse(data.contains("?foo=" + paramValue + "?foo=" + paramValue),
                            "access log contains duplicated query params");
                    Assertions.assertTrue(data.contains("HTTP/1.0"),
                            "HTTP/1.0 protocol value is missing in the access log");
                }
            });
}