@GET public Response getIndex(@Context ContainerRequest request, @Context HttpHeaders headers) { final URI originalLocation = request.getRequestUri(); if (originalLocation.getPath().endsWith("/")) { return get(request, headers, originalLocation.getPath()); } final URI redirect = UriBuilder.fromPath(originalLocation.getPath() + "/").build(); return Response.temporaryRedirect(redirect).build(); }
@GET public Response redirectToWebapp() { return Response.seeOther(UriBuilder.fromPath("maps/").build()).build(); }
private String _constructResourceURL(String uriPrefix) { UriBuilder uriBuilder = UriBuilder.fromPath(uriPrefix); URI resourceURI = uriBuilder.path( uriPrefix.contains("/p/") ? "" : "p" ).path( "{resource}" ).build( getValue() ); return resourceURI.toString(); }
private static UriBuilder applyLinkStyle(String template, InjectLink.Style style, UriInfo uriInfo) { UriBuilder ub = null; switch (style) { case ABSOLUTE: ub = uriInfo.getBaseUriBuilder().path(template); break; case ABSOLUTE_PATH: String basePath = uriInfo.getBaseUri().getPath(); ub = UriBuilder.fromPath(basePath).path(template); break; case RELATIVE_PATH: ub = UriBuilder.fromPath(template); break; } return ub; }
private UriBuilder getURIBuilder(String path, Object[] queryParams) { if (path == null) { path = ""; } UriBuilder builder = UriBuilder.fromPath(path); if (queryParams != null) { for (int i = 0; i < queryParams.length; i += 2) { String param = queryParams[i].toString(); Object value = queryParams[i + 1]; if (value != null) { if (value instanceof Collection) { Object[] values = ((Collection<?>) value).toArray(); builder.queryParam(param, values); } else { builder.queryParam(param, value); } } } } return builder; } }
public String getWebSiteURL() { UriBuilder uriBuilder = UriBuilder.fromPath(getHost()); URI webSiteURI = uriBuilder.path( "p" ).path( "commerce-web-site" ).path( "{webSiteId}" ).build( getValue() ); return webSiteURI.toString(); }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdRevisions( com.sun.jersey.api.client.Client client, URI uri ) { _client = client; StringBuilder template = new StringBuilder( BASE_URI.toString() ); if ( template.charAt( ( template.length() - 1 ) ) != '/' ) { template.append( "/pur-repository-plugin/api/revision/{pathId : .+}/revisions" ); } else { template.append( "pur-repository-plugin/api/revision/{pathId : .+}/revisions" ); } _uriBuilder = UriBuilder.fromPath( template.toString() ); _templateAndMatrixParameterValues = new HashMap<String, Object>(); com.sun.jersey.api.uri.UriTemplate uriTemplate = new com.sun.jersey.api.uri.UriTemplate( template.toString() ); HashMap<String, String> parameters = new HashMap<String, String>(); uriTemplate.match( uri.toString(), parameters ); _templateAndMatrixParameterValues.putAll( parameters ); }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdVersioningConfiguration( com.sun.jersey.api.client.Client client, URI uri ) { _client = client; StringBuilder template = new StringBuilder( BASE_URI.toString() ); if ( template.charAt( ( template.length() - 1 ) ) != '/' ) { template.append( "/pur-repository-plugin/api/revision/{pathId}/versioningConfiguration" ); } else { template.append( "pur-repository-plugin/api/revision/{pathId}/versioningConfiguration" ); } _uriBuilder = UriBuilder.fromPath( template.toString() ); _templateAndMatrixParameterValues = new HashMap<String, Object>(); com.sun.jersey.api.uri.UriTemplate uriTemplate = new com.sun.jersey.api.uri.UriTemplate( template.toString() ); HashMap<String, String> parameters = new HashMap<String, String>(); uriTemplate.match( uri.toString(), parameters ); _templateAndMatrixParameterValues.putAll( parameters ); }
/** * Create new instance using existing Client instance, and the URI from which the parameters will be extracted * */ public PathIdPurge( com.sun.jersey.api.client.Client client, URI uri ) { _client = client; StringBuilder template = new StringBuilder( BASE_URI.toString() ); if ( template.charAt( ( template.length() - 1 ) ) != '/' ) { template.append( "/pur-repository-plugin/api/purge/{pathId : .+}/purge" ); } else { template.append( "pur-repository-plugin/api/purge/{pathId : .+}/purge" ); } _uriBuilder = UriBuilder.fromPath( template.toString() ); _templateAndMatrixParameterValues = new HashMap<String, Object>(); com.sun.jersey.api.uri.UriTemplate uriTemplate = new com.sun.jersey.api.uri.UriTemplate( template.toString() ); HashMap<String, String> parameters = new HashMap<String, String>(); uriTemplate.match( uri.toString(), parameters ); _templateAndMatrixParameterValues.putAll( parameters ); }
public void doDelete(IndexedRecord indexedRecord) throws IOException { String resourceId = getIndexedRecordId(indexedRecord); String resourceURL = _tLiferayOutputProperties.resource.resourceProperty. getSingleResourceOperationURL(); UriBuilder uriBuilder = UriBuilder.fromPath(resourceURL); URI singleResourceUri = uriBuilder.path( "/{resourceId}" ).build( resourceId ); try { _liferaySink.doApioDeleteRequest( _runtimeContainer, singleResourceUri.toASCIIString()); } catch (IOException ioe) { if (_log.isDebugEnabled()) { _log.debug("Unable to delete the resource", ioe); } throw ioe; } }
/** * Creates a new instance with the given parameters * * @param id the node id * @return Response (201) if the instance was created */ @POST public Response createInstance( @QueryParam("id") int id, @QueryParam("instanceID") String instanceID, @QueryParam("hostname") String hostname, @QueryParam("ip") String ip, @QueryParam("rack") String rack, @QueryParam("token") String token) { log.info( "Creating instance [id={}, instanceId={}, hostname={}, ip={}, rack={}, token={}", id, instanceID, hostname, ip, rack, token); PriamInstance instance = factory.create( config.getAppName(), id, instanceID, hostname, ip, rack, null, token); URI uri = UriBuilder.fromPath("/{id}").build(instance.getId()); return Response.created(uri).build(); }
public void doUpdate(IndexedRecord indexedRecord) throws IOException { ObjectNode objectNode = _createApioExpectedForm(indexedRecord, true); String resourceId = getIndexedRecordId(indexedRecord); String resourceURL = _tLiferayOutputProperties.resource.resourceProperty. getSingleResourceOperationURL(); UriBuilder uriBuilder = UriBuilder.fromPath(resourceURL); URI singleResourceUri = uriBuilder.path( "/{resourceId}" ).build( resourceId ); try { _liferaySink.doApioPutRequest( _runtimeContainer, singleResourceUri.toASCIIString(), objectNode); } catch (IOException ioe) { if (_log.isDebugEnabled()) { _log.debug("Unable to update the resource: ", ioe); } throw ioe; } }
public Result makeRequest(RemoteInstanceRequestClient client, String methodName, Object... values) { String remoteResponse; String errorMessage; { try { URI remoteUri = UriBuilder .fromPath(getPath()) .scheme(exhibitor.getRestScheme()) .host(hostname) .port(exhibitor.getRestPort()) .path(ClusterResource.class, methodName) .build(values); remoteResponse = client.getWebResource(remoteUri, MediaType.APPLICATION_JSON_TYPE, String.class); errorMessage = ""; } catch ( Exception e ) { remoteResponse = "{}"; errorMessage = e.getMessage(); if ( errorMessage == null ) { errorMessage = "Unknown"; } } } return new Result(remoteResponse, errorMessage); }
@GET @Path("/") public Response getIndex(@Context UriInfo info) { return Response.status(Status.MOVED_PERMANENTLY).location(UriBuilder.fromPath(singularityUriBase).path(UiResource.UI_RESOURCE_LOCATION).build()).build(); } }
public static URI relativize(URI from, URI to) { if (!compare(from.getScheme(), to.getScheme())) return to; if (!compare(from.getHost(), to.getHost())) return to; if (from.getPort() != to.getPort()) return to; if (from.getPath() == null && to.getPath() == null) return URI.create(""); else if (from.getPath() == null) return URI.create(to.getPath()); else if (to.getPath() == null) return to; String fromPath = from.getPath(); if (fromPath.startsWith("/")) fromPath = fromPath.substring(1); String[] fsplit = fromPath.split("/"); String toPath = to.getPath(); if (toPath.startsWith("/")) toPath = toPath.substring(1); String[] tsplit = toPath.split("/"); int f = 0; for (;f < fsplit.length && f < tsplit.length; f++) { if (!fsplit[f].equals(tsplit[f])) break; } UriBuilder builder = UriBuilder.fromPath(""); for (int i = f; i < fsplit.length; i++) builder.path(".."); for (int i = f; i < tsplit.length; i++) builder.path(tsplit[i]); return builder.build(); }
public static HalTaskList fromTaskList(List<Task> tasks, long count) { HalTaskList taskList = new HalTaskList(); // embed tasks List<HalResource<?>> embeddedTasks = new ArrayList<HalResource<?>>(); for (Task task : tasks) { embeddedTasks.add(HalTask.fromTask(task)); } taskList.addEmbedded("task", embeddedTasks); // links taskList.addLink("self", fromPath(TaskRestService.PATH).build()); taskList.count = count; return taskList; }
public static HalTaskList fromTaskList(List<Task> tasks, long count) { HalTaskList taskList = new HalTaskList(); // embed tasks List<HalResource<?>> embeddedTasks = new ArrayList<HalResource<?>>(); for (Task task : tasks) { embeddedTasks.add(HalTask.fromTask(task)); } taskList.addEmbedded("task", embeddedTasks); // links taskList.addLink("self", fromPath(TaskRestService.PATH).build()); taskList.count = count; return taskList; }