當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClient.stop方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.client.HttpClient.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClient.stop方法的具體用法?Java HttpClient.stop怎麽用?Java HttpClient.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.client.HttpClient的用法示例。


在下文中一共展示了HttpClient.stop方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sentRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public static int sentRequest(final String url, final String method, final String content) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange contentExchange = new ContentExchange();
        contentExchange.setMethod(method);
        contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
        contentExchange.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        contentExchange.setURL(url);
        httpClient.send(contentExchange);
        contentExchange.waitForDone();
        return contentExchange.getResponseStatus();
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:18,代碼來源:RestfulTestsUtil.java

示例2: sentGetRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public static String sentGetRequest(final String url) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange contentExchange = new ContentExchange();
        contentExchange.setMethod("GET");
        contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        contentExchange.setURL(url);
        httpClient.send(contentExchange);
        contentExchange.waitForDone();
        return contentExchange.getResponseContent();
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:17,代碼來源:RestfulTestsUtil.java

示例3: sentRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
private static ContentExchange sentRequest(final String content) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange result = new ContentExchange();
        result.setMethod("POST");
        result.setRequestContentType(MediaType.APPLICATION_JSON);
        result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        result.setURL(URL);
        httpClient.send(result);
        result.waitForDone();
        return result;
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:18,代碼來源:RestfulServerTest.java

示例4: submit

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(SSLContext.getDefault());
    HttpClient httpClient = new HttpClient(sslContextFactory);
    // Configure HttpClient here
    httpClient.start();

    ResponseEntity<String> responseEntity = null;

    for (int i=0;i< requestOptions.getCount();i++) {
        final Request request = httpClient
            .newRequest(requestOptions.getUrl());

        for(Map.Entry<String,String> e : requestOptions.getHeaderMap().entrySet()) {
            request.header(e.getKey(), e.getValue());
        }

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        final ContentResponse response = request.send();

        int responseCode = response.getStatus();
        System.out.println("Response Code : " + responseCode);

        String responseContent = IOUtils.toString(response.getContent(), "utf-8");

        //print result
        System.out.println(responseContent);

        responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
    }

    httpClient.stop();
    return responseEntity;
}
 
開發者ID:eeichinger,項目名稱:jcurl,代碼行數:37,代碼來源:JettyEngine.java

示例5: stopHttpClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
private synchronized void stopHttpClient(HttpClient client) {
    if (client.isStarted()) {
        try {
            client.stop();
        } catch (Exception e) {
            logger.error("Unable to stop HttpClient !", e);
        }
    }
}
 
開發者ID:pathec,項目名稱:ZWay-library-for-Java,代碼行數:10,代碼來源:ZWayApiHttp.java

示例6: doStop

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Override
protected void doStop() throws Exception {
    try {
        super.doStop();
    } finally {
        // check if this endpoint has its own http client that needs to be stopped
        final HttpClient httpClient = getConfiguration().getHttpClient();
        if (httpClient != null && getComponent().getConfig().getHttpClient() != httpClient) {
            final String endpointUri = getEndpointUri();
            LOG.debug("Stopping http client for {} ...", endpointUri);
            httpClient.stop();
            LOG.debug("Stopped http client for {}", endpointUri);
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:16,代碼來源:SalesforceEndpoint.java

示例7: login

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public static BayeuxParameters login(URL loginEndpoint, String username, String password,
        BayeuxParameters parameters) throws Exception {
    HttpClient client = new HttpClient(parameters.sslContextFactory());
    try {
        client.getProxyConfiguration().getProxies().addAll(parameters.proxies());
        client.start();
        URL endpoint = new URL(loginEndpoint, getSoapUri());
        Request post = client.POST(endpoint.toURI());
        post.content(new ByteBufferContentProvider("text/xml", ByteBuffer.wrap(soapXmlForLogin(username, password))));
        post.header("SOAPAction", "''");
        post.header("PrettyPrint", "Yes");
        ContentResponse response = post.send();
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        spf.setNamespaceAware(true);
        SAXParser saxParser = spf.newSAXParser();

        LoginResponseParser parser = new LoginResponseParser();
        saxParser.parse(new ByteArrayInputStream(response.getContent()), parser);

        String sessionId = parser.sessionId;
        if (sessionId == null || parser.serverUrl == null) { throw new ConnectException(
                String.format("Unable to login: %s", parser.faultstring)); }

        URL soapEndpoint = new URL(parser.serverUrl);
        String cometdEndpoint = Float.parseFloat(parameters.version()) < 37 ? COMETD_REPLAY_OLD : COMETD_REPLAY;
        URL replayEndpoint = new URL(soapEndpoint.getProtocol(), soapEndpoint.getHost(), soapEndpoint.getPort(),
                new StringBuilder().append(cometdEndpoint).append(parameters.version()).toString());
        return new DelegatingBayeuxParameters(parameters) {
            @Override
            public String bearerToken() {
                return sessionId;
            }

            @Override
            public URL endpoint() {
                return replayEndpoint;
            }
        };
    } finally {
        client.stop();
        client.destroy();
    }
}
 
開發者ID:forcedotcom,項目名稱:EMP-Connector,代碼行數:48,代碼來源:LoginHelper.java


注:本文中的org.eclipse.jetty.client.HttpClient.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。