Java Code Examples for org.eclipse.jetty.client.HttpClient#setConnectorType()

The following examples show how to use org.eclipse.jetty.client.HttpClient#setConnectorType() . 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: RestfulTestsUtil.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * Send request.
 * @param url the url
 * @param method the method name
 * @param content the content
 * @return the http status code
 * @throws Exception exception when error
 */
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();
    }
}
 
Example 2
Source File: RestfulTestsUtil.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * Send get request.
 * @param url the url
 * @return the http response
 * @throws Exception exception when error
 */
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();
    }
}
 
Example 3
Source File: RestfulServerTest.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 4
Source File: FritzahaWebInterface.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor to set up interface
 * 
 * @param host
 *            Hostname/IP address of Fritzbox
 * @param port
 *            Port to use for Fritzbox connection
 * @param protocol
 *            Protocol to use (HTTP,HTTPS)
 * @param username
 *            Username for login
 * @param password
 *            Password for login
 * @param synctimeout
 *            Timeout for synchronous http-connections
 * @param asynctimeout
 *            Timeout for asynchronous http-connections
 */
public FritzahaWebInterface(String host, int port, String protocol, String username, String password,
        int synctimeout, int asynctimeout) {
    this.host = host;
    this.port = port;
    this.protocol = protocol;
    this.username = username;
    this.password = password;
    this.timeout = synctimeout;
    this.asynctimeout = asynctimeout;
    sid = null;
    asyncclient = new HttpClient(new SslContextFactory(true));
    asyncclient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
    asyncclient.setMaxConnectionsPerAddress(asyncmaxconns);
    asyncclient.setTimeout(asynctimeout);
    try {
        asyncclient.start();
    } catch (Exception e) {
        logger.error("Could not start HTTP Client for " + getURL(""));
    }
    authenticate();
    logger.debug("Starting with SID " + sid);
}