List of usage examples for org.springframework.web.util UriUtils encodeQuery
public static String encodeQuery(String query, Charset charset)
From source file:org.wheelmap.android.net.TotalNodeCountExecutor.java
@Override public void execute(long id) throws RestServiceException { TotalNodeCountRequestBuilder requestBuilder = null; requestBuilder = new TotalNodeCountRequestBuilder(getServer(), getApiKey(), AcceptType.JSON); try {//w w w. j av a2 s .co m String request = UriUtils.encodeQuery(requestBuilder.buildRequestUri(), "utf-8"); long countTotal = requestNodeCountForURL(request); long countUnknown = requestNodeCountForURL(request + "&wheelchair=unknown"); if (countTotal != -1 && countUnknown != -1 && countTotal > countUnknown) { long count = countTotal - countUnknown; WheelmapApp.getDefaultPrefs().edit().putLong("ItemCountTotal", count).commit(); } } catch (Exception e) { e.printStackTrace(); processException(RestServiceException.ERROR_NETWORK_FAILURE, new NetworkErrorException(), false); } }
From source file:org.wheelmap.android.net.AbstractExecutor.java
protected T executeRequest(RequestBuilder requestBuilder) throws RestServiceException { T content = null;/* ww w . ja v a 2 s .co m*/ String request = null; try { request = UriUtils.encodeQuery(requestBuilder.buildRequestUri(), "utf-8"); } catch (UnsupportedEncodingException e) { processException(RestServiceException.ERROR_INTERNAL_ERROR, e, true); } Log.d("Executer", request); if (request == null) { // workaround for compiling not recognizing that request will be initialized return null; } int retryCount = 0; while (retryCount < fMaxRetryCount) { try { if (requestBuilder.getRequestType() == RequestBuilder.REQUEST_GET) { Log.d(getTag(), "getRequest = *" + request + "*"); content = mRequestProcessor.get(new URI(request), mClazz); } else if (requestBuilder.getRequestType() == RequestBuilder.REQUEST_POST) { Log.d(getTag(), "postRequest = *" + request + "*"); content = (T) mRequestProcessor.post(new URI(request), null, mClazz); } else if (requestBuilder.getRequestType() == RequestBuilder.REQUEST_PUT_PHOTO) { Log.d(getTag(), "uploadPhoto = *" + request + "+"); content = (T) mRequestProcessor.post(new URI(request), null, mClazz); } else if (requestBuilder.getRequestType() == RequestBuilder.REQUEST_MAX_NODE_COUNT) { Log.d(getTag(), "getTotalNodeCount = *" + request + "+"); content = (T) mRequestProcessor.get(new URI(request), mClazz); } else { Log.d(getTag(), "putRequest = *" + request + "*"); mRequestProcessor.put(new URI(request), null); } break; } catch (URISyntaxException e) { processException(RestServiceException.ERROR_INTERNAL_ERROR, e, true); } catch (ResourceAccessException e) { retryCount++; if (retryCount < fMaxRetryCount) { Log.d(getTag(), "request timed out - retrying"); try { Thread.sleep(200); } catch (InterruptedException e1) { // do nothing, just // continue and try // again } continue; } else { processException(RestServiceException.ERROR_NETWORK_FAILURE, e, true); } } catch (HttpClientErrorException e) { HttpStatus status = e.getStatusCode(); checkApiCallClientErrors(e); if (status.value() == statusAuthRequired || (this instanceof ApiKeyExecutor && status.value() == statusBadRequest)) { Log.e(getTag(), "authorization failed - apikey not valid"); processException(RestServiceException.ERROR_AUTHORIZATION_FAILED, e, true); } else if (status.value() == statusRequestForbidden) { Log.e(getTag(), "request forbidden"); processException(RestServiceException.ERROR_REQUEST_FORBIDDEN, e, true); } else if ((status.value() == statusBadRequest) || (status.value() == statusNotFound) || (status.value() == statusNotAcceptable)) { Log.e(getTag(), "request error"); processException(RestServiceException.ERROR_CLIENT_FAILURE, e, true); } else { processException(RestServiceException.ERROR_CLIENT_FAILURE, e, true); } } catch (HttpServerErrorException e) { HttpStatus status = e.getStatusCode(); if (status.value() == statusDownMaintenance) { processException(RestServiceException.ERROR_SERVER_DOWN, e, true); } else { processException(RestServiceException.ERROR_SERVER_FAILURE, e, true); } } catch (HttpMessageConversionException e) { processException(RestServiceException.ERROR_NETWORK_FAILURE, e, false); } catch (RestClientException e) { processException(RestServiceException.ERROR_NETWORK_UNKNOWN_FAILURE, e, true); } } Log.d(getTag(), "executeRequest successful"); if (content != null) { WheelmapApp app = (WheelmapApp) this.getContext().getApplicationContext(); if (content.getClass().toString().equals("class org.wheelmap.android.mapping.node.Photos")) { Log.d("Photos"); try { for (Photo p : ((Photos) content).getPhotos()) { p.getImages().remove(9); p.getImages().remove(8); p.getImages().remove(7); p.getImages().remove(6); p.getImages().remove(5); p.getImages().remove(0); p.getImages().remove(0); p.getImages().remove(0); p.getImages().remove(0); } app.setPhotos((Photos) content); } catch (Exception e) { e.printStackTrace(); } } else if (content.getClass().toString().equals("class org.wheelmap.android.mapping.node.SingleNode")) { Log.d("Node"); try { app.setNode(((SingleNode) content).getNode()); } catch (Exception ex) { ex.printStackTrace(); } } else if (content.getClass().toString().equals("class org.wheelmap.android.mapping.node.Nodes")) { int size = ((Nodes) content).getNodes().size(); if (size == 0) { if (app.isSearching() == true) app.setSearchSuccessfully(false); else app.setSearchSuccessfully(true); } } } return content; }
From source file:org.openmrs.module.openhmis.cashier.web.controller.BillAddEditController.java
private String encodeRequestQuery(HttpServletRequest request) { String requestQueryParam = ""; try {//from ww w . ja va 2 s . c o m requestQueryParam = UriUtils.encodeQuery("?" + request.getQueryString(), "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error("UnsupportedEncodingException occured when trying to encode request query", e); } return requestQueryParam; }
From source file:com.tyro.oss.pact.spring4.pact.consumer.ReturnExpect.java
private static String urlencode(String path) { try {// w w w .j a va 2 s .c o m return UriUtils.encodeQuery(path, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.esupportail.publisher.web.rest.SubscriberResource.java
/** * POST /subscribers -> Create a new subscriber. */// www . j av a2 s .c o m @RequestMapping(value = "/subscribers", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(SecurityConstants.IS_ROLE_ADMIN + " || " + SecurityConstants.IS_ROLE_USER + " && @permissionService.canEditCtxTargets(authentication, #subscriber.subjectCtxId.context)") @Timed public ResponseEntity<Void> create(@Validated @RequestBody Subscriber subscriber) throws URISyntaxException, UnsupportedEncodingException { log.debug("REST request to save Subscriber : {}", subscriber); if (subscriberRepository.findOne(subscriber.getId()) != null) { return ResponseEntity.badRequest().header("Failure", "The subscriber should not already exist").build(); } // TODO: check if the context can support subscribers EnumSet<ContextType> ctxTypes = EnumSet.of(ContextType.ORGANIZATION, ContextType.PUBLISHER); boolean subscribersOnCtx = false; switch (subscriber.getSubjectCtxId().getContext().getKeyType()) { case ORGANIZATION: subscribersOnCtx = true; break; case PUBLISHER: subscribersOnCtx = true; break; case CATEGORY: case FEED: AbstractClassification classif = classificationRepository .findOne(subscriber.getSubjectCtxId().getContext().getKeyId()); if (classif != null && !WritingMode.TARGETS_ON_ITEM .equals(classif.getPublisher().getContext().getRedactor().getWritingMode()) && classif.getPublisher().isHasSubPermsManagement()) { subscribersOnCtx = true; } break; case ITEM: AbstractItem item = itemRepository.findOne(subscriber.getSubjectCtxId().getContext().getKeyId()); if (item != null && WritingMode.TARGETS_ON_ITEM.equals(item.getRedactor().getWritingMode())) { subscribersOnCtx = true; } break; default: // non bloquant log.warn("ContextType unknown !"); break; } if (!subscribersOnCtx) { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } subscriberRepository.save(subscriber); String composedIdURL = new String( Base64.encodeBase64(subscriber.getId().getSubject().getKeyValue().getBytes(StandardCharsets.UTF_8))) + "/"; composedIdURL += subscriber.getId().getSubject().getKeyType().getId() + "/"; composedIdURL += subscriber.getId().getSubject().getKeyAttribute() + "/"; composedIdURL += subscriber.getId().getContext().getKeyId() + "/"; composedIdURL += subscriber.getId().getContext().getKeyType().name(); log.debug(composedIdURL); return ResponseEntity .created(new URI( "/api/subscribers/" + UriUtils.encodeQuery(composedIdURL, StandardCharsets.UTF_8.name()))) .build(); }