Refine search
/** * Constructs a nested Map data structure with the information represented * by this Resource. The result is particularly suitable for use with with * {@link XmlMarshaller}. * * @return the nested Map data structure */ protected ScriptModel makeDataModel() { String baseRef = getRequest().getResourceRef().getBaseRef().toString(); if(!baseRef.endsWith("/")) { baseRef += "/"; } Reference baseRefRef = new Reference(baseRef); ScriptModel model = new ScriptModel(scriptingConsole, new Reference(baseRefRef, "..").getTargetRef().toString(), getAvailableScriptEngines()); return model; }
public JobRelatedResource(Context ctx, Request req, Response res) throws ResourceException { super(ctx, req, res); cj = getEngine().getJob((String)req.getAttributes().get("job")); if(cj==null) { throw new ResourceException(404); } }
/** * If client can accept text/html, always prefer it. WebKit-based browsers * claim to want application/xml, but we don't want to give it to them. See * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a> */ public Variant getPreferredVariant() { boolean addExplicitTextHtmlPreference = false; for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) { if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) { mediaTypePreference.setQuality(Float.MAX_VALUE); addExplicitTextHtmlPreference = false; break; } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) { addExplicitTextHtmlPreference = true; } } if (addExplicitTextHtmlPreference) { List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes(); acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE)); getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes); } return super.getPreferredVariant(); }
public void acceptRepresentation(Representation entity) throws ResourceException { if (appCtx == null) { throw new ResourceException(404); } // copy op? Form form = getRequest().getEntityAsForm(); beanPath = form.getFirstValue("beanPath"); String newVal = form.getFirstValue("newVal"); if(newVal!=null) { int i = beanPath.indexOf("."); String beanName = i<0?beanPath:beanPath.substring(0,i); Object namedBean = appCtx.getBean(beanName); BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean); String propPath = beanPath.substring(i+1); Object coercedVal = bwrap.convertIfNecessary(newVal, bwrap.getPropertyValue(propPath).getClass()); bwrap.setPropertyValue(propPath, coercedVal); } Reference ref = getRequest().getResourceRef(); ref.setPath(getBeansRefPath()); ref.addSegment(beanPath); getResponse().redirectSeeOther(ref); }
protected void writeHtml(Writer writer) { String baseRef = getRequest().getResourceRef().getBaseRef().toString(); if(!baseRef.endsWith("/")) { baseRef += "/"; } Configuration tmpltCfg = getTemplateConfiguration(); ViewModel viewModel = new ViewModel(); viewModel.setFlashes(Flash.getFlashes(getRequest())); viewModel.put("baseRef",baseRef); viewModel.put("staticRef", getStaticRef("")); viewModel.put("baseResourceRef",getRequest().getRootRef().toString()+"/engine/static/"); viewModel.put("model", makeDataModel()); viewModel.put("selectedEngine", chosenEngine); try { Template template = tmpltCfg.getTemplate("Script.ftl"); template.process(viewModel, writer); writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } catch (TemplateException e) { throw new RuntimeException(e); } } }
protected String buildUploadFailedHtmlResponse(Throwable t, Request request, Response response) { try { handleException(request, response, t); } catch (ResourceException e) { getLogger().debug("Got error while uploading artifact", t); StringBuilder resp = new StringBuilder(); resp.append("<html><body><error>"); resp.append(StringEscapeUtils.escapeHtml(e.getMessage())); resp.append("</error></body></html>"); String forceSuccess = request.getResourceRef().getQueryAsForm().getFirstValue("forceSuccess"); if (!"true".equals(forceSuccess)) { response.setStatus(e.getStatus()); } return resp.toString(); } // We have an error at this point, can't get here return null; }
/** * Constructs a nested Map data structure with the information represented * by this Resource. The result is particularly suitable for use with with * {@link XmlMarshaller}. * * @return the nested Map data structure */ protected CrawlJobModel makeDataModel() { String baseRef = getRequest().getResourceRef().getBaseRef().toString(); if (!baseRef.endsWith("/")) { baseRef += "/"; } return new CrawlJobModel(cj,baseRef); }
protected boolean isDescribe( Request request ) { // check do we need describe return request.getResourceRef().getQueryAsForm().getFirst( IS_DESCRIBE_PARAMETER ) != null; }
public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { Form form = request.getResourceRef().getQueryAsForm(); final long timeout = Long.parseLong(form.getFirstValue("timeout", "60000")); try { final long startTime = System.currentTimeMillis(); while (System.currentTimeMillis() - startTime <= timeout) { if (!((ManagerImpl) manager).isUpdatePrefixFileJobRunning()) { response.setStatus(Status.SUCCESS_OK); return "Ok"; } Thread.sleep(500); } } catch (final InterruptedException ignore) { // ignore } response.setStatus(Status.SUCCESS_ACCEPTED); return "Still munching on them..."; } }
Response response) { final Reference baseRef = request.getResourceRef().getBaseRef(); request.setResourceRef(targetRef); request.getAttributes().remove("org.restlet.http.headers"); getContext().getClientDispatcher().handle(request, response); response.setEntity(rewrite(response.getEntity())); response.getAttributes().remove("org.restlet.http.headers"); final Template rt = new Template(this.targetTemplate); rt.setLogger(getLogger()); final int matched = rt.parse(response.getLocationRef().toString(), request); final String remainingPart = (String) request.getAttributes() .get("rr"); response.setLocationRef(baseRef.toString() + remainingPart);
@Override public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { Form form = request.getResourceRef().getQueryAsForm(); int requestedStatus = Integer.parseInt(form.getFirstValue("status")); throw new ResourceException(requestedStatus); } }
public List<Variant> getVariants() { List<Variant> variants = super.getVariants(); Form f = getRequest().getResourceRef().getQueryAsForm(); String format = f.getFirstValue("format"); if("textedit".equals(format)) { if(variants.isEmpty()) { FileRepresentation)v, this, f.getFirstValue("pos"), f.getFirstValue("lines"), f.getFirstValue("reverse"))); };
public String getRestRepoRemoteStatus( ProxyRepository repository, Request request, Response response ) throws ResourceException { Form form = request.getResourceRef().getQueryAsForm(); boolean forceCheck = form.getFirst( "forceCheck" ) != null; RemoteStatus rs = repository.getRemoteStatus( new ResourceStoreRequest( RepositoryItemUid.PATH_ROOT ), forceCheck ); if ( RemoteStatus.UNKNOWN.equals( rs ) ) { // set status to ACCEPTED, since we have incomplete info response.setStatus( Status.SUCCESS_ACCEPTED ); } return rs == null ? null : rs.toString(); }
/** * GET outputs an existing layer * * @param req * @param resp * @throws RestletException * @throws */ protected void doGet(Request req, Response resp) throws RestletException { String layerName = (String) req.getAttributes().get("layer"); final String formatExtension = (String) req.getAttributes().get("extension"); Representation representation; if (layerName == null) { String restRoot = req.getResourceRef().getParentRef().toString(); if (restRoot.endsWith("/")) { restRoot = restRoot.substring(0, restRoot.length() - 1); } representation = listLayers(formatExtension, restRoot); } else { try { layerName = URLDecoder.decode(layerName, "UTF-8"); } catch (UnsupportedEncodingException uee) { } representation = doGetInternal(layerName, formatExtension); } resp.setEntity(representation); }
final Request request = new Request(); request.setResourceRef(url.toString()); request.setMethod(method); request.setEntity(representation); request.getClientInfo().getAcceptedMediaTypes().add( new Preference<MediaType>(representation.getMediaType()));
@Override public Object upload(Context context, Request request, Response response, List<FileItem> files) throws ResourceException { // NEXUS-4151: Do not accept upload/deploy requests with media type (Content-Type) of // "application/x-www-form-urlencoded", since ad 1, it's wrong, ad 2, we do know // Jetty's Request object "eats" up it's body to parse request parameters, invoked // way earlier in security filters if (request.isEntityAvailable()) { MediaType mt = request.getEntity().getMediaType(); if (mt != null && MediaType.APPLICATION_WWW_FORM.isCompatible(mt)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString() + "\" is not acceptable for uploads!"); } } try { final ResourceStoreRequest req = getResourceStoreRequest(request); for (FileItem fileItem : files) { getResourceStore(request).storeItem(req, fileItem.getInputStream(), null); } } catch (Exception t) { handleException(request, response, t); } return null; }
public static String findIP( Request request ) { Form form = (Form) request.getAttributes().get( "org.restlet.http.headers" ); String forwardedIP = getFirstForwardedIp( form.getFirstValue( FORWARD_HEADER ) ); if ( forwardedIP != null ) { return forwardedIP; } List<String> ipAddresses = request.getClientInfo().getAddresses(); return resolveIp( ipAddresses ); }
/** * Sets the reference that the client should follow for redirections or * resource creations. If you pass a relative location URI, it will be * resolved with the current base reference of the request's resource * reference (see {@link Request#getResourceRef()} and * {@link Reference#getBaseRef()}. * * @param locationUri * The URI to set. */ public void setLocationRef(String locationUri) { Reference baseRef = null; if (getRequest().getResourceRef() != null) { if (getRequest().getResourceRef().getBaseRef() != null) { baseRef = getRequest().getResourceRef().getBaseRef(); } else { baseRef = getRequest().getResourceRef(); } } setLocationRef(new Reference(baseRef, locationUri).getTargetRef()); }
@Override public HttpClientCall create(Request request) { HttpClientCall result = null; try { result = new Hc4MethodCall(this, request.getMethod().toString(), request.getResourceRef().toString(), request .isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
public String getBeansRefPath() { Reference ref = getRequest().getResourceRef(); String path = ref.getPath(); int i = path.indexOf("/beans/"); if(i>0) { return path.substring(0,i+"/beans/".length()); } if(!path.endsWith("/")) { path += "/"; } return path; }