@Override public void acceptRepresentation(Representation entity) throws ResourceException { Form form = getRequest().getEntityAsForm(); chosenEngine = form.getFirstValue("engine"); String script = form.getFirstValue("script"); if(StringUtils.isBlank(script)) { script=""; } ScriptEngine eng = MANAGER.getEngineByName(chosenEngine); scriptingConsole.bind("scriptResource", this); scriptingConsole.execute(eng, script); scriptingConsole.unbind("scriptResource"); //TODO: log script, results somewhere; job log INFO? getResponse().setEntity(represent()); }
Restlet sayHello = new Restlet() { @Override public void handle(Request request, Response response) { response.setEntity("Hello World!", MediaType.TEXT_PLAIN); } }; new Server(Protocol.HTTP, 80, sayHello).start();
/** * Sets the entity representation. * * @param entity * The entity representation. */ @Override public void setEntity(Representation entity) { getWrappedResponse().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) { getWrappedResponse().setEntity(value, mediaType); }
private void handleDoGet(Response response, TileLayer tl, boolean listAllTasks) { response.setEntity(makeFormPage(tl, listAllTasks), MediaType.TEXT_HTML); }
@Override public void handleGet() { Representation representation = new StringRepresentation(String.valueOf(count), MediaType.TEXT_PLAIN); getResponse().setEntity(representation); } }
Component c = new Component(); c.getServers().add(Protocol.HTTP, 8182); VirtualHost host = new VirtualHost(); host.setHostDomain("localhost"); c.getHosts().add(host); host.attach(new Restlet() { @Override public void handle(Request request, Response response) { response.setEntity("hello, world", MediaType.TEXT_PLAIN); } }); c.start();
TemplateRoute route = component.getDefaultHost().attach( "/test", new Restlet() { @Override public void handle(Request request, Response response) { response.setEntity("test", MediaType.TEXT_PLAIN); } }); // Default matching mode int defaultMatching = route.getMatchingMode(); // Set another matching mode route.setMatchingMode(Template.MODE_EQUALS);
private void handleKillThreadPost(Form form, TileLayer tl, Response resp) { String id = form.getFirstValue("thread_id"); StringBuilder doc = new StringBuilder(); makeHeader(doc); if (seeder.terminateGWCTask(Long.parseLong(id))) { doc.append("<ul><li>Requested to terminate task " + id + ".</li></ul>"); } else { doc.append("<ul><li>Sorry, either task " + id + " has not started yet, or it is a truncate task that cannot be interrutped.</li></ul>"); ; } if (tl != null) { doc.append("<p><a href=\"./" + tl.getName() + "\">Go back</a></p>\n"); } resp.setEntity(doc.toString(), MediaType.TEXT_HTML); }
@Override protected void afterHandle(Request request, Response response) { if (getMode() == MODE_RESPONSE) { response.setEntity(transform(response.getEntity())); } }
@Override public void handleGet() { Representation represeentation = new DescribeJSONFormat().toRepresentation(featureType); getResponse().setEntity(represeentation); }
@Override protected void afterHandle(Request request, Response response) { if (getMode() == MODE_RESPONSE) { response.setEntity(transform(response.getEntity())); } }
@Override public void handleGet() { Representation representation = new FeaturesJSONFormat().toRepresentation(features); getResponse().setEntity(representation); }
@Override public void handleGet() { Representation representation = new CapabilitiesJSONFormat().toRepresentation(catalog); getResponse().setEntity(representation); }
@Override public void handleGet() { getResponse().setEntity(new FileRepresentation(getTemplateFile(), MEDIATYPE_FTL, 0)); }
public void handle(Request request, Response response) { Method met = request.getMethod(); try { if (met.equals(Method.POST)) { doPost(request, response); } else { throw new RestletException("Method not allowed", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (RestletException re) { response.setEntity(re.getRepresentation()); response.setStatus(re.getStatus()); } catch (IOException ioe) { response.setEntity("Encountered IO error " + ioe.getMessage(), MediaType.TEXT_PLAIN); response.setStatus(Status.SERVER_ERROR_INTERNAL); } }
@Override public void acceptRepresentation(Representation entity) throws ResourceException { Form form = getRequest().getEntityAsForm(); chosenEngine = form.getFirstValue("engine"); String script = form.getFirstValue("script"); if(StringUtils.isBlank(script)) { script=""; } ScriptEngine eng = MANAGER.getEngineByName(chosenEngine); scriptingConsole.bind("scriptResource", this); scriptingConsole.execute(eng, script); scriptingConsole.unbind("scriptResource"); //TODO: log script, results somewhere; job log INFO? getResponse().setEntity(represent()); }
@Override public void handleGet() { String bbox = "[" + bounds.getMinX() + ", " + bounds.getMinY() + ", " + bounds.getMaxX() + ", " + bounds.getMaxY() + "]"; Representation representation = new StringRepresentation(bbox, MediaType.APPLICATION_JSON); getResponse().setEntity(representation); } }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains( Encoding.FREEMARKER)) { final TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); if (this.dataModel == null) { representation.setDataModel(request, response); } else { representation.setDataModel(this.dataModel); } response.setEntity(representation); } }
public void handle(Request request, Response response) { Method met = request.getMethod(); try { if (met.equals(Method.POST)) { doPost(request, response); } else { throw new RestletException("Method not allowed", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (RestletException re) { response.setEntity(re.getRepresentation()); response.setStatus(re.getStatus()); } }