protected static URI getRedirectUri(final UriInfo m_uriInfo, final Object... pathComponents) { if (pathComponents != null && pathComponents.length == 0) { final URI requestUri = m_uriInfo.getRequestUri(); try { return new URI( requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getHost(), requestUri.getPort(), requestUri.getPath().replaceAll("/$", ""), null, null); } catch (final URISyntaxException e) { return requestUri; } } else { UriBuilder builder = m_uriInfo.getRequestUriBuilder(); for (final Object component : pathComponents) { if (component != null) { builder = builder.path(component.toString()); } } return builder.build(); } }
/** * Creates an entry in the group. In a case the group does not exist already it will be * automatically created. * * @param entryStream the input stream corresponding to the content of the registry entry * @param groupName the relative path to the group * @request {code} "entryStream" : the input stream corresponding to the content of the registry * entry {code} Example : {code:xml} <registry * xlinks:href="http://localhost:8080/portal/rest/registry/"> <GroovyScript2RestLoader * xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/GroovyScript2RestLoader"/> * <Audit xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/Audit"/> * </registry> {code} @LevelAPI Experimental */ @POST @Path("/{groupName:.+}") @Consumes(MediaType.APPLICATION_XML) public Response createEntry( InputStream entryStream, @PathParam("groupName") String groupName, @Context UriInfo uriInfo) { SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null); try { RegistryEntry entry = RegistryEntry.parse(entryStream); regService.createEntry(sessionProvider, normalizePath(groupName), entry); URI location = uriInfo.getRequestUriBuilder().path(entry.getName()).build(); return Response.created(location).build(); } catch (IllegalArgumentException e) { LOG.error("Create registry entry failed", e); throw new WebApplicationException(e); } catch (IOException e) { LOG.error("Create registry entry failed", e); throw new WebApplicationException(e); } catch (SAXException e) { LOG.error("Create registry entry failed", e); throw new WebApplicationException(e); } catch (ParserConfigurationException e) { LOG.error("Create registry entry failed", e); throw new WebApplicationException(e); } catch (RepositoryException e) { LOG.error("Create registry entry failed", e); throw new WebApplicationException(e); } }
@POST public Response addMessage(String msg) throws URISyntaxException { Message m = singleton.addMessage(msg); URI msgURI = ui.getRequestUriBuilder().path(Integer.toString(m.getUniqueId())).build(); return Response.created(msgURI).build(); }
@POST @LoggedIn @Transactional @ValidatePayload @Produces("application/json") @Consumes("application/json") public Response insert(Bookmark body, @Context UriInfo uriInfo) throws Exception { checkId(body); String id = bc.insert(body).getId().toString(); URI location = uriInfo.getRequestUriBuilder().path(id).build(); return Response.created(location).entity(id).build(); }
/** * Creates a new session for the given user with the given password. * * @throws ApiException If database error occurs, password is incorrect, or some other known error * occurs. * @param username The username of the person logging in. This param is part of the URL but is * ignored. Actual username comes in via Json. * @param jsonBody The Json request. * @return 201 CREATED upon completion. */ @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response createSession(@PathParam("username") String username, String jsonBody) throws ApiException { CreateUserSessionRequest request = new CreateUserSessionRequest(); request.deserializeFrom(jsonBody); SQLConnection sql = SQLConnection.connectDefault(); UserSession session = null; try { session = UserSession.start(sql, request.user, request.pass); } finally { sql.close(); } URI newUri = uriInfo.getRequestUriBuilder().path(session.getSessionId().toString()).build(); UserSessionResponse response = session.toResponse(ApiStatus.CREATED); return Response.created(newUri).entity(response.serialize()).build(); }