Java Code Examples for javax.ws.rs.core.UriBuilder#path()
The following examples show how to use
javax.ws.rs.core.UriBuilder#path() .
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: RestUtil.java From cloud-odata-java with Apache License 2.0 | 6 votes |
private static URI buildBaseUri(final HttpServletRequest request, final javax.ws.rs.core.UriInfo uriInfo, final List<PathSegment> precedingPathSegments) throws ODataException { try { UriBuilder uriBuilder = uriInfo.getBaseUriBuilder(); for (final PathSegment ps : precedingPathSegments) { uriBuilder = uriBuilder.path(ps.getPath()); for (final String key : ps.getMatrixParameters().keySet()) { final Object[] v = ps.getMatrixParameters().get(key).toArray(); uriBuilder = uriBuilder.matrixParam(key, v); } } /* * workaround because of host name is cached by uriInfo */ uriBuilder.host(request.getServerName()); String uriString = uriBuilder.build().toString(); if (!uriString.endsWith("/")) { uriString = uriString + "/"; } return new URI(uriString); } catch (final URISyntaxException e) { throw new ODataException(e); } }
Example 2
Source File: UriTemplateParser.java From krazo with Apache License 2.0 | 5 votes |
/** * <p>Parses given method and constructs a {@link UriTemplate} containing * all the information found in the annotations {@link javax.ws.rs.Path}, * {@link javax.ws.rs.QueryParam} and {@link javax.ws.rs.MatrixParam}.</p> */ UriTemplate parseMethod(Method method, String basePath) { UriBuilder uriBuilder = UriBuilder.fromPath(basePath); Path controllerPath = AnnotationUtils.getAnnotation(method.getDeclaringClass(), Path.class); if (controllerPath != null) { uriBuilder.path(controllerPath.value()); } Path methodPath = AnnotationUtils.getAnnotation(method, Path.class); if (methodPath != null) { uriBuilder.path(methodPath.value()); } UriTemplate.Builder uriTemplateBuilder = UriTemplate.fromTemplate(uriBuilder.toTemplate()); // Populate a List with all properties of given target and all parameters of given method // except for BeanParams where we need all properties of annotated type. List<AnnotatedElement> annotatedElements = BeanUtils.getFieldsAndAccessors(method.getDeclaringClass()); Arrays.asList(method.getParameters()).forEach(param -> { if (param.isAnnotationPresent(BeanParam.class)) { annotatedElements.addAll(BeanUtils.getFieldsAndAccessors(param.getType())); } else { annotatedElements.add(param); } }); annotatedElements.forEach(accessibleObject -> { if (accessibleObject.isAnnotationPresent(QueryParam.class)) { uriTemplateBuilder.queryParam(accessibleObject.getAnnotation(QueryParam.class).value()); } if (accessibleObject.isAnnotationPresent(MatrixParam.class)) { uriTemplateBuilder.matrixParam(accessibleObject.getAnnotation(MatrixParam.class).value()); } }); return uriTemplateBuilder.build(); }
Example 3
Source File: Skolemizer.java From Processor with Apache License 2.0 | 5 votes |
public URI build(Resource resource, OntClass typeClass) { if (resource == null) throw new IllegalArgumentException("Resource cannot be null"); if (typeClass == null) throw new IllegalArgumentException("OntClass cannot be null"); // skolemization template builds with absolute path builder (e.g. "{slug}") String path = getStringValue(typeClass, LDT.path); if (path == null) throw new IllegalStateException("Cannot skolemize resource of class " + typeClass + " which does not have ldt:path annotation"); final UriBuilder builder; // treat paths starting with / as absolute, others as relative (to the current absolute path) // JAX-RS URI templates do not have this distinction (leading slash is irrelevant) if (path.startsWith("/")) builder = getBaseUriBuilder().clone(); else { Resource parent = getParent(typeClass); if (parent != null) builder = UriBuilder.fromUri(parent.getURI()); else builder = getAbsolutePathBuilder().clone(); } Map<String, String> nameValueMap = getNameValueMap(resource, new UriTemplateParser(path)); builder.path(path); // add fragment identifier String fragment = getStringValue(typeClass, LDT.fragment); return builder.fragment(fragment).buildFromMap(nameValueMap); // TO-DO: wrap into SkolemizationException }
Example 4
Source File: QueueResource.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected String createSenderWithIdLink(UriInfo info) { UriBuilder builder = info.getRequestUriBuilder(); builder.path("create"); String uri = builder.build().toString(); uri += "/{id}"; return uri; }
Example 5
Source File: CustomerResource.java From resteasy-examples with Apache License 2.0 | 5 votes |
@POST @Consumes("application/xml") public Response createCustomer(Customer customer, @Context UriInfo uriInfo) { customer.setId(idCounter.incrementAndGet()); customerDB.put(customer.getId(), customer); System.out.println("Created customer " + customer.getId()); UriBuilder builder = uriInfo.getAbsolutePathBuilder(); builder.path(Integer.toString(customer.getId())); return Response.created(builder.build()).build(); }
Example 6
Source File: ClaimServiceImpl.java From cxf-fediz with Apache License 2.0 | 5 votes |
@Override public Response addClaim(UriInfo ui, Claim claim) { LOG.info("add Claim config"); Claim createdClaim = claimDAO.addClaim(claim); UriBuilder uriBuilder = UriBuilder.fromUri(ui.getRequestUri()); uriBuilder.path("{index}"); URI location = uriBuilder.build(createdClaim.getClaimType().toString()); return Response.created(location).entity(claim).build(); }
Example 7
Source File: ConsulAdvertiser.java From dropwizard-consul with Apache License 2.0 | 5 votes |
/** * Return the health check URL for the service * * @param applicationScheme Scheme the server is listening on * @return health check URL */ protected String getHealthCheckUrl(String applicationScheme) { final UriBuilder builder = UriBuilder.fromPath(environment.getAdminContext().getContextPath()); builder.path("healthcheck"); builder.scheme(applicationScheme); if (serviceAddress.get() == null) { builder.host("127.0.0.1"); } else { builder.host(serviceAddress.get()); } builder.port(serviceAdminPort.get()); return builder.build().toString(); }
Example 8
Source File: UriUtil.java From container with Apache License 2.0 | 5 votes |
public static URI encode(final URI uri) { final List<PathSegment> pathSegments = UriComponent.decodePath(uri, false); final UriBuilder uriBuilder = RuntimeDelegate.getInstance().createUriBuilder(); // Build base URL uriBuilder.scheme(uri.getScheme()).host(uri.getHost()).port(uri.getPort()); // Iterate over path segments and encode it if necessary for (final PathSegment ps : pathSegments) { uriBuilder.path(UriComponent.encode(ps.toString(), UriComponent.Type.PATH_SEGMENT)); } logger.debug("URL before encoding: {}", uri.toString()); URI result = uriBuilder.build(); logger.debug("URL after encoding: {}", result.toString()); return result; }
Example 9
Source File: TrustedIdpServiceImpl.java From cxf-fediz with Apache License 2.0 | 5 votes |
@Override public Response addTrustedIDP(UriInfo ui, TrustedIdp trustedIDP) { LOG.info("add Trusted IDP config"); TrustedIdp createdTrustedIdp = trustedIdpDAO.addTrustedIDP(trustedIDP); UriBuilder uriBuilder = UriBuilder.fromUri(ui.getRequestUri()); uriBuilder.path("{index}"); URI location = uriBuilder.build(createdTrustedIdp.getRealm()); return Response.created(location).entity(trustedIDP).build(); }
Example 10
Source File: TopicResource.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected String createSenderWithIdLink(UriInfo info) { UriBuilder builder = info.getRequestUriBuilder(); builder.path("create"); String uri = builder.build().toString(); uri += "/{id}"; return uri; }
Example 11
Source File: ResponseBuilder.java From library with Apache License 2.0 | 5 votes |
/** * Create a new http-200 response * * @return the http-200 (ok) response */ public Response ok() { final UriBuilder builder = this.location.getAbsolutePathBuilder(); if (this.entity != null) { builder.path(this.entity); } return Response.ok(builder.build()).build(); }
Example 12
Source File: Router.java From redpipe with Apache License 2.0 | 5 votes |
private static URI findURI(MethodFinder method, Object... params) { Method m = method.method(); UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class); UriBuilder builder = uriInfo.getBaseUriBuilder().path(m.getDeclaringClass()); if(m.isAnnotationPresent(Path.class)) builder.path(m); return builder.build(params); }
Example 13
Source File: MetricsEndpoint.java From javametrics with Apache License 2.0 | 5 votes |
private URI getCollectionIDFromURIInfo(UriInfo uriInfo, int contextId) { // remove parameters from url String urlPath = uriInfo.getPath(); UriBuilder builder = UriBuilder.fromPath(urlPath.substring(0,urlPath.indexOf("/"))); builder.path(Integer.toString(contextId)); return builder.build(); }
Example 14
Source File: ResourceUtil.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Returns a URI based on the supplied URI with the paths appended to the base URI. * * @param uriInfo * URI of current actions * @param paths * Paths that need to be appended * @return */ public static URI getURI(UriInfo uriInfo, String... paths) { UriBuilder builder = uriInfo.getBaseUriBuilder(); for (String path : paths) { if (path != null) { builder.path(path); } } return builder.build(); }
Example 15
Source File: ConsumersResource.java From activemq-artemis with Apache License 2.0 | 5 votes |
@POST public Response createSubscription(@FormParam("autoAck") @DefaultValue("true") boolean autoAck, @FormParam("selector") String selector, @Context UriInfo uriInfo) { ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\""); try { QueueConsumer consumer = null; int attributes = 0; if (selector != null) { attributes = attributes | SELECTOR_SET; } if (autoAck) { consumer = createConsumer(selector); } else { attributes |= ACKNOWLEDGED; consumer = createAcknowledgedConsumer(selector); } String attributesSegment = "attributes-" + attributes; UriBuilder location = uriInfo.getAbsolutePathBuilder(); location.path(attributesSegment); location.path(consumer.getId()); Response.ResponseBuilder builder = Response.created(location.build()); if (autoAck) { QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1"); } else { AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1"); } return builder.build(); } catch (ActiveMQException e) { throw new RuntimeException(e); } finally { } }
Example 16
Source File: OrderResource.java From blog-tutorials with MIT License | 5 votes |
@POST public Response createNewOrder(JsonObject order, @Context UriInfo uriInfo) { Integer newOrderId = this.orderService.createNewOrder(new Order(order)); UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder(); uriBuilder.path(Integer.toString(newOrderId)); return Response.created(uriBuilder.build()).build(); }
Example 17
Source File: OIDCLoginProtocolService.java From keycloak with Apache License 2.0 | 4 votes |
public static UriBuilder authUrl(UriBuilder baseUriBuilder) { UriBuilder uriBuilder = tokenServiceBaseUrl(baseUriBuilder); return uriBuilder.path(OIDCLoginProtocolService.class, "auth"); }
Example 18
Source File: TopicResource.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected String createSenderLink(UriInfo info) { UriBuilder builder = info.getRequestUriBuilder(); builder.path("create"); String uri = builder.build().toString(); return uri; }
Example 19
Source File: DockerV2LoginProtocolService.java From keycloak with Apache License 2.0 | 4 votes |
public static UriBuilder authUrl(final UriBuilder baseUriBuilder) { final UriBuilder uriBuilder = authProtocolBaseUrl(baseUriBuilder); return uriBuilder.path(DockerV2LoginProtocolService.class, "auth"); }
Example 20
Source File: ResponseBuilder.java From library with Apache License 2.0 | 3 votes |
/** * Create a new http-201 response * * @return the http-201 (created) response */ public Response created() { final UriBuilder builder = this.location.getAbsolutePathBuilder(); if (this.entity == null) { throw new WebserviceException("The response entity can't be null"); } builder.path(this.entity); return Response.created(builder.build()).entity(this.entity).build(); }