public Request getTopicCreationRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.POST, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; }
public Request getTopicExpansionRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.PUT, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; } }
@Override public void setEntity(Representation entity) { super.setEntity(entity); this.entityAdded = true; }
/** * Sets the entity representation. * * @param entity * The entity representation. */ @Override public void setEntity(Representation entity) { getWrappedRequest().setEntity(entity); }
/** * Sets a textual entity. * * @param value * The represented string. * @param mediaType * The representation's media type. */ @Override public void setEntity(String value, MediaType mediaType) { getWrappedRequest().setEntity(value, mediaType); }
Filter filter = new Filter(getContext()) { @Override protected int beforeHandle(Request request, Response response) { try { JsonRepresentation jrep = new JsonRepresentation(request.getEntity()); String token = jrep.getJsonObject().getString("token"); System.out.println(token); request.setEntity(jrep); } catch (JSONException | IOException e) { throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } return super.beforeHandle(request, response); } };
Filter filter = new Filter(getContext()) { @Override protected int beforeHandle(Request request, Response response) { try { JsonRepresentation jrep = new JsonRepresentation(request.getEntity()); JSONObject jo = jrep.getJsonObject(); String token = jo.getString("token"); System.out.println(token); request.setEntity(new JsonRepresentation(jo)); } catch (JSONException | IOException e) { throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } return super.beforeHandle(request, response); } };
private boolean containsToken(Request request) { try { Representation repr = request.getEntity(); String content = repr.getText(); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> jsonContent = objectMapper.readValue( content, Map.class); StringRepresentation sRepr = new StringRepresentation( content, repr.getMediaType()); request.setEntity(sRepr); if (jsonContent.get("token") != null) { return true; } } catch (Exception ex) { (...) } return false; }
@Override public void setInputStream(InputStream stream) { getRequest().setEntity(new InputRepresentation(stream)); }
@Override public boolean writeRequest(Object requestObject, Request request) throws ResourceException { if (requestObject == null) { if (!Method.GET.equals(request.getMethod())) request.setEntity(new EmptyRepresentation()); return true; } if (requestObject instanceof Representation) { request.setEntity((Representation) requestObject); return true; } for (RequestWriter requestWriter : requestWriters) { if (requestWriter.writeRequest(requestObject, request)) return true; } return false; } }
Form form = new Form(); form.add("foo", "bar"); form.add("abc", "123"); Request request = new Request(Method.POST, "http://host/path/to/resource"); request.setEntity(form.getWebRepresentation()); request.setReferrerRef("http://host/path/to/referrer"); Response response = client.handle(request);
@Override protected int beforeHandle(Request request, Response response) { if ((getMode() == MODE_REQUEST) && canTransform(request.getEntity())) { request.setEntity(transform(request.getEntity())); } return CONTINUE; }
public Request getTopicExpansionRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.PUT, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; } }
public Request getTopicCreationRequestUrl(String topic, int numPartitions) { Request request = new Request(Method.POST, _baseUrl + "/topics/"); TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions); request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON); return request; }
/** * @param mediaType * @param entityStream * @return */ static Form getForm(MediaType mediaType, InputStream entityStream) { Form form = new Form(new InputRepresentation(entityStream, toRestletMediaType(mediaType))); Request.getCurrent().setEntity(form.getWebRepresentation()); return form; }
/** * Allows filtering before its handling by the target Restlet. Does nothing * by default. * * @param request * The request to filter. * @param response * The response to filter. * @return The continuation status. */ @Override public int beforeHandle(Request request, Response response) { // Check if decoding of the request entity is needed if (isDecodingRequest() && canDecode(request.getEntity())) { request.setEntity(decode(request.getEntity())); } return CONTINUE; }
@Override public boolean writeRequest(Object requestObject, Request request) throws ResourceException { if (requestObject instanceof Form) { // Form as query parameters if (request.getMethod().equals(Method.GET)) request.getResourceRef().setQuery(((Form)requestObject).getQueryString()); else request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8)); return true; } return false; } }
private String getAccessTokenFromBody(Request request) { Method method = request.getMethod(); if (method.equals(Method.GET)) { return null; } Representation entity = request.getEntity(); if (entity != null && !MediaType.APPLICATION_WWW_FORM .equals(entity.getMediaType())) { return null; } Form form = new Form(request.getEntity()); final String token = form .getFirstValue(OAuthServerResource.ACCESS_TOKEN); if (token == null || token.isEmpty()) { return null; } // Restore the body request.setEntity(form.getWebRepresentation()); logger.fine("Found Bearer Token in Body."); return token; }
/** * Allows filtering before its handling by the target Restlet. Does nothing * by default. * * @param request * The request to filter. * @param response * The response to filter. * @return The continuation status. */ @Override public int beforeHandle(Request request, Response response) { // Check if encoding of the request entity is needed if (isEncodingRequest() && getEncoderService().canEncode(request.getEntity())) { request.setEntity(encode(request.getClientInfo(), request.getEntity())); } return CONTINUE; }
@Override public Representation put(Representation entity) throws ResourceException { if (!this.directory.isModifiable()) { setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, "The directory is not modifiable."); return null; } // Transfer of PUT calls is only allowed if the readOnly flag is not set. Request contextRequest = new Request(Method.PUT, this.targetUri); // Add support of partial PUT calls. contextRequest.getRanges().addAll(getRanges()); contextRequest.setEntity(entity); Response contextResponse = new Response(contextRequest); contextRequest.setResourceRef(this.targetUri); getClientDispatcher().handle(contextRequest, contextResponse); setStatus(contextResponse.getStatus()); return null; }