Search in sources :

Example 6 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method postUrlAsString.

/**
 * 通过POST方法请求url
 *
 * @param url
 * @param params
 */
public static void postUrlAsString(String url, Map<String, String> params, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.setBodyEncoding("utf-8");
        setPostParams(params, rb);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 7 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method uploadFile.

public static void uploadFile(String url, Map<String, String> params, File file, String inputName, String fileName, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        setPostParams(params, rb);
        FilePart part = new FilePart(inputName, fileName, file);
        rb.addBodyPart(part);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException) FilePart(com.ning.http.multipart.FilePart)

Example 8 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method getUrlAsString.

/**
 * 通过GET方法请求url
 *
 * @param url
 * @param params
 */
public static void getUrlAsString(String url, Map<String, String> params, int reqTimeout, HttpResultCallback callback) {
    if (StringUtils.isBlank(url)) {
        return;
    }
    String gurl = getFullUrl(url, params, "utf-8");
    try {
        BoundRequestBuilder rb = getAsyncHttpClient(reqTimeout).prepareGet(gurl);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 9 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method postBodyAsString.

/**
 * 通过POST方法请求url
 *
 * @param url
 * @param body
 */
public static void postBodyAsString(String url, String body, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.setBodyEncoding("utf-8");
        rb.setBody(body);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 10 with BoundRequestBuilder

use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project openhab1-addons by openhab.

the class PlexConnector method internalSendCommand.

private void internalSendCommand(String machineIdentifier, String url) throws IOException {
    logger.debug("Calling url {}", url);
    BoundRequestBuilder builder = client.prepareGet(url).setHeaders(getDefaultHeaders()).setHeader("X-Plex-Target-Client-Identifier", machineIdentifier);
    builder.execute(new AsyncCompletionHandler<Response>() {

        @Override
        public Response onCompleted(Response response) throws Exception {
            if (response.getStatusCode() != 200) {
                logger.error("Error while sending command to Plex: {}\r\n{}", response.getStatusText(), response.getResponseBody());
            }
            return response;
        }

        @Override
        public void onThrowable(Throwable t) {
            logger.error("Error sending command to Plex", t);
        }
    });
}
Also used : Response(com.ning.http.client.Response) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) TimeoutException(org.jboss.netty.handler.timeout.TimeoutException) JAXBException(javax.xml.bind.JAXBException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) JsonParseException(org.codehaus.jackson.JsonParseException)

Aggregations

BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)15 IOException (java.io.IOException)12 Response (com.ning.http.client.Response)3 ExecutionException (java.util.concurrent.ExecutionException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)2 BoundRequestBuilder (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)2 Response (org.apache.apex.shaded.ning19.com.ning.http.client.Response)2 Cookie (org.apache.apex.shaded.ning19.com.ning.http.client.cookie.Cookie)2 WebSocketUpgradeHandler (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)1 Request (com.ning.http.client.Request)1 FilePart (com.ning.http.multipart.FilePart)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1