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"))); };
/** * Construct navigational URI for given parameters. * * @param pos desired position in file * @param lines desired signed line count * @param reverse if line ordering should be displayed in reverse * @return String URI appropriate to navigate to desired view */ protected String getControlUri(long pos, int lines, boolean reverse) { Form query = new Form(); query.add("format","paged"); if(pos!=0) { query.add("pos", Long.toString(pos)); } if(lines!=128) { if(Math.abs(lines)<1) { lines = 1; } query.add("lines",Integer.toString(lines)); } if(reverse) { query.add("reverse","y"); } Reference viewRef = dirResource.getRequest().getOriginalRef().clone(); viewRef.setQuery(query.getQueryString()); return viewRef.toString(); } }
protected boolean isDescribe( Request request ) { // check do we need describe return request.getResourceRef().getQueryAsForm().getFirst( IS_DESCRIBE_PARAMETER ) != null; }
@Override protected int beforeHandle(Request request, Response response) { Cookie cookie = request.getCookies().getFirst("Credentials"); if (cookie != null) { // Extract the challenge response from the cookie String[] credentials = cookie.getValue().split("="); if (credentials.length == 2) { String identifier = credentials[0]; String secret = credentials[1]; request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); } } else if (Method.POST.equals(request.getMethod()) && request.getResourceRef().getQueryAsForm().getFirst("login") != null) { // Intercepting a login form Form credentials = new Form(request.getEntity()); String identifier = credentials.getFirstValue("identifier"); String secret = credentials.getFirstValue("secret"); request.setChallengeResponse(new ChallengeResponse( ChallengeScheme.HTTP_COOKIE, identifier, secret)); // Continue call processing to return the target representation if // authentication is successful or a new login page request.setMethod(Method.GET); } return super.beforeHandle(request, response); }
public Page readFrom(Class<Page> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { ObjectFactory objectFactory = new ObjectFactory(); Page page = objectFactory.createPage(); HttpServletRequest httpServletRequest = (HttpServletRequest) Context.getCurrent().getAttributes().get(Constants.HTTP_REQUEST); Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM); Form form = new Form(representation); /* * If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to * read data using getParameter() */ if (form.getNames().isEmpty()) { page.setTitle(httpServletRequest.getParameter(TITLE_FIELD_NAME)); page.setParent(httpServletRequest.getParameter(PARENT_FIELD_NAME)); page.setContent(httpServletRequest.getParameter(CONTENT_FIELD_NAME)); } else { page.setTitle(form.getFirstValue(TITLE_FIELD_NAME)); page.setParent(form.getFirstValue(PARENT_FIELD_NAME)); page.setContent(form.getFirstValue(CONTENT_FIELD_NAME)); } return page; }
Form params = request.getResourceRef().getQueryAsForm(); if (params.getFirstValue("from") != null) { from = Integer.valueOf(params.getFirstValue("from")); if (params.getFirstValue("count") != null) { count = Integer.valueOf(params.getFirstValue("count")); Map<String, String> par = params.getValuesMap(); feed.setLink(request.getResourceRef().toString());
String username = this.getRequest().getResourceRef().getQueryAsForm().getFirstValue("username", true); final Form data = new Form(this.getRequest().getEntity()); submittedRoles.addAll(Arrays.asList(this.getRequest().getResourceRef().getQueryAsForm() .getValuesArray("activeRoles", true))); for(final String nextEntry : data.getValuesMap().keySet()) submittedRoles.addAll(Arrays.asList(data.getValuesArray("activeRoles", true))); username = data.getFirstValue("username", true);
protected HashMap<String,String> convertFormStrings(Form params) { HashMap<String,String> converted = new HashMap<String,String>(); for (String key : params.getNames()) { Matcher matcher = xmlnsRE.matcher(key); if (matcher.matches()) { // nop } else { converted.put(key, params.getFirstValue(key)); } } return converted; }
String query = request.getResourceRef().getQuery(); Request httpRequest = (Request) request; if (httpRequest.getHostRef() != null) { String host = httpRequest.getHostRef().getHostDomain(); int port = httpRequest.getHostRef().getHostPort(); String protocol = "http"; if (httpRequest.getHostRef().getSchemeProtocol() != null) { Form form = new Form(query); if (form != null) { for (Map.Entry<String, String> entry : form.getValuesMap() .entrySet()) {
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); }
private String getAccessTokenFromQuery(Request request) { // Try to find token in URI query Form params = request.getOriginalRef().getQueryAsForm(); String token = params.getFirstValue(OAuthServerResource.ACCESS_TOKEN); if (token != null && !token.isEmpty()) { logger.fine("Found Bearer Token in URI query."); return token; } return null; }
@Override public Token requestToken(OAuthParameters parameters) throws OAuthException { // Graph API MUST use body method. setupBodyClientCredentials(parameters); Representation input = parameters.toRepresentation(); // Unlike RFC6749, Facebook token parameters are included in www-form. Form result = new Form(post(input)); if (result.getFirstValue(ERROR) != null) { throw OAuthException.toOAuthException(result); } return FacebookTokenResponse.parseResponse(result); }
/** * Returns the Representation of an item. * * @param item * the item. * * @return The Representation of the item. */ public static Representation getRepresentation(Item item) { // Gathering informations into a Web form. Form form = new Form(); form.add("name", item.getName()); form.add("description", item.getDescription()); return form.getWebRepresentation(); }
/** * @param parameters * @return a form with the given parameters. Will never return null. */ public static Form toRestletSeries(Map<String, String> parameters) { final Form form = new Form(); if (parameters == null) { return form; } for (final Map.Entry<String, String> parameter : parameters.entrySet()) { form.add(parameter.getKey(), parameter.getValue()); } return form; }
@Override public Object post(final Context context, final Request request, final Response response, final Object payload) throws ResourceException { final String taskType = request.getAttributes().get("taskType").toString(); if (taskType != null) { final NexusTask<?> taskInstance = nexusScheduler.createTaskInstance(taskType); final Map<String, String> valuesMap = request.getResourceRef().getQueryAsForm().getValuesMap(); if (valuesMap != null && !valuesMap.isEmpty()) { for (Map.Entry<String, String> entry : valuesMap.entrySet()) { taskInstance.addParameter(entry.getKey(), entry.getValue()); } } final ScheduledTask<?> scheduledTask = nexusScheduler.submit(taskType, taskInstance); try { scheduledTask.get(); } catch (Exception e) { throw new ResourceException(e); } } return null; }
Form form = new Form(representation); if (form.getNames().isEmpty()) { String text = httpServletRequest.getParameter(TAGS_FIELD_NAME); if (text != null) { String text = form.getFirstValue(TAGS_FIELD_NAME); if (text != null) { String[] tagNames = text.split(" |,|\\|"); for (String tagName : form.getValuesArray(TAG_FIELD_NAME)) { Tag tag = objectFactory.createTag(); tag.setName(tagName);
if (getTarget().getOriginalRef().hasQuery()) { params.putAll( getTarget().getOriginalRef().getQueryAsForm(true).getValuesMap() ); if (MediaType.APPLICATION_WWW_FORM.equals(getTarget().getEntity().getMediaType(), true)) { params.putAll( new Form(getTarget().getEntity(), true).getValuesMap() ); } else if (MediaType.MULTIPART_FORM_DATA.equals(getTarget().getEntity().getMediaType(), true)) {
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 ); }