baseRef.setPath(baseRef.getPath() + "/");
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); }
/** * Sets the segments of a hierarchical path.<br> * A new absolute path will replace any existing one. * * @param segments * The segments of the hierarchical path. */ public void setSegments(List<String> segments) { final StringBuilder sb = new StringBuilder(); for (final String segment : segments) { sb.append('/').append(segment); } setPath(sb.toString()); }
/** * Sets the segments of a hierarchical path.<br> * A new absolute path will replace any existing one. * * @param segments * The segments of the hierarchical path. */ public void setSegments(List<String> segments) { final StringBuilder sb = new StringBuilder(); for (final String segment : segments) { sb.append('/').append(segment); } setPath(sb.toString()); }
/** * Sets the segments of a hierarchical path.<br> * A new absolute path will replace any existing one. * * @param segments * The segments of the hierarchical path. */ public void setSegments(List<String> segments) { final StringBuilder sb = new StringBuilder(); for (final String segment : segments) { sb.append('/').append(segment); } setPath(sb.toString()); }
/** * Sets the last segment of the path. If no path is available, then it * creates one and adds a slash in front of the given last segmetn. <br> * Note that no URI decoding is done by this method. * * @param lastSegment * The last segment of a hierarchical path. */ public void setLastSegment(String lastSegment) { final String path = getPath(); final int lastSlashIndex = path.lastIndexOf('/'); if (lastSlashIndex != -1) { setPath(path.substring(0, lastSlashIndex + 1) + lastSegment); } else { setPath('/' + lastSegment); } }
/** * Sets the last segment of the path. If no path is available, then it * creates one and adds a slash in front of the given last segmetn. <br> * Note that no URI decoding is done by this method. * * @param lastSegment * The last segment of a hierarchical path. */ public void setLastSegment(String lastSegment) { String path = getPath(); int lastSlashIndex = -1; if (path != null) { lastSlashIndex = path.lastIndexOf('/'); } if (lastSlashIndex != -1) { setPath(path.substring(0, lastSlashIndex + 1) + lastSegment); } else { setPath('/' + lastSegment); } }
/** * Sets the last segment of the path. If no path is available, then it * creates one and adds a slash in front of the given last segmetn. <br> * Note that no URI decoding is done by this method. * * @param lastSegment * The last segment of a hierarchical path. */ public void setLastSegment(String lastSegment) { String path = getPath(); if (path != null) { int lastSlashIndex = path.lastIndexOf('/'); if (lastSlashIndex != -1) { setPath(path.substring(0, lastSlashIndex + 1) + lastSegment); return; } } setPath('/' + lastSegment); }
/** * Adds a segment at the end of the path. If the current path doesn't end * with a slash character, one is inserted before the new segment value. The * value is automatically encoded if necessary. * * @param value * The segment value to add. * @return The updated reference. */ public Reference addSegment(String value) { final String path = getPath(); if (value != null) { if (path == null) { setPath("/" + value); } else if (path.endsWith("/")) { setPath(path + encode(value)); } else { setPath(path + "/" + encode(value)); } } return this; }
/** * Adds a segment at the end of the path. If the current path doesn't end * with a slash character, one is inserted before the new segment value. The * value is automatically encoded if necessary. * * @param value * The segment value to add. * @return The updated reference. */ public Reference addSegment(String value) { final String path = getPath(); if (value != null) { if (path == null) { setPath("/" + value); } else { if (path.endsWith("/")) { setPath(path + encode(value)); } else { setPath(path + "/" + encode(value)); } } } return this; }
private void setRequestPathToAnnotationPath(Method javaMethod, Request request) { Path methodPathAnnotation = javaMethod.getAnnotation(Path.class); if (methodPathAnnotation != null) { String methodPath = methodPathAnnotation.value(); if (!StringUtils.isNullOrEmpty(methodPath)) { String fullUriFromPath = request.getResourceRef().getPath(); if (fullUriFromPath.endsWith("/")) { if (methodPath.startsWith("/")) { fullUriFromPath += methodPath.substring(1); } else { fullUriFromPath += methodPath; } } else { if (methodPath.startsWith("/")) { fullUriFromPath += methodPath; } else { fullUriFromPath += "/" + methodPath; } } request.getResourceRef().setPath(fullUriFromPath); } } }
public synchronized ContextResourceClient newClient( String relativePath ) { if( relativePath.startsWith( "http://" ) ) { return contextResourceFactory.newClient( new Reference( relativePath ) ); } Reference reference = this.reference.clone(); if( relativePath.startsWith( "/" ) ) { reference.setPath( relativePath ); } else { reference.setPath( reference.getPath() + relativePath ); reference = reference.normalize(); } return contextResourceFactory.newClient( reference ); }
private Reference updateBaseRefPath( Reference reference ) { if ( reference.getBaseRef().getPath() == null ) { reference.getBaseRef().setPath( "/" ); } else if ( !reference.getBaseRef().getPath().endsWith( "/" ) ) { reference.getBaseRef().setPath( reference.getBaseRef().getPath() + "/" ); } return reference; }
@Override protected int beforeHandle( Request request, Response response ) { String extensions = request.getResourceRef().getExtensions(); if ( extensions != null ) { int idx = extensions.lastIndexOf( '.' ); if ( idx != -1 ) { extensions = extensions.substring( idx + 1 ); } MetadataService metadataService = getApplication().getMetadataService(); Metadata metadata = metadataService.getMetadata( extensions ); if ( metadata instanceof MediaType ) { request.getClientInfo().setAcceptedMediaTypes( Collections.singletonList( new Preference<MediaType>( ( MediaType ) metadata ) ) ); String path = request.getResourceRef().getPath(); path = path.substring( 0, path.length() - extensions.length() - 1 ); request.getResourceRef().setPath( path ); } } return Filter.CONTINUE; }
protected Reference createRootReference(Request request, String relPart) { Reference ref = new Reference(getContextRoot(request), relPart); if (!ref.getBaseRef().getPath().endsWith("/")) { ref.getBaseRef().setPath(ref.getBaseRef().getPath() + "/"); } return ref.getTargetRef(); }
@Override public Reference getContextRoot( Request request ) { Reference result = null; if ( globalRestApiSettings.isEnabled() && globalRestApiSettings.isForceBaseUrl() && StringUtils.isNotEmpty( globalRestApiSettings.getBaseUrl() ) ) { result = new Reference( globalRestApiSettings.getBaseUrl() ); } else { result = request.getRootRef(); } // fix for when restlet is at webapp root if ( StringUtils.isEmpty( result.getPath() ) ) { result.setPath( "/" ); } return result; }
protected Reference createRootReference( Request request, String relPart ) { Reference ref = new Reference( getContextRoot( request ), relPart ); if ( !ref.getBaseRef().getPath().endsWith( "/" ) ) { ref.getBaseRef().setPath( ref.getBaseRef().getPath() + "/" ); } return ref.getTargetRef(); }
@Override public Reference getContextRoot(Request request) { Reference result = null; if (globalRestApiSettings.isEnabled() && globalRestApiSettings.isForceBaseUrl() && StringUtils.isNotEmpty(globalRestApiSettings.getBaseUrl())) { result = new Reference(globalRestApiSettings.getBaseUrl()); } else { // TODO: NEXUS-6045 hack, Restlet app root is now "/service/local", so going up 2 levels! result = request.getRootRef().getParentRef().getParentRef(); } // fix for when restlet is at webapp root if (StringUtils.isEmpty(result.getPath())) { result.setPath("/"); } return result; }
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); }