当前位置: 首页>>代码示例>>Java>>正文


Java Executor类代码示例

本文整理汇总了Java中org.apache.http.client.fluent.Executor的典型用法代码示例。如果您正苦于以下问题:Java Executor类的具体用法?Java Executor怎么用?Java Executor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Executor类属于org.apache.http.client.fluent包,在下文中一共展示了Executor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createWebHook

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
/**
 * Creates a web hook in Gogs with the passed json configuration string
 *
 * @param jsonCommand A json buffer with the creation command of the web hook
 * @param projectName the project (owned by the user) where the webHook should be created
 * @throws IOException something went wrong
 */
int createWebHook(String jsonCommand, String projectName) throws IOException {

    String gogsHooksConfigUrl = getGogsServer_apiUrl()
            + "repos/" + this.gogsServer_user
            + "/" + projectName + "/hooks";

    Executor executor = getExecutor();

    String result = executor
            .execute(Request.Post(gogsHooksConfigUrl).bodyString(jsonCommand, ContentType.APPLICATION_JSON))
            .returnContent().asString();
    JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( result );
    int id = jsonObject.getInt("id");

    return id;
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:24,代码来源:GogsConfigHandler.java

示例2: removeHook

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
/**
 * Removes a web hook from a GOGS project
 *
 * @param projectName Name of the Gogs project to remove the hook from
 * @param hookId      The ID of the hook to remove
 * @throws IOException something went wrong
 */
void removeHook(String projectName, int hookId) throws IOException {
    String gogsHooksConfigUrl = getGogsServer_apiUrl()
            + "repos/" + this.gogsServer_user
            + "/" + projectName + "/hooks/" + hookId;

    Executor executor = getExecutor();

    int result = executor
            .execute(Request.Delete(gogsHooksConfigUrl))
            .returnResponse().getStatusLine().getStatusCode();

    if (result != 204) {
        throw new IOException("Delete hook did not return the expected value (returned " + result + ")");
    }
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:23,代码来源:GogsConfigHandler.java

示例3: createEmptyRepo

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
/**
 * Creates an empty repository (under the configured user).
 * It is created as a public repository, un-initialized.
 *
 * @param projectName the project name (repository) to create
 * @throws IOException Something went wrong (example: the repo already exists)
 */
void createEmptyRepo(String projectName) throws IOException {

    Executor executor = getExecutor();
    String gogsHooksConfigUrl = getGogsServer_apiUrl() + "user/repos";

    int result = executor
            .execute(Request
                    .Post(gogsHooksConfigUrl)
                    .bodyForm(Form.form()
                            .add("name", projectName)
                            .add("description", "API generated repository")
                            .add("private", "true")
                            .add("auto_init", "false")
                            .build()
                    )
            )
            .returnResponse().getStatusLine().getStatusCode();


    if (result != 201) {
        throw new IOException("Repository creation call did not return the expected value (returned " + result + ")");
    }
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:31,代码来源:GogsConfigHandler.java

示例4: post

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
/**
 * Post the data to the DataSift Ingestion endpoint.
 * @param data the data to send
 * @return the http response
 * @throws URISyntaxException if the uri is invalid or the request fails
 * @throws IOException if the http post fails
 */
@SuppressWarnings("checkstyle:designforextension")
public HttpResponse post(final String data) throws URISyntaxException, IOException {
    log.debug("post()");

    URI uri = getUri();
    String authToken = getAuthorizationToken(config);

    metrics.sendAttempt.mark();
    log.trace("Posting to ingestion endpoint {}", data);
    log.debug("Posting to ingestion endpoint data length {} bytes", data.length());

    Request request = Request.Post(uri)
                             .useExpectContinue()
                             .version(HttpVersion.HTTP_1_1)
                             .addHeader("Auth", authToken)
                             .bodyString(data, ContentType.create("application/json"));

    return Executor.newInstance(httpClient)
                .execute(request)
                .returnResponse();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:29,代码来源:BulkManager.java

示例5: renewSession

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean renewSession(final Executor executor, final String url, final String serviceName) throws IOException {
	assert sessionKey.isPresent();
	final String _sessionKey = sessionKey.get();
	final String uri = String.format("%s/v1/session/renew/%s", url, _sessionKey);
	logger.debug("PUT {}", uri);
	final Response response = executor.execute(Request.Put(uri));
	boolean renewedOk = response.returnResponse().getStatusLine().getStatusCode() == 200;

	logger.debug("Session {} renewed={}", _sessionKey, renewedOk);
	if (!renewedOk) {
		logger.debug("Attempting to re-establish session for serviceName={}", serviceName);
		destroySession(url, _sessionKey);
		sessionKey = Optional.empty();
		sessionKey = initSessionKey(serviceName);
		renewedOk = sessionKey.isPresent();
	}
	return renewedOk;
}
 
开发者ID:jhberges,项目名称:camel-consul-leader,代码行数:19,代码来源:ConsulFacadeBean.java

示例6: testProxyAuthWithSSL

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
@Test
public void testProxyAuthWithSSL() throws Exception {
    SSLContext sslContext = new SSLContextBuilder()
            .loadTrustMaterial(new File(keyStoreFile), keystorePW.toCharArray(), new TrustSelfSignedStrategy())
            .build();

    try (CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslContext)
            .setSSLHostnameVerifier(new HostnameVerifier() {

                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }

            }).build()) {
        Executor ex = Executor.newInstance(httpclient);
        Response response = ex.execute(Request.Get("https://localhost:9200/blahobar.234324234/logs/1")
                .addHeader("Authorization", String.format("Bearer %s", token))
                .addHeader("X-Proxy-Remote-User", proxyUser));
        System.out.println(response.returnContent().asString());
    } catch (Exception e) {
        System.out.println(e);
        fail("Test Failed");
    }
}
 
开发者ID:fabric8io,项目名称:openshift-elasticsearch-plugin,代码行数:26,代码来源:HttpsProxyClientCertAuthenticatorIntegrationTest.java

示例7: invoke

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
static <ResType extends Error, ReqType> ResType invoke(final ClientConfig config, final ReqType request, final Class<ResType> responseClass,
                                                       final Options opts) throws IOException {
    Request httpRequest = createRequest(config, request, opts);
    Executor invoker = createExecutor(config);
    return invoker
            .execute(httpRequest)
            .handleResponse(
                new ResponseHandler<ResType>() {
                    public ResType handleResponse(HttpResponse response) throws IOException {
                        ResType res = Endpoint.handleResponse(response, responseClass);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("response: {}", res);
                        }
                        return res;
                    }
                }
            );
}
 
开发者ID:woki,项目名称:adyen-api,代码行数:19,代码来源:Endpoint.java

示例8: run

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
@Scheduled(cron = "0 0 9,18 * * ?")
public void run() {
    for (Account account : getAccounts()) {
        try {
            RequestConfig config = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD_STRICT).build();
            CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(config).build();
            Executor executor = Executor.newInstance(client).use(new BasicCookieStore());
            if(login(executor, account)) {
                checkIn(executor, account);
            }
        } catch (Exception e) {
            log.error("【V2EX】【" + account.getUsername() + "】签到异常", e);
        }

    }
}
 
开发者ID:usc,项目名称:check-in,代码行数:17,代码来源:V2exCheckInTask.java

示例9: checkIn

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean checkIn(Executor executor, Account account) throws ClientProtocolException, IOException, URISyntaxException, InterruptedException {
    String usrename = account.getUsername();

    String rtn = executor.execute(appendTimeOuts(Request.Get(CHECK_IN_URL))).returnContent().asString();
    if(StringUtils.contains(rtn, "fa-ok-sign")) {
        log.info("【V2EX】【{}】每日登录奖励已领取,当前账户余额:{}", usrename, getBalance(rtn));
        return true;
    }

    Elements element = Jsoup.parse(rtn).getElementsByAttributeValueMatching("onclick", "/mission/daily/redeem");
    String once = StringUtils.substringBetween(element.attr("onclick"), "'", "'");
    if(StringUtils.isNotEmpty(once)) {
        String url = "http://www.v2ex.com" + once;

        String checkInRtn = executor.execute(appendTimeOuts(Request.Get(url)).userAgent(USER_AGENT).addHeader("Referer", CHECK_IN_URL)).returnContent().asString();
        log.info("【V2EX】【{}】签到成功,当前账户余额:{}", usrename, getBalance(checkInRtn));
        return true;
    }

    log.info("【V2EX】【{}】签到成功", usrename);
    return false;
}
 
开发者ID:usc,项目名称:check-in,代码行数:23,代码来源:V2exCheckInTask.java

示例10: login

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean login(Executor executor, Account account) throws ClientProtocolException, IOException, URISyntaxException {
    String usrename = account.getUsername();

    List<NameValuePair> formParams = new ArrayList<NameValuePair>();
    formParams.add(new BasicNameValuePair("username", usrename));
    formParams.add(new BasicNameValuePair("password", account.getPassword()));
    formParams.add(new BasicNameValuePair("rememberme", "on"));
    formParams.add(new BasicNameValuePair("captcha", ""));
    formParams.add(new BasicNameValuePair("redirect_url", "http://www.smzdm.com"));

    String loginJson = executor.execute(appendTimeOuts(Request.Post(LOGIN_URL)).bodyForm(formParams)).returnContent().asString();
    JSONObject loginJsonParseObject = JSON.parseObject(loginJson);
    if(0 != loginJsonParseObject.getInteger("error_code")) {
        log.info("【SMZDM】【{}】登录失败:{}", usrename, loginJsonParseObject.getString("error_msg"));
        return false;
    }

    log.info("【SMZDM】【{}】登录成功", usrename);
    return true;
}
 
开发者ID:usc,项目名称:check-in,代码行数:21,代码来源:SmzdmCheckInTask.java

示例11: checkIn

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean checkIn(Executor executor, Account account) throws ClientProtocolException, IOException, URISyntaxException {
    String usrename = account.getUsername();

    URI checkInURI = new URIBuilder(CHECK_IN_URL).
            addParameter("_", System.currentTimeMillis() + "").
            build();

    String signInJson = executor.execute(appendTimeOuts(Request.Get(checkInURI))).returnContent().asString();
    JSONObject signInParseObject = JSON.parseObject(signInJson);
    if(0 != signInParseObject.getInteger("error_code")) {
        log.info("【SMZDM】【{}】签到失败:{}", usrename, signInParseObject.getString("error_msg"));
        return false;
    }

    log.info("【SMZDM】【{}】签到成功", usrename);
    return true;
}
 
开发者ID:usc,项目名称:check-in,代码行数:18,代码来源:SmzdmCheckInTask.java

示例12: run

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
@Scheduled(cron = "0 0 5,18 * * ?")
public void run() {
    for (Account account : getAccounts()) {
        try {
            CloseableHttpClient client = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
            Executor executor = Executor.newInstance(client).use(new BasicCookieStore());
            String token = login(executor, account);
            if(StringUtils.isNotEmpty(token)) {
                if(checkIn(executor, account, token)) {
                    // lottery(executor, account, token);
                }
            }
        } catch (Exception e) {
            log.error("【SMZDM】【" + account.getUsername() + "】签到异常", e);
        }
    }
}
 
开发者ID:usc,项目名称:check-in,代码行数:18,代码来源:SmzdmAndroidTask.java

示例13: login

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean login(Executor executor, Account account) throws ClientProtocolException, IOException {
    // 1st load first page, 313932302c31303830 = stringToHex("1920,1080")
    executor.execute(appendTimeOuts(Request.Get(URL))).discardContent();
    executor.execute(appendTimeOuts(Request.Get(URL + "?security_verify_data=313932302c31303830"))).discardContent();

    String usrename = account.getUsername();

    List<NameValuePair> formParams = new ArrayList<NameValuePair>();
    formParams.add(new BasicNameValuePair("account", usrename));
    formParams.add(new BasicNameValuePair("password", account.getPassword()));
    formParams.add(new BasicNameValuePair("remember", "0"));
    formParams.add(new BasicNameValuePair("url_back", URL));

    String loginJson = executor.execute(appendTimeOuts(Request.Post(LOGIN_URL)).bodyForm(formParams)).returnContent().asString();
    JSONObject loginJsonParseObject = JSON.parseObject(loginJson);
    if(1 != loginJsonParseObject.getInteger("status")) {
        log.info("【ZIMUZU】【{}】登录失败:{}", usrename, loginJsonParseObject.getString("info"));
        return false;
    }

    log.info("【ZIMUZU】【{}】登录成功", usrename);
    return true;
}
 
开发者ID:usc,项目名称:check-in,代码行数:24,代码来源:ZiMuZuTvSignInTask.java

示例14: signIn

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
private boolean signIn(Executor executor, Account account) throws ClientProtocolException, IOException, InterruptedException {
    // String usrename = account.getUsername();

    executor.execute(appendTimeOuts(Request.Get(URL))).discardContent();
    executor.execute(appendTimeOuts(Request.Get("http://www.zimuzu.tv/public/hotkeyword"))).discardContent();
    executor.execute(appendTimeOuts(Request.Get("http://www.zimuzu.tv/user/login/getCurUserTopInfo"))).discardContent();

    // String rtn = executor.execute(appendTimeOuts(Request.Get(SIGN_IN_URL))).returnContent().asString();
    // if (StringUtils.contains(rtn, "您今天已登录")) {
    //     log.info("【ZIMUZU】【{}】签到成功", usrename);
    //     return true;
    // }
    //
    // log.info("【ZIMUZU】【{}】签到失败", usrename);
    return false;
}
 
开发者ID:usc,项目名称:check-in,代码行数:17,代码来源:ZiMuZuTvSignInTask.java

示例15: setUpClass

import org.apache.http.client.fluent.Executor; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
    conf = new Configuration(CONF_FILE_PATH);
    MongoDBClientSingleton.init(conf);
    mongoClient = MongoDBClientSingleton.getInstance().getClient();

    BASE_URL = "http://" + conf.getHttpHost() + ":" + conf.getHttpPort();

    createURIs();

    final String host = MONGO_HOST;
    final int port = conf.getHttpPort();
    adminExecutor = Executor.newInstance().authPreemptive(new HttpHost(host, port, HTTP)).auth(new HttpHost(host), "admin", "changeit");
    user1Executor = Executor.newInstance().authPreemptive(new HttpHost(host, port, HTTP)).auth(new HttpHost(host), "user1", "changeit");
    user2Executor = Executor.newInstance().authPreemptive(new HttpHost(host, port, HTTP)).auth(new HttpHost(host), "user2", "changeit");
    unauthExecutor = Executor.newInstance();
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:18,代码来源:HttpClientAbstactIT.java


注:本文中的org.apache.http.client.fluent.Executor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。