org.apache.http.impl.client.BasicCookieStore Java Examples

The following examples show how to use org.apache.http.impl.client.BasicCookieStore. 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: HttpTransportClient.java    From vk-java-sdk with MIT License 8 votes vote down vote up
public HttpTransportClient(int retryAttemptsNetworkErrorCount, int retryAttemptsInvalidStatusCount) {
    this.retryAttemptsNetworkErrorCount = retryAttemptsNetworkErrorCount;
    this.retryAttemptsInvalidStatusCount = retryAttemptsInvalidStatusCount;

    CookieStore cookieStore = new BasicCookieStore();
    RequestConfig requestConfig = RequestConfig.custom()
            .setSocketTimeout(SOCKET_TIMEOUT_MS)
            .setConnectTimeout(CONNECTION_TIMEOUT_MS)
            .setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
            .setCookieSpec(CookieSpecs.STANDARD)
            .build();

    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

    connectionManager.setMaxTotal(MAX_SIMULTANEOUS_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(MAX_SIMULTANEOUS_CONNECTIONS);

    httpClient = HttpClients.custom()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig)
            .setDefaultCookieStore(cookieStore)
            .setUserAgent(USER_AGENT)
            .build();
}
 
Example #2
Source File: RealmsAPI.java    From FishingBot with GNU General Public License v3.0 6 votes vote down vote up
public RealmsAPI(AuthData authData) {
    BasicCookieStore cookies = new BasicCookieStore();

    BasicClientCookie sidCookie = new BasicClientCookie("sid", String.join(":", "token", authData.getAccessToken(), authData.getProfile()));
    BasicClientCookie userCookie = new BasicClientCookie("user", authData.getUsername());
    BasicClientCookie versionCookie = new BasicClientCookie("version", ProtocolConstants.getVersionString(FishingBot.getInstance().getServerProtocol()));

    sidCookie.setDomain(".pc.realms.minecraft.net");
    userCookie.setDomain(".pc.realms.minecraft.net");
    versionCookie.setDomain(".pc.realms.minecraft.net");

    sidCookie.setPath("/");
    userCookie.setPath("/");
    versionCookie.setPath("/");

    cookies.addCookie(sidCookie);
    cookies.addCookie(userCookie);
    cookies.addCookie(versionCookie);

    client = HttpClientBuilder.create()
            .setDefaultCookieStore(cookies)
            .build();
}
 
Example #3
Source File: BasicHttpSolrClientTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException,
IOException {
  BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue);
  cookie.setVersion(0);
  cookie.setPath("/");
  cookie.setDomain(jetty.getBaseUrl().getHost());

  CookieStore cookieStore = new BasicCookieStore();
  CookieSpec cookieSpec = new SolrPortAwareCookieSpecFactory().create(context);
 // CookieSpec cookieSpec = registry.lookup(policy).create(context);
  // Add the cookies to the request
  List<Header> headers = cookieSpec.formatCookies(Collections.singletonList(cookie));
  for (Header header : headers) {
    request.addHeader(header);
  }
  context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
}
 
Example #4
Source File: CMODataAbapClient.java    From devops-cm-client with Apache License 2.0 6 votes vote down vote up
public CMODataAbapClient(String endpoint, String user, String password) throws URISyntaxException {

        this.endpoint = new URI(endpoint);
        this.requestBuilder = new TransportRequestBuilder(this.endpoint);

        // the same instance needs to be used as long as we are in the same session. Hence multiple
        // clients must share the same cookie store. Reason: we are logged on with the first request
        // and get a cookie. That cookie - expressing the user has already been logged in - needs to be
        // present in all subsequent requests.
        CookieStore sessionCookieStore = new BasicCookieStore();

        BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
        basicCredentialsProvider.setCredentials(
                new AuthScope(this.endpoint.getHost(), this.endpoint.getPort()),
                new UsernamePasswordCredentials(user, password));

        this.clientFactory = new HttpClientFactory(sessionCookieStore, basicCredentialsProvider);
    }
 
Example #5
Source File: AsyncHttpClient.java    From letv with Apache License 2.0 6 votes vote down vote up
public static CookieStore getuCookie() {
    CookieStore uCookie = new BasicCookieStore();
    try {
        String COOKIE_S_LINKDATA = LemallPlatform.getInstance().getCookieLinkdata();
        if (!TextUtils.isEmpty(COOKIE_S_LINKDATA)) {
            String[] cookies = COOKIE_S_LINKDATA.split("&");
            for (String item : cookies) {
                String[] keyValue = item.split(SearchCriteria.EQ);
                if (keyValue.length == 2) {
                    if (OtherUtil.isContainsChinese(keyValue[1])) {
                        keyValue[1] = URLEncoder.encode(keyValue[1], "UTF-8");
                    }
                    BasicClientCookie cookie = new BasicClientCookie(keyValue[0], keyValue[1]);
                    cookie.setVersion(0);
                    cookie.setDomain(".lemall.com");
                    cookie.setPath("/");
                    uCookie.addCookie(cookie);
                }
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return uCookie;
}
 
Example #6
Source File: Solidfiles.java    From neembuu-uploader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    try {
        if (file.length() > fileSizeLimit) {
            throw new NUMaxFileSizeException(fileSizeLimit, file.getName(), this.getHost());
        }
        
        if (solidfilesAccount.loginsuccessful) {
            httpContext = solidfilesAccount.getHttpContext();
        }
        else {
            cookieStore = new BasicCookieStore();
            httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        }
        
        uploadInitialising();
        fileupload();
    } catch(NUException ex){
        ex.printError();
        uploadInvalid();
    } catch (Exception e) {
        Logger.getLogger(Solidfiles.class.getName()).log(Level.SEVERE, null, e);

        uploadFailed();
    }
}
 
Example #7
Source File: NetLoad.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
public String PostInformation(String url, Map<String, String> map)
		throws ClientProtocolException, IOException {
	List<NameValuePair> params = new ArrayList<NameValuePair>();
	Set<Map.Entry<String, String>> set = map.entrySet();
	Iterator<Map.Entry<String, String>> iterator = set.iterator();
	while (iterator.hasNext()) {
		Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator
				.next();
		params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
	}
	HttpPost post = new HttpPost(url);
	post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
	cookieStore = new BasicCookieStore();
	DefaultHttpClient client = new DefaultHttpClient();
	HttpResponse httpResponse = client.execute(post);
	int status = httpResponse.getStatusLine().getStatusCode();
	if (status == 200) {
		HttpEntity entity = httpResponse.getEntity();
		if (entity != null) {
			return EntityUtils.toString(entity, "UTF-8");
		}
		return null;
	} else {
		return null;
	}
}
 
Example #8
Source File: HttpUriRequestConverter.java    From webmagic with Apache License 2.0 6 votes vote down vote up
private HttpClientContext convertHttpClientContext(Request request, Site site, Proxy proxy) {
    HttpClientContext httpContext = new HttpClientContext();
    if (proxy != null && proxy.getUsername() != null) {
        AuthState authState = new AuthState();
        authState.update(new BasicScheme(ChallengeState.PROXY), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
        httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState);
    }
    if (request.getCookies() != null && !request.getCookies().isEmpty()) {
        CookieStore cookieStore = new BasicCookieStore();
        for (Map.Entry<String, String> cookieEntry : request.getCookies().entrySet()) {
            BasicClientCookie cookie1 = new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
            cookie1.setDomain(UrlUtils.removePort(UrlUtils.getDomain(request.getUrl())));
            cookieStore.addCookie(cookie1);
        }
        httpContext.setCookieStore(cookieStore);
    }
    return httpContext;
}
 
Example #9
Source File: OAuthRedirectUriTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCustomScheme() throws IOException {
    oauth.clientId("custom-scheme");

    oauth.redirectUri("android-app://org.keycloak.examples.cordova/https/keycloak-cordova-example.github.io/login");
    oauth.openLoginForm();

    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH).build();
    CookieStore cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);

    String loginUrl = driver.getCurrentUrl();

    CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(globalConfig).setDefaultCookieStore(cookieStore).build();

    try {
        String loginPage = SimpleHttp.doGet(loginUrl, client).asString();

        String formAction = loginPage.split("action=\"")[1].split("\"")[0].replaceAll("&amp;", "&");
        SimpleHttp.Response response = SimpleHttp.doPost(formAction, client).param("username", "test-user@localhost").param("password", "password").asResponse();

        response.getStatus();
        assertThat(response.getFirstHeader("Location"), Matchers.startsWith("android-app://org.keycloak.examples.cordova/https/keycloak-cordova-example.github.io/login"));
    } finally {
        client.close();
    }
}
 
Example #10
Source File: VideoWoodAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
       httpContext = new BasicHttpContext();
       cookieStore = new BasicCookieStore();
       httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

       NULogger.getLogger().info("Getting startup cookies & link from VideoWood.tv");
       responseString = NUHttpClientUtils.getData("http://videowood.tv/login", httpContext);
       doc = Jsoup.parse(responseString);
vdwood_token = doc.select("form").select("input[name=_token]").attr("value");
   }
 
Example #11
Source File: FilesBombAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from FilesBomb.in");
    //responseString = NUHttpClientUtils.getData("", httpContext);
}
 
Example #12
Source File: PlayedToAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from Played.to");
    //responseString = NUHttpClientUtils.getData("", httpContext);
}
 
Example #13
Source File: FileOmAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from FileOM.com");
    //responseString = NUHttpClientUtils.getData("http://fileom.com", httpContext);
}
 
Example #14
Source File: PreservingCookiePathProxyServlet.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
private HttpResponse login(BonitaCredentials credentials) throws IOException {
    BasicHttpContext httpContext = new BasicHttpContext();
    BasicCookieStore cookieStore = new BasicCookieStore();
    httpContext.setAttribute("http.cookie-store", cookieStore);
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("username", credentials.username));
    urlParameters.add(new BasicNameValuePair("password", credentials.password));
    urlParameters.add(new BasicNameValuePair("redirect", "false"));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, "utf-8");
    HttpPost postRequest = new HttpPost(credentials.loginServletURI);
    postRequest.setEntity(entity);
    return getProxyClient().execute(postRequest, httpContext);
}
 
Example #15
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a separate Http context to protect session cookies.
 *
 * @return HttpClientContext instance with cookies
 */
private HttpClientContext cloneContext() {
    // Create a local context to avoid cookie reset on error
    BasicCookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookies(httpClientAdapter.getCookies().toArray(new org.apache.http.cookie.Cookie[0]));
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);
    return context;
}
 
Example #16
Source File: UnionService.java    From seezoon-framework-all with Apache License 2.0 5 votes vote down vote up
/**
 * https://uac.10010.com/portal/Service/SendMSG?callback=jQuery17205929719702722311_1528559748925&req_time=1528560335346&mobile=13249073372&_=1528560335347
 * @throws Exception 
 * @throws ParseException 
 */
@Test
public void sendSms() throws ParseException, Exception {
	CookieStore cookie = new BasicCookieStore() ;
	HttpClientContext httpClientContext = HttpClientContext.create();
	httpClientContext.setCookieStore(cookie);
	MultiValueMap<String,String> params =  new LinkedMultiValueMap<>();
	params.put("req_time", Lists.newArrayList(String.valueOf(System.currentTimeMillis())));
	params.put("_=", Lists.newArrayList(String.valueOf(System.currentTimeMillis())));
	params.put("mobile", Lists.newArrayList("13249073372"));
	String url = UriComponentsBuilder.fromHttpUrl("https://uac.10010.com/portal/Service/SendMSG").queryParams(params).build().toUriString();
	HttpGet request = new HttpGet(url);
	request.setHeader("Referer", "https://uac.10010.com/portal/custLogin");
	request.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36");
	CloseableHttpResponse response = client.execute(request, httpClientContext);
	System.out.println("response:" + JSON.toJSONString(response));
	if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {// 成功
		HttpEntity entity = response.getEntity();
		if (null != entity) {
			String result = EntityUtils.toString(entity, "UTF-8");
			EntityUtils.consume(entity);
			System.out.println("result" + result);
		} else {
			throw new ServiceException("请求无数据返回");
		}
	} else {
		throw new ServiceException("请求状态异常失败");
	}
	System.out.println("cookie:" + JSON.toJSONString(cookie));
	
}
 
Example #17
Source File: Instagram4j.java    From instagram4j with Apache License 2.0 5 votes vote down vote up
/**
 * Setup some variables
 */
public void setup() {
	log.info("Setup...");

	if (StringUtils.isEmpty(this.username)) {
		throw new IllegalArgumentException("Username is mandatory.");
	}

	if (StringUtils.isEmpty(this.password)) {
		throw new IllegalArgumentException("Password is mandatory.");
	}

	this.deviceId = InstagramHashUtil.generateDeviceId(this.username, this.password);

	if (StringUtils.isEmpty(this.uuid)) {
		this.uuid = InstagramGenericUtil.generateUuid(true);
	}

	if (StringUtils.isEmpty(this.advertisingId)) {
		this.advertisingId = InstagramGenericUtil.generateUuid(true);
	}

	if (this.cookieStore == null) {
		this.cookieStore = new BasicCookieStore();
	}

	log.info("Device ID is: " + this.deviceId + ", random id: " + this.uuid);
	HttpClientBuilder builder = HttpClientBuilder.create();
	if (proxy != null) {
		builder.setProxy(proxy);
	}

	if (credentialsProvider != null)
		builder.setDefaultCredentialsProvider(credentialsProvider);

	builder.setDefaultCookieStore(this.cookieStore);
	this.client = builder.build();
}
 
Example #18
Source File: Session.java    From timer with Apache License 2.0 5 votes vote down vote up
public Session(HttpEntityProviderService providerService) {
    this.context = HttpClientContext.create();
    this.httpClient = new HttpConnectionManager().getHtpClient();
    this.cookies = new BasicCookieStore();
    this.context.setCookieStore(cookies);
    this.providerService = providerService;

}
 
Example #19
Source File: ZaasClientHttpsTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeEach
public void setupMethod() throws Exception {
    httpsClientProvider = mock(HttpsClientProvider.class);
    statusLine = mock(StatusLine.class);
    headerElement = mock(HeaderElement.class);
    header = mock(Header.class);
    closeableHttpResponse = mock(CloseableHttpResponse.class);
    closeableHttpClient = mock(CloseableHttpClient.class);
    httpsEntity = mock(HttpEntity.class);

    ConfigProperties configProperties = getConfigProperties();
    long now = System.currentTimeMillis();
    long expiration = now + 10000;
    long expirationForExpiredToken = now - 1000;

    Key jwtSecretKey = getDummyKey(configProperties);

    token = getToken(now, expiration, jwtSecretKey);
    expiredToken = getToken(now, expirationForExpiredToken, jwtSecretKey);
    invalidToken = token + "DUMMY TEXT";

    when(httpsClientProvider.getHttpsClientWithTrustStore(any(BasicCookieStore.class))).thenReturn(closeableHttpClient);
    when(closeableHttpClient.execute(any(HttpGet.class))).thenReturn(closeableHttpResponse);
    when(closeableHttpClient.execute(any(HttpPost.class))).thenReturn(closeableHttpResponse);
    when(closeableHttpResponse.getEntity()).thenReturn(httpsEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(statusLine);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);

    String baseUrl = "/api/v1/gateway/auth";
    tokenService = new TokenServiceHttpsJwt(httpsClientProvider, baseUrl, "localhost");
    passTicketService = new PassTicketServiceHttps(httpsClientProvider, baseUrl);
}
 
Example #20
Source File: PromptFileAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    httpPost = new NUHttpPost("http://www.promptfile.com/modal.php");
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("modal", "login"));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    httpPost.setEntity(entity);
    httpResponse = httpclient.execute(httpPost, httpContext);
    responseString = EntityUtils.toString(httpResponse.getEntity());
    
    p = Pattern.compile("sid=[a-z0-9]*(?=\")");
    m = p.matcher(responseString);

    while (m.find()){
        captcha_sid = m.group();
    }
    
    captcha_url = "http://www.promptfile.com/securimage_show.php?" + captcha_sid;
    
    Captcha captcha = captchaServiceProvider().newCaptcha();
    captcha.setFormTitle(Translation.T().captchacontrol()+" (PromptFile.com)");
    captcha.setImageURL(captcha_url);
    captcha.setHttpContext(httpContext);
    captchaString = captcha.getCaptchaString();
}
 
Example #21
Source File: NowDownloadAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from NowDownload.to");
    //responseString = NUHttpClientUtils.getData("http://www.nowdownload.to", httpContext);
}
 
Example #22
Source File: FileDownloader.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
private BasicCookieStore getWebDriverCookies(Set<Cookie> seleniumCookieSet) {
    BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore();
    for (Cookie seleniumCookie : seleniumCookieSet) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        copyOfWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return copyOfWebDriverCookieStore;
}
 
Example #23
Source File: SendFileAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from SendFile.su");
    //responseString = NUHttpClientUtils.getData("SendFile.su", httpContext);
}
 
Example #24
Source File: VipFileAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from Vip-File.com");
    //responseString = NUHttpClientUtils.getData("http://vip-file.com", httpContext);
}
 
Example #25
Source File: IguanaShareAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from IguanaShare.com");
    //responseString = NUHttpClientUtils.getData("", httpContext);
}
 
Example #26
Source File: DDLStorageAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from DDLStorage.com");
    //responseString = NUHttpClientUtils.getData("http://www.ddlstorage.com", httpContext);
}
 
Example #27
Source File: DropVideoAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from DropVideo.com");
    //responseString = NUHttpClientUtils.getData("", httpContext);
}
 
Example #28
Source File: StreaminAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from Streamin.to");
    //responseString = NUHttpClientUtils.getData("http://streamin.to/", httpContext);
}
 
Example #29
Source File: AzkabanProjectService.java    From DataSphereStudio with Apache License 2.0 5 votes vote down vote up
private void uploadProject(String tmpSavePath, Project project, Cookie cookie) throws AppJointErrorException {
    String projectName = project.getName();
    HttpPost httpPost = new HttpPost(projectUrl + "?project=" + projectName);
    httpPost.addHeader(HTTP.CONTENT_ENCODING, "UTF-8");
    CloseableHttpResponse response = null;
    File file = new File(tmpSavePath);
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(cookie);
    CloseableHttpClient httpClient = null;
    InputStream inputStream = null;
    try {
        httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
        MultipartEntityBuilder entityBuilder =  MultipartEntityBuilder.create();
        entityBuilder.addBinaryBody("file",file);
        entityBuilder.addTextBody("ajax", "upload");
        entityBuilder.addTextBody("project", projectName);
        httpPost.setEntity(entityBuilder.build());
        response = httpClient.execute(httpPost);
        HttpEntity httpEntity = response.getEntity();
        inputStream = httpEntity.getContent();
        String entStr = null;
        entStr = IOUtils.toString(inputStream, "utf-8");
        if(response.getStatusLine().getStatusCode() != 200){
            logger.error("调用azkaban上传接口的返回不为200, status code 是 {}", response.getStatusLine().getStatusCode());
            throw new AppJointErrorException(90013, "release project failed, " + entStr);
        }
        logger.info("upload project:{} success!",projectName);
    }catch (Exception e){
        logger.error("upload failed,reason:",e);
        throw new AppJointErrorException(90014,e.getMessage(), e);
    }
    finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(response);
        IOUtils.closeQuietly(httpClient);
    }
}
 
Example #30
Source File: UpaFileAccount.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() throws Exception {
    httpContext = new BasicHttpContext();
    cookieStore = new BasicCookieStore();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    //NULogger.getLogger().info("Getting startup cookies & link from UpaFile.com");
    //responseString = NUHttpClientUtils.getData("http://upafile.com", httpContext);
}