List of usage examples for org.apache.http.client.utils URIBuilder setParameter
public URIBuilder setParameter(final String param, final String value)
From source file:api.Client.java
public Request<UploadStatus> uploadProductImageApiUploadService(Number storeId, String token, Number id, InputStream body) {/* www .j a va2s . co m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/image"); 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<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(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 UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeletedDiscountCouponsResponse> discountCouponsDeletedEntityService(Number storeId, String token, String from_date, String to_date, Number offset, Number limit) { try {/*from ww w .j av a 2 s . c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons/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<DeletedDiscountCouponsResponse>(getRequestExecutor(), builder.build()) { @Override public DeletedDiscountCouponsResponse 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 DeletedDiscountCouponsResponse(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<UploadStatus> uploadCategoryImageApiUploadService(Number storeId, String token, Number id, InputStream body) {//from w w w . jav a 2 s. c om try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/categories/" + id + "/image"); 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<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(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 UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeleteStatus> clearCombinationsProductApiService(Number storeId, String token, Number id) { try {/*w w w . j a v a2 s.co m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/combinations"); 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"); 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<UploadStatus> uploadProductGalleryImageApiUploadService(Number storeId, String token, String fileName, Number id, InputStream body) { try {/*from w w w . j a va2 s . c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/gallery"); if (token != null) builder.setParameter("token", token.toString()); if (fileName != null) builder.setParameter("fileName", fileName.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<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(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 UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<UploadStatus> uploadProductFileApiUploadService(Number storeId, String token, Number id, String fileName, String description, InputStream body) { try {/*from ww w . j a v a 2 s . c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/files"); if (token != null) builder.setParameter("token", token.toString()); if (description != null) builder.setParameter("description", description.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); if (id == null) throw new IllegalArgumentException("No parameter id is set"); if (fileName == null) throw new IllegalArgumentException("No parameter fileName is set"); builder.setParameter("fileName", fileName.toString()); if (body == null) throw new IllegalArgumentException("No request body"); return new Request<UploadStatus>(getRequestExecutor(), builder.build(), createInputStreamEntity(body)) { @Override public UploadStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(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 UploadStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<List<Combination>> getCombinationsProductApiService(Number storeId, String token, Number id) { try {/*w ww .jav a2s . co m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/combinations"); 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"); return new Request<List<Combination>>(getRequestExecutor(), builder.build()) { @Override public List<Combination> 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 array."); JSONArray list = new JSONArray(EntityUtils.toString(entity)); List<Combination> result = new ArrayList<Combination>(list.length()); for (int i = 0; i < list.length(); i++) { result.add(new Combination(list.getJSONObject(i))); } return result; } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<CreateStatus> createCombinationProductApiService(Number storeId, String token, Number id, Combination body) {// www . j a v a 2 s .c om try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/combinations"); 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<CreateStatus>(getRequestExecutor(), builder.build(), new StringEntity(body.asJson().toString(), ContentType.APPLICATION_JSON)) { @Override public CreateStatus execute(RequestExecutor executor) throws IOException, JSONException { HttpPost method = new HttpPost(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 CreateStatus(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<ProductSearchResult> searchProductApiService(Number storeId, String keyword, Number priceFrom, Number priceTo, Number category, Boolean withSubcategories, String sortBy, Number offset, Number limit, String createdFrom, String createdTo, String updatedFrom, String updatedTo, Boolean enabled, Boolean inStock, String token) { try {/*from w w w. ja v a2 s .c om*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products"); if (keyword != null) builder.setParameter("keyword", keyword.toString()); if (priceFrom != null) builder.setParameter("priceFrom", priceFrom.toString()); if (priceTo != null) builder.setParameter("priceTo", priceTo.toString()); if (category != null) builder.setParameter("category", category.toString()); if (withSubcategories != null) builder.setParameter("withSubcategories", withSubcategories.toString()); if (sortBy != null) builder.setParameter("sortBy", sortBy.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (createdFrom != null) builder.setParameter("createdFrom", createdFrom.toString()); if (createdTo != null) builder.setParameter("createdTo", createdTo.toString()); if (updatedFrom != null) builder.setParameter("updatedFrom", updatedFrom.toString()); if (updatedTo != null) builder.setParameter("updatedTo", updatedTo.toString()); if (enabled != null) builder.setParameter("enabled", enabled.toString()); if (inStock != null) builder.setParameter("inStock", inStock.toString()); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<ProductSearchResult>(getRequestExecutor(), builder.build()) { @Override public ProductSearchResult 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 ProductSearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<InputStream> getProductEgoodApiUploadService(Number storeId, String token, Number id, Number fileId) {/*from w w w . j av a2 s .c o m*/ try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/" + id + "/files/" + fileId); 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 (fileId == null) throw new IllegalArgumentException("No parameter fileId is set"); return new Request<InputStream>(getRequestExecutor(), builder.build()) { @Override public InputStream 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 binary output."); return entity.getContent(); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }