Example usage for org.apache.http.client.utils URIBuilder setParameter

List of usage examples for org.apache.http.client.utils URIBuilder setParameter

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder setParameter.

Prototype

public URIBuilder setParameter(final String param, final String value) 

Source Link

Document

Sets parameter of URI query overriding existing value if set.

Usage

From source file:api.Client.java

public Request<UpdateStatus> updateCustomerApiService(Number storeId, String token, Number id, Customer body) {
    try {/*w w w .  j av  a  2 s . c om*/
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/customers/" + id);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (id == null)
            throw new IllegalArgumentException("No parameter id is set");

        if (body == null)
            throw new IllegalArgumentException("No request body");
        return new Request<UpdateStatus>(getRequestExecutor(), builder.build(),
                new StringEntity(body.asJson().toString(), ContentType.APPLICATION_JSON)) {
            @Override
            public UpdateStatus execute(RequestExecutor executor) throws IOException, JSONException {
                HttpPut method = new HttpPut(uri);
                method.setEntity(body);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new UpdateStatus(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DeletedOrdersResponse> ordersDeletedEntityService(Number storeId, String token, String from_date,
        String to_date, Number offset, Number limit) {
    try {/* w ww. j  av  a 2 s .c o  m*/
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/deleted");
        if (token != null)
            builder.setParameter("token", token.toString());
        if (from_date != null)
            builder.setParameter("from_date", from_date.toString());
        if (to_date != null)
            builder.setParameter("to_date", to_date.toString());
        if (offset != null)
            builder.setParameter("offset", offset.toString());
        if (limit != null)
            builder.setParameter("limit", limit.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        return new Request<DeletedOrdersResponse>(getRequestExecutor(), builder.build()) {
            @Override
            public DeletedOrdersResponse execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DeletedOrdersResponse(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<UpdateStatus> updateCategoryService(Number storeId, Number id, String token, Category body) {
    try {// ww  w  .j  av  a  2 s  . c  o m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/categories/" + id);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (id == null)
            throw new IllegalArgumentException("No parameter id is set");

        if (body == null)
            throw new IllegalArgumentException("No request body");
        return new Request<UpdateStatus>(getRequestExecutor(), builder.build(),
                new StringEntity(body.asJson().toString(), ContentType.APPLICATION_JSON)) {
            @Override
            public UpdateStatus execute(RequestExecutor executor) throws IOException, JSONException {
                HttpPut method = new HttpPut(uri);
                method.setEntity(body);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new UpdateStatus(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<Product> getProductApiService(Number storeId, Number productId, String token) {
    try {//w ww .  ja v a2  s .  c  o  m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + productId);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (productId == null)
            throw new IllegalArgumentException("No parameter productId is set");

        return new Request<Product>(getRequestExecutor(), builder.build()) {
            @Override
            public Product execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new Product(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DeleteStatus> deleteProductApiService(Number storeId, Number productId, String token) {
    try {/*from w  w  w. j a  v  a  2s.c o  m*/
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + productId);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (productId == null)
            throw new IllegalArgumentException("No parameter productId is set");

        return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) {
            @Override
            public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException {
                HttpDelete method = new HttpDelete(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DeleteStatus(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<Order> getOrderOrderApiService(Number storeId, String token, Number orderNumber) {
    try {/*from   w  ww. j  a v a  2s.  c o  m*/
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/" + orderNumber);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (orderNumber == null)
            throw new IllegalArgumentException("No parameter orderNumber is set");

        return new Request<Order>(getRequestExecutor(), builder.build()) {
            @Override
            public Order execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new Order(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DeleteStatus> removeOrderOrderApiService(Number storeId, Number orderNumber, String token) {
    try {/*from  w  ww.  ja  v a 2 s .  c  o m*/
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/" + orderNumber);
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        if (orderNumber == null)
            throw new IllegalArgumentException("No parameter orderNumber is set");

        return new Request<DeleteStatus>(getRequestExecutor(), builder.build()) {
            @Override
            public DeleteStatus execute(RequestExecutor executor) throws IOException, JSONException {
                HttpDelete method = new HttpDelete(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DeleteStatus(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DeletedProductsResponse> productsDeletedEntityService(Number storeId, String token,
        String from_date, String to_date, Number offset, Number limit) {
    try {// w w  w. j av a  2 s .c  o  m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/deleted");
        if (token != null)
            builder.setParameter("token", token.toString());
        if (from_date != null)
            builder.setParameter("from_date", from_date.toString());
        if (to_date != null)
            builder.setParameter("to_date", to_date.toString());
        if (offset != null)
            builder.setParameter("offset", offset.toString());
        if (limit != null)
            builder.setParameter("limit", limit.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        return new Request<DeletedProductsResponse>(getRequestExecutor(), builder.build()) {
            @Override
            public DeletedProductsResponse execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DeletedProductsResponse(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DiscountCouponResult> listDiscountCouponService(Number storeId, String code,
        String discount_type, String availability, Number limit, Number offset, String token) {
    try {//from w w  w.java 2 s . c  o m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons");
        if (code != null)
            builder.setParameter("code", code.toString());
        if (discount_type != null)
            builder.setParameter("discount_type", discount_type.toString());
        if (availability != null)
            builder.setParameter("availability", availability.toString());
        if (limit != null)
            builder.setParameter("limit", limit.toString());
        if (offset != null)
            builder.setParameter("offset", offset.toString());
        if (token != null)
            builder.setParameter("token", token.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        return new Request<DiscountCouponResult>(getRequestExecutor(), builder.build()) {
            @Override
            public DiscountCouponResult execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DiscountCouponResult(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:api.Client.java

public Request<DeletedCustomersResponse> customersDeletedEntityService(Number storeId, String token,
        String from_date, String to_date, Number offset, Number limit) {
    try {// ww  w  .j  av  a  2s .c  o  m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/customers/deleted");
        if (token != null)
            builder.setParameter("token", token.toString());
        if (from_date != null)
            builder.setParameter("from_date", from_date.toString());
        if (to_date != null)
            builder.setParameter("to_date", to_date.toString());
        if (offset != null)
            builder.setParameter("offset", offset.toString());
        if (limit != null)
            builder.setParameter("limit", limit.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        return new Request<DeletedCustomersResponse>(getRequestExecutor(), builder.build()) {
            @Override
            public DeletedCustomersResponse execute(RequestExecutor executor)
                    throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new DeletedCustomersResponse(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}