/** * Assumes that there is a "callback" query parameter available in the URI * query string, containing the name of the JavaScript callback method. */ @Override public void afterHandle(Request request, Response response) { // Check the presence of the callback parameter String callback = request.getResourceRef().getQueryAsForm() .getFirstValue("callback"); if (callback != null) { Representation entity = response.getEntity(); if (entity != null && ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON .equals(entity.getMediaType()))) { response.setEntity(new JsonpRepresentation(callback, response .getStatus(), response.getEntity())); response.setStatus(Status.SUCCESS_OK); } } }
/** * Returns the wrapped representation's stream. * * @return The wrapped representation's stream. * @see ContentStream#getStream() */ public InputStream getStream() throws IOException { return representation.getStream(); }
public Representation post(Representation entity) { try { final String topicName = (String) getRequest().getAttributes().get("topicName"); String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = null; if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic())); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to add new topic, with exception: %s", e));
/** * Constructor. * * @param representation * The representation. */ public ContentType(Representation representation) { this(representation.getMediaType(), representation.getCharacterSet()); }
@Override public InputSource getInputSource() throws IOException { if (this.xmlRepresentation.isAvailable()) { return new InputSource(this.xmlRepresentation.getStream()); } return new InputSource((InputStream) null); }
/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. */ public DomRepresentation(Representation xmlRepresentation) { super((xmlRepresentation == null) ? null : xmlRepresentation .getMediaType()); this.setAvailable(xmlRepresentation.isAvailable()); this.xmlRepresentation = xmlRepresentation; }
return DateUtils.format(new Date(), FORMAT_RFC_1123.get(0)); case "ecs": return (entity != null && entity.getCharacterSet() != null) ? entity.getCharacterSet().getName() : null; case "ee": return getEncodingsAsString(entity); return getModificationDateAsString(entity); case "emt": return (entity != null && entity.getMediaType() != null) ? entity.getMediaType().getName() : null; case "es": return (entity != null && entity.getSize() != -1) ? Long.toString(entity.getSize()) : null; case "et": return (entity != null && entity.getTag() != null) ? entity.getTag().getName() : null; case "m": return (this.request.getMethod() != null) ? this.request.getMethod().getName() : null; return (entity != null && entity.getCharacterSet() != null) ? entity.getCharacterSet().getName() : null; case "EE": return getEncodingsAsString(entity); return getModificationDateAsString(entity); case "EMT": return (entity != null && entity.getMediaType() != null) ? entity.getMediaType().getName() : null; case "ES": return (entity != null && entity.getSize() != -1) ? Long.toString(entity.getSize()) : null; case "ET": return (entity != null && entity.getTag() != null) ? entity.getTag().getName() : null; case "S": return (status != null) ? Integer.toString(status.getCode()) : null;
/** * Tests whether the RDF/JSON page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyJson() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 0); }
private void handleQuery( String segment ) Request request = Request.getCurrent(); Response response = Response.getCurrent(); response.setStatus( Status.REDIRECTION_FOUND ); response .setLocationRef( new Reference( request .getResourceRef() .toString() + "/" ).toString() ); return; .getMethod() .isSafe() && queryMethod.getParameterTypes().length != 0 && request .getResourceRef() .getQuery() == null ) || ( !request .getMethod() .isSafe() && queryMethod.getParameterTypes().length != 0 && !( request .getEntity() .isAvailable() || request .getResourceRef() .getQuery() != null || queryMethod
Reference baseRef = new Reference(base); targetRef = new Reference(baseRef, href); } else { targetRef = new Reference(href); String targetUri = targetRef.getTargetRef().toString(); Response response = this.context.getClientDispatcher().handle( new Request(Method.GET, targetUri)); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { try { result = new StreamSource(response.getEntity().getStream()); result.setSystemId(targetUri);
private boolean shouldShowCommandForm( Method interactionMethod ) { // Show form on GET/HEAD if( Request.getCurrent().getMethod().isSafe() ) { return true; } if( interactionMethod.getParameterTypes().length > 0 ) { return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent() .getEntity() .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent() .getResourceRef() .getQuery() != null ); } return false; }
@Override public void write(java.io.Writer writer) throws IOException { writer.write(getCallback()); writer.write("({\"status\":"); writer.write(Integer.toString(getStatus().getCode())); writer.write(",\"body\":"); if (MediaType.APPLICATION_JSON.equals(wrappedRepresentation .getMediaType())) { IoUtils.copy(wrappedRepresentation.getReader(), writer); } else { writer.write("\""); String text = wrappedRepresentation.getText(); if (text.indexOf('\"') >= 0) { text = text.replace("\"", "\\\""); } writer.write(text); writer.write("\""); } writer.write("});"); }
public Representation post(Representation entity) { try { final String topicName = (String) getRequest().getAttributes().get("topicName"); LOGGER.info("received request to whitelist topic {} on mm ", topicName); if (_managerControllerHelix != null) { Form params = getRequest().getResourceRef().getQueryAsForm(); String srcCluster = params.getFirstValue("src"); String dstCluster = params.getFirstValue("dst"); String routeId = params.getFirstValue("routeid"); if (srcCluster == null || dstCluster == null || routeId == null) { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return new StringRepresentation("Missing parameters for whitelisting topic " + topicName + " in federated uReplicator"); getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); String resp = String.format("Failed to add new topic: %s, src=%s, dst=%s, routeid=%s", topicName, srcCluster, dstCluster, routeId); String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = null; if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null if (topicPartitionInfo == null) { LOGGER.warn("failed to whitelist topic {} on mm because of not exists in src cluster", topicName); getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return new StringRepresentation(String.format( "Failed to add new topic: %s, it's not exsited in source kafka cluster!", topicName));
if(nextRequest.getEntity() == null) if(MediaType.MULTIPART_FORM_DATA.equals(nextRequest.getEntity().getMediaType(), true)) OntologyUtils.log.debug("Found multipart/form-data request entity: {}", nextRequest.getEntity()); nextDataHandler); nextResponse.redirectSeeOther(nextRequest.getRootRef().toString(false, false) + propertyUtil.get(OasProps.PROP_ONTOLOGY_MANAGER_PATH, OasProps.DEF_ONTOLOGY_MANAGER_PATH));
method = (Method.HEAD.equals(method)) ? Method.GET : method; if ((getRequest().getEntity() != null) && getRequest().getEntity() .isAvailable()) { MediaType emt = getRequest() .getEntity().getMediaType(); List<MediaType> amts = getMetadataService() .getAllMediaTypes( if (amts != null) { for (MediaType amt : amts) { if (amt.equals(emt)) { score = 1.0f; } else if (amt.includes(emt)) { score = Math.max(0.8f, score); } else if (amt .isCompatible(emt)) { score = Math.max(0.6f, score);
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; }
if (contextResponse.getEntity() == null) { return new ReferenceList(0); if (!MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity().getMediaType())) { this.uniqueReference = contextResponse.getEntity().getLocationRef(); return new ReferenceList(Arrays.asList(contextResponse.getEntity().getLocationRef())); String entryUri = variantReference.toString(); int lastSlashIndex = entryUri.lastIndexOf('/'); String fullEntryName = (lastSlashIndex == -1) ? entryUri : entryUri.substring(lastSlashIndex + 1);
request.bufferEntity(); && response.getStatus().isRecoverableError() && request.getMethod().isIdempotent() && (retryAttempt < getRetryAttempts()) && ((request.getEntity() == null) || request.getEntity() .isAvailable())) { retry(request, response, references, retryAttempt, next); && response.getStatus().isRedirection() && (response.getLocationRef() != null)) { boolean doRedirection = false; if (request.getMethod().isSafe()) { doRedirection = true; } else { if (Status.REDIRECTION_SEE_OTHER.equals(response .getStatus())) {
private Status createFile(Request request, File file) { // This is simple PUT of the full entity try { if (request.isEntityAvailable()) { Files.copy(request.getEntity().getStream(), file.toPath()); return SUCCESS_CREATED; } if (file.createNewFile()) { return SUCCESS_NO_CONTENT; } } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the new file", ioe); return new Status(SERVER_ERROR_INTERNAL, ioe); } String message = "Unable to create the new file"; getLogger().warning(message); return new Status(SERVER_ERROR_INTERNAL, message); }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings() .contains(Encoding.FREEMARKER)) { TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); representation.setDataModel(createDataModel(request, response)); response.setEntity(representation); } }