javax.ws.rs.core.PathSegment Java Examples
The following examples show how to use
javax.ws.rs.core.PathSegment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EndpointMutatorTest.java From secure-data-service with Apache License 2.0 | 6 votes |
@Test public void testGetResourceVersionForSearch() { List<PathSegment> segments = getPathSegmentList("v1/search"); MutatedContainer mutated = mock(MutatedContainer.class); when(mutated.getPath()).thenReturn("/search"); assertEquals("Should match", "v1", endpointMutator.getResourceVersion(segments, mutated)); segments = getPathSegmentList("v1.0/search"); assertEquals("Should match", "v1.0", endpointMutator.getResourceVersion(segments, mutated)); segments = getPathSegmentList("v1.1/search"); assertEquals("Should match", "v1.1", endpointMutator.getResourceVersion(segments, mutated)); segments = getPathSegmentList("v1.3/search"); assertEquals("Should match", "v1.3", endpointMutator.getResourceVersion(segments, mutated)); }
Example #2
Source File: CollectionResource.java From usergrid with Apache License 2.0 | 6 votes |
private void addItemToServiceContext( UriInfo ui, PathSegment itemName ) throws Exception { // The below is duplicated because it could change in the future // and is probably not all needed but not determined yet. if ( itemName.getPath().startsWith( "{" ) ) { Query query = Query.fromJsonString( itemName.getPath() ); if ( query != null ) { ServiceParameter.addParameter( getServiceParameters(), query ); } } else { ServiceParameter.addParameter( getServiceParameters(), itemName.getPath() ); } addMatrixParams( getServiceParameters(), ui, itemName ); }
Example #3
Source File: Estimate.java From oryx with Apache License 2.0 | 6 votes |
@GET @Path("{userID}/{itemID : .+}") @Produces({MediaType.TEXT_PLAIN, "text/csv", MediaType.APPLICATION_JSON}) public List<Double> get(@PathParam("userID") String userID, @PathParam("itemID") List<PathSegment> pathSegmentsList) throws OryxServingException { ALSServingModel model = getALSServingModel(); float[] userFeatures = model.getUserVector(userID); checkExists(userFeatures != null, userID); return pathSegmentsList.stream().map(pathSegment -> { float[] itemFeatures = model.getItemVector(pathSegment.getPath()); if (itemFeatures == null) { return 0.0; } else { double value = VectorMath.dot(itemFeatures, userFeatures); Preconditions.checkState(!(Double.isInfinite(value) || Double.isNaN(value)), "Bad estimate"); return value; } }).collect(Collectors.toList()); }
Example #4
Source File: UriMutator.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Mutates the API call (not to a base entity) to a more-specific (and * generally more constrained) URI based on the user's role. * * @param segments * List of Path Segments representing request URI. * @param queryParameters * String containing query parameters. * @param user * User requesting resource. * @return MutatedContainer representing {mutated path (if necessary), * mutated parameters (if necessary)}, where path or parameters will * be null if they didn't need to be rewritten. */ private MutatedContainer mutateUriBasedOnRole(List<PathSegment> segments, String queryParameters, Entity user) throws IllegalArgumentException { MutatedContainer mutatedPathAndParameters = null; if (mutateToTeacher()) { mutatedPathAndParameters = mutateTeacherRequest(segments, queryParameters, user); } else if (mutateToStaff()) { mutatedPathAndParameters = mutateStaffRequest(segments, queryParameters, user); } else if (isStudent(user) || isParent(user)) { mutatedPathAndParameters = mutateStudentParentRequest( stringifyPathSegments(segments), queryParameters, user); } return mutatedPathAndParameters; }
Example #5
Source File: DcReadDeleteModeManager.java From io with Apache License 2.0 | 6 votes |
/** * PCSの動作モードがReadDeleteOnlyモードの場合は、参照系リクエストのみ許可する. * 許可されていない場合は例外を発生させてExceptionMapperにて処理する. * @param method リクエストメソッド * @param pathSegment パスセグメント */ public static void checkReadDeleteOnlyMode(String method, List<PathSegment> pathSegment) { // ReadDeleteOnlyモードでなければ処理を許可する if (!ReadDeleteModeLockManager.isReadDeleteOnlyMode()) { return; } // 認証処理はPOSTメソッドだが書き込みは行わないので例外として許可する if (isAuthPath(pathSegment)) { return; } // $batchはPOSTメソッドだが参照と削除のリクエストも実行可能であるため // $batch内部で書き込み系処理をエラーとする if (isBatchPath(pathSegment)) { return; } // ReadDeleteOnlyモード時に、許可メソッドであれば処理を許可する if (ACCEPT_METHODS.contains(method)) { return; } throw DcCoreException.Server.READ_DELETE_ONLY; }
Example #6
Source File: DocumentTreeResource.java From atomix with Apache License 2.0 | 6 votes |
@GET @Path("/{name}/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public void get( @PathParam("name") String name, @PathParam("path") List<PathSegment> path, @Suspended AsyncResponse response) { getPrimitive(name).thenCompose(tree -> tree.get(getDocumentPath(path))).whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(new VersionedResult(result)).build()); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
Example #7
Source File: GetResponseBuilder.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Throws a QueryParseException if the end user tried to query an endpoint that does * not support querying. * * * @param uriInfo */ protected void validatePublicResourceQuery(final UriInfo uriInfo) { List<PathSegment> uriPathSegments = uriInfo.getPathSegments(); if (uriPathSegments != null) { // if of the form "v1/foo" if (uriPathSegments.size() == 2) { String endpoint = uriPathSegments.get(1).getPath(); // if that endpoint does not allow querying if (this.resourceEndPoint.getQueryingDisallowedEndPoints().contains(endpoint)) { ApiQuery apiQuery = new ApiQuery(uriInfo); // if the user tried to execute a query/filter if (apiQuery.getCriteria().size() > 0) { throw new QueryParseException("Querying not allowed", apiQuery.toString()); } } } } }
Example #8
Source File: HttpUtils.java From cxf with Apache License 2.0 | 6 votes |
public static String fromPathSegment(PathSegment ps) { if (PathSegmentImpl.class.isAssignableFrom(ps.getClass())) { return ((PathSegmentImpl)ps).getOriginalPath(); } StringBuilder sb = new StringBuilder(); sb.append(ps.getPath()); for (Map.Entry<String, List<String>> entry : ps.getMatrixParameters().entrySet()) { for (String value : entry.getValue()) { sb.append(';').append(entry.getKey()); if (value != null) { sb.append('=').append(value); } } } return sb.toString(); }
Example #9
Source File: ContextValidator.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * white list student accessible URL. Can't do it in validateUserHasContextToRequestedEntity * because we must also block some url that only has 2 segment, i.e. * disciplineActions/disciplineIncidents * * @param request * @return if url is accessible to students principals */ public boolean isUrlBlocked(ContainerRequest request) { List<PathSegment> segs = cleanEmptySegments(request.getPathSegments()); if (isSystemCall(segs)) { // do not block system calls return false; } if (SecurityUtil.isStudent()) { return !studentAccessValidator.isAllowed(request); } else if (SecurityUtil.isParent()) { return !parentAccessValidator.isAllowed(request); } return false; }
Example #10
Source File: CarResource.java From resteasy-examples with Apache License 2.0 | 5 votes |
@GET @Path("/matrix/{make}/{model}/{year}") @Produces("text/plain") public String getFromMatrixParam(@PathParam("make") String make, @PathParam("model") PathSegment car, @MatrixParam("color") Color color, @PathParam("year") String year) { return "A " + color + " " + year + " " + make + " " + car.getPath(); }
Example #11
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモード時にMKCOLメソッドが実行された場合はDcCoreExceptionが発生すること. * @throws Exception . */ @Test(expected = DcCoreException.class) public void ReadDeleteOnlyモード時にMKCOLメソッドが実行された場合は503が返却されること() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); DcReadDeleteModeManager.checkReadDeleteOnlyMode(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MKCOL, pathSegment); }
Example #12
Source File: ResourceHelperTest.java From secure-data-service with Apache License 2.0 | 5 votes |
@Test public void testExtractVersion() { PathSegment segment1 = mock(PathSegment.class); when(segment1.getPath()).thenReturn("v1.1"); List<PathSegment> segmentList = new ArrayList<PathSegment>(); assertEquals("Should match", PathConstants.V1, resourceHelper.extractVersion(segmentList)); segmentList.add(segment1); assertEquals("", "v1.1", resourceHelper.extractVersion(segmentList)); }
Example #13
Source File: BookStore.java From cxf with Apache License 2.0 | 5 votes |
@GET @Path("/segment/list/{pathsegment:.+}/") public Book getBookBySegment(@PathParam("pathsegment") List<PathSegment> list) throws Exception { return doGetBook(list.get(0).getPath() + list.get(1).getPath() + list.get(2).getPath()); }
Example #14
Source File: ODataRootLocator.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Default root behavior which will delegate all paths to a ODataLocator. * @param pathSegments URI path segments - all segments have to be OData * @param xHttpMethod HTTP Header X-HTTP-Method for tunneling through POST * @param xHttpMethodOverride HTTP Header X-HTTP-Method-Override for tunneling through POST * @return a locator handling OData protocol * @throws ODataException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ @Path("/{pathSegments: .*}") public Object handleRequest( @Encoded @PathParam("pathSegments") final List<PathSegment> pathSegments, @HeaderParam("X-HTTP-Method") final String xHttpMethod, @HeaderParam("X-HTTP-Method-Override") final String xHttpMethodOverride) throws ODataException, ClassNotFoundException, InstantiationException, IllegalAccessException { if (xHttpMethod != null && xHttpMethodOverride != null) { /* * X-HTTP-Method-Override : implemented by CXF * X-HTTP-Method : implemented in ODataSubLocator:handlePost */ if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) { throw new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD); } } if (servletRequest.getPathInfo() == null) { return handleRedirect(); } ODataServiceFactory serviceFactory = getServiceFactory(); int pathSplit = getPathSplit(); final SubLocatorParameter param = new SubLocatorParameter(); param.setServiceFactory(serviceFactory); param.setPathSegments(pathSegments); param.setHttpHeaders(httpHeaders); param.setUriInfo(uriInfo); param.setRequest(request); param.setServletRequest(servletRequest); param.setPathSplit(pathSplit); return ODataSubLocator.create(param); }
Example #15
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモード時にDELETEメソッドが実行された場合はDcCoreExceptionが発生しないこと. * @throws Exception . */ @Test public void ReadDeleteOnlyモード時にDELETEメソッドが実行された場合はDcCoreExceptionが発生しないこと() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); try { DcReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.DELETE, pathSegment); } catch (DcCoreException e) { fail(e.getMessage()); } }
Example #16
Source File: StudioInterface.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
/** * Submits a job to the scheduler * @param sessionId a valid session id * @param multipart a form with the job file as form data * @return the <code>jobid</code> of the newly created job */ @POST @Path("{path:submit}") @Consumes(MediaType.MULTIPART_FORM_DATA) JobIdData submit(@HeaderParam("sessionid") String sessionId, @PathParam("path") PathSegment pathSegment, MultipartFormDataInput multipart) throws JobCreationRestException, NotConnectedRestException, PermissionRestException, SubmissionClosedRestException, IOException;
Example #17
Source File: CourseResourceFolderWebService.java From olat with Apache License 2.0 | 5 votes |
@GET @Path("coursefolder/{path:.*}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_HTML, MediaType.APPLICATION_OCTET_STREAM }) public Response getCourseFiles(@PathParam("courseId") final Long courseId, @PathParam("path") final List<PathSegment> path, @Context final UriInfo uriInfo, @Context final HttpServletRequest httpRequest, @Context final Request request) { return getFiles(courseId, path, FolderType.COURSE_FOLDER, uriInfo, httpRequest, request); }
Example #18
Source File: CourseResourceFolderWebService.java From olat with Apache License 2.0 | 5 votes |
@GET @Path("coursefolder/{path:.*}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_HTML, MediaType.APPLICATION_OCTET_STREAM }) public Response getCourseFiles(@PathParam("courseId") final Long courseId, @PathParam("path") final List<PathSegment> path, @Context final UriInfo uriInfo, @Context final HttpServletRequest httpRequest, @Context final Request request) { return getFiles(courseId, path, FolderType.COURSE_FOLDER, uriInfo, httpRequest, request); }
Example #19
Source File: WingsResource.java From wings with Apache License 2.0 | 5 votes |
protected boolean isPage(String lastsegment) { List<PathSegment> segments = uriInfo.getPathSegments(); if(segments.size() > 0 && lastsegment.equals(segments.get(segments.size()-1).toString())) return true; return false; }
Example #20
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモード時にHEADメソッドが実行された場合はDcCoreExceptionが発生しないこと. * @throws Exception . */ @Test public void ReadDeleteOnlyモード時にHEADメソッドが実行された場合はDcCoreExceptionが発生しないこと() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); try { DcReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.HEAD, pathSegment); } catch (DcCoreException e) { fail(e.getMessage()); } }
Example #21
Source File: CatalogWebService.java From olat with Apache License 2.0 | 5 votes |
private Long getCatalogEntryKeyFromPath(final List<PathSegment> path) { final PathSegment lastPath = path.get(path.size() - 1); Long key = null; try { key = new Long(lastPath.getPath()); } catch (final NumberFormatException e) { key = null; } return key; }
Example #22
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモード時にGETメソッドが実行された場合はDcCoreExceptionが発生しないこと. * @throws Exception . */ @Test public void ReadDeleteOnlyモード時にGETメソッドが実行された場合はDcCoreExceptionが発生しないこと() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); try { DcReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.GET, pathSegment); } catch (DcCoreException e) { fail(e.getMessage()); } }
Example #23
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモードではない状態でPUTメソッドが実行された場合はDcCoreExceptionが発生しないこと. * @throws Exception . */ @Test public void ReadDeleteOnlyモードではない状態でPUTメソッドが実行された場合はDcCoreExceptionが発生しないこと() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(false); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); try { DcReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.PUT, pathSegment); } catch (DcCoreException e) { fail(e.getMessage()); } }
Example #24
Source File: UsersResource.java From usergrid with Apache License 2.0 | 5 votes |
@Override @Path("{itemName}") public AbstractContextResource addNameParameter( @Context UriInfo ui, @PathParam("itemName") PathSegment itemName) throws Exception { if(logger.isTraceEnabled()){ logger.trace( "ServiceResource.addNameParameter" ); logger.trace( "Current segment is {}", itemName.getPath() ); } if ( itemName.getPath().startsWith( "{" ) ) { Query query = Query.fromJsonString( itemName.getPath() ); if ( query != null ) { addParameter( getServiceParameters(), query ); } addMatrixParams( getServiceParameters(), ui, itemName ); return getSubResource( ServiceResource.class ); } addParameter( getServiceParameters(), itemName.getPath() ); addMatrixParams( getServiceParameters(), ui, itemName ); String forceString = ui.getQueryParameters().getFirst("force"); Identifier id; if (forceString != null && "email".equals(forceString.toLowerCase())) { id = Identifier.fromEmail(itemName.getPath().toLowerCase()); } else if (forceString != null && "name".equals(forceString.toLowerCase())) { id = Identifier.fromName(itemName.getPath().toLowerCase()); } else { id = Identifier.from(itemName.getPath()); } if ( id == null ) { throw new IllegalArgumentException( "Not a valid user identifier: " + itemName.getPath() ); } return getSubResource( UserResource.class ).init( id ); }
Example #25
Source File: VersionFilterTest.java From secure-data-service with Apache License 2.0 | 5 votes |
@Test public void testNonRewrite() { PathSegment segment1 = mock(PathSegment.class); when(segment1.getPath()).thenReturn("v5"); PathSegment segment2 = mock(PathSegment.class); when(segment2.getPath()).thenReturn("students"); List<PathSegment> segments = Arrays.asList(segment1, segment2); when(containerRequest.getPathSegments()).thenReturn(segments); when(containerRequest.getProperties()).thenReturn(new HashMap<String, Object>()); ContainerRequest request = versionFilter.filter(containerRequest); verify(containerRequest, never()).setUris((URI) any(), (URI) any()); assertNull("Should be null", request.getProperties().get(REQUESTED_PATH)); }
Example #26
Source File: PathSegmentImplTest.java From everrest with Eclipse Public License 2.0 | 5 votes |
@Test public void parsesPathSegmentsFromString() { PathSegment pathSegment = PathSegmentImpl.fromString(pathSegmentString, decode); MultivaluedMap<String, String> matrixParameters = pathSegment.getMatrixParameters(); assertEquals(expectedPath, pathSegment.getPath()); assertEquals(expectedMatrixParameters.size() / 2, matrixParameters.size()); for (int i = 0; i < expectedMatrixParameters.size(); i += 2) { String expectedMatrixParameterName = expectedMatrixParameters.get(i); String expectedMatrixParameterValue = expectedMatrixParameters.get(i + 1); assertEquals(expectedMatrixParameterValue, matrixParameters.getFirst(expectedMatrixParameterName)); } }
Example #27
Source File: EstimateForAnonymous.java From oryx with Apache License 2.0 | 5 votes |
static List<Pair<String, Double>> parsePathSegments(List<PathSegment> pathSegments) { return pathSegments.stream().map(segment -> { String s = segment.getPath(); int offset = s.indexOf('='); return offset < 0 ? new Pair<>(s, 1.0) : new Pair<>(s.substring(0, offset), Double.parseDouble(s.substring(offset + 1))); }).collect(Collectors.toList()); }
Example #28
Source File: FileIncludesResource.java From usergrid with Apache License 2.0 | 5 votes |
@Path( RootResource.ENTITY_ID_PATH + "/errors" ) public FileErrorsResource getIncludes( @Context UriInfo ui, @PathParam( "entityId" ) PathSegment entityId ) throws Exception { final UUID fileImportId = UUID.fromString( entityId.getPath() ); return getSubResource( FileErrorsResource.class ).init( application, importId,fileImportId ); }
Example #29
Source File: CatalogWebService.java From olat with Apache License 2.0 | 5 votes |
/** * Get the owners of the local sub tree * * @response.representation.200.qname {http://www.example.com}userVO * @response.representation.200.mediaType application/xml, application/json * @response.representation.200.doc The catalog entry * @response.representation.200.example {@link org.olat.connectors.rest.user.Examples#SAMPLE_USERVOes} * @response.representation.401.doc Not authorized * @response.representation.404.doc The path could not be resolved to a valid catalog entry * @param path * The path * @param httpRquest * The HTTP request * @return The response */ @GET @Path("{path:.*}/owners") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response getOwners(@PathParam("path") final List<PathSegment> path, @Context final HttpServletRequest httpRequest) { final Long key = getCatalogEntryKeyFromPath(path); if (key == null) { return Response.serverError().status(Status.NOT_ACCEPTABLE).build(); } final CatalogEntry ce = catalogService.loadCatalogEntry(key); if (ce == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } if (!isAuthor(httpRequest) && !canAdminSubTree(ce, httpRequest)) { return Response.serverError().status(Status.UNAUTHORIZED).build(); } final SecurityGroup sg = ce.getOwnerGroup(); if (sg == null) { return Response.ok(new UserVO[0]).build(); } final List<Identity> ids = baseSecurity.getIdentitiesOfSecurityGroup(sg); int count = 0; final UserVO[] voes = new UserVO[ids.size()]; for (final Identity id : ids) { voes[count++] = UserVOFactory.get(id); } return Response.ok(voes).build(); }
Example #30
Source File: DcReadDeleteModeManagerTest.java From io with Apache License 2.0 | 5 votes |
/** * ReadDeleteOnlyモード時にPOSTメソッドが実行された場合はDcCoreExceptionが発生すること. * @throws Exception . */ @Test(expected = DcCoreException.class) public void ReadDeleteOnlyモード時にPOSTメソッドが実行された場合は503が返却されること() throws Exception { PowerMockito.spy(ReadDeleteModeLockManager.class); PowerMockito.when(ReadDeleteModeLockManager.class, "isReadDeleteOnlyMode").thenReturn(true); List<PathSegment> pathSegment = getPathSegmentList(new String[] {"cell", "box", "odata", "entity" }); DcReadDeleteModeManager.checkReadDeleteOnlyMode(HttpMethod.POST, pathSegment); }