Java Code Examples for javax.ws.rs.core.UriInfo#getBaseUriBuilder()

The following examples show how to use javax.ws.rs.core.UriInfo#getBaseUriBuilder() . 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: QueueConsumer.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Path("consume-next{index}")
@POST
public synchronized Response poll(@HeaderParam(Constants.WAIT_HEADER) @DefaultValue("0") long wait,
                                  @PathParam("index") long index,
                                  @Context UriInfo info) {
   ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + info.getRequestUri() + "\"");

   if (closed) {
      UriBuilder builder = info.getBaseUriBuilder();
      builder.path(info.getMatchedURIs().get(1)).path("consume-next");
      String uri = builder.build().toString();

      // redirect to another consume-next

      return Response.status(307).location(URI.create(uri)).build();
   }
   return checkIndexAndPoll(wait, info, info.getMatchedURIs().get(1), index);
}
 
Example 2
Source File: RootServiceImpl.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
public Response head(UriInfo uriInfo) {
    UriBuilder absolute = uriInfo.getBaseUriBuilder();
    URI claimUrl = absolute.clone().path("claims").build();
    URI idpUrl = absolute.clone().path("idps").build();
    URI applicationUrl = absolute.clone().path("applications").build();
    URI trustedIdpUrl = absolute.clone().path("trusted-idps").build();
    URI rolesUrl = absolute.clone().path("roles").build();
    URI entitlementsUrl = absolute.clone().path("entitlements").build();
    javax.ws.rs.core.Link claims = javax.ws.rs.core.Link.fromUri(claimUrl).rel("claims")
        .type("application/xml").build();
    javax.ws.rs.core.Link idps = javax.ws.rs.core.Link.fromUri(idpUrl).rel("idps")
        .type("application/xml").build();
    javax.ws.rs.core.Link applications = javax.ws.rs.core.Link.fromUri(applicationUrl).rel("applications")
        .type("application/xml").build();
    javax.ws.rs.core.Link trustedIdps = javax.ws.rs.core.Link.fromUri(trustedIdpUrl).rel("trusted-idps")
        .type("application/xml").build();
    javax.ws.rs.core.Link roles = javax.ws.rs.core.Link.fromUri(rolesUrl).rel("roles")
        .type("application/xml").build();
    javax.ws.rs.core.Link entitlements = javax.ws.rs.core.Link.fromUri(entitlementsUrl).rel("entitlements")
        .type("application/xml").build();

    Response.ResponseBuilder builder = Response.ok().links(
        claims, idps, applications, trustedIdps, roles, entitlements);
    return builder.build();
}
 
Example 3
Source File: AcknowledgedQueueConsumer.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
@Path("acknowledge-next{index}")
@POST
public synchronized Response poll(@HeaderParam(Constants.WAIT_HEADER) @DefaultValue("0") long wait,
                                  @PathParam("index") long index,
                                  @Context UriInfo info) {
   ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + info.getPath() + "\"");

   if (closed) {
      UriBuilder builder = info.getBaseUriBuilder();
      String path = info.getMatchedURIs().get(1);
      builder.path(path).path("acknowledge-next");
      String uri = builder.build().toString();

      // redirect to another acknowledge-next

      return Response.status(307).location(URI.create(uri)).build();
   }
   return checkIndexAndPoll(wait, info, info.getMatchedURIs().get(1), index);
}
 
Example 4
Source File: RepositoryEntriesResource.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * List all entries in the OLAT repository
 * 
 * @response.representation.200.qname {http://www.example.com}repositoryEntryVO
 * @response.representation.200.mediaType text/plain, text/html, application/xml, application/json
 * @response.representation.200.doc List all entries in the repository
 * @response.representation.200.example {@link org.olat.connectors.rest.support.vo.Examples#SAMPLE_REPOENTRYVOes}
 * @param uriInfo
 *            The URI information
 * @param httpRequest
 *            The HTTP request
 * @return
 */
@GET
@Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
public Response getEntriesText(@Context final UriInfo uriInfo, @Context final HttpServletRequest httpRequest) {
    try {
        // list of courses open for everybody
        final Roles roles = getRoles(httpRequest);
        final List<String> types = new ArrayList<String>();
        final List<RepositoryEntry> coursRepos = RepositoryServiceImpl.getInstance().genericANDQueryWithRolesRestriction("*", "*", "*", types, roles, null);

        final StringBuilder sb = new StringBuilder();
        sb.append("Course List\n");
        for (final RepositoryEntry repoE : coursRepos) {
            final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
            final URI repoUri = baseUriBuilder.path(RepositoryEntriesResource.class).path(repoE.getKey().toString()).build();

            sb.append("<a href=\"").append(repoUri).append(">").append(repoE.getDisplayname()).append("(").append(repoE.getKey()).append(")").append("</a>")
                    .append("\n");
        }

        return Response.ok(sb.toString()).build();
    } catch (final Exception e) {
        throw new WebApplicationException(e);
    }
}
 
Example 5
Source File: UserVOFactory.java    From olat with Apache License 2.0 6 votes vote down vote up
public static UserVO link(final UserVO userVO, final UriInfo uriInfo) {
    if (uriInfo != null) {
        final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        final URI getUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).build();
        userVO.getLink().add(new LinkVO("self", getUri.toString(), ""));
        userVO.getLink().add(new LinkVO("edit", getUri.toString(), ""));
        userVO.getLink().add(new LinkVO("delete", getUri.toString(), ""));

        final URI groupUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).path("groups").build();
        userVO.getLink().add(new LinkVO("self", groupUri.toString(), "Groups"));

        final URI portraitUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).path("portrait").build();
        userVO.getLink().add(new LinkVO("self", portraitUri.toString(), "Portrait"));
    }
    return userVO;
}
 
Example 6
Source File: ArchiveLogCollection.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * コンストラクタ.
 * @param cell コレクションが属するCellオブジェクト
 * @param uriInfo コレクションのURL情報
 */
public ArchiveLogCollection(Cell cell, UriInfo uriInfo) {
    // archiveコレクションの作成日と更新日はセルの作成日とする
    // ただし更新日についてはアーカイブログファイルが作成されている場合、そのファイルの最新日が「createFileInformation」で設定される
    this.created = cell.getPublished();
    this.updated = cell.getPublished();

    // archiveコレクションのURLを生成
    StringBuilder urlSb = new StringBuilder();
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    uriBuilder.scheme(DcCoreConfig.getUnitScheme());
    urlSb.append(uriBuilder.build().toASCIIString());
    urlSb.append(uriInfo.getPath());
    this.url = urlSb.toString();

    StringBuilder archiveDirName = EventUtils.getEventLogDir(cell.getId(), cell.getOwner()).append("archive");
    this.directoryPath = archiveDirName.toString();
}
 
Example 7
Source File: UserVOFactory.java    From olat with Apache License 2.0 6 votes vote down vote up
public static UserVO link(final UserVO userVO, final UriInfo uriInfo) {
    if (uriInfo != null) {
        final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        final URI getUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).build();
        userVO.getLink().add(new LinkVO("self", getUri.toString(), ""));
        userVO.getLink().add(new LinkVO("edit", getUri.toString(), ""));
        userVO.getLink().add(new LinkVO("delete", getUri.toString(), ""));

        final URI groupUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).path("groups").build();
        userVO.getLink().add(new LinkVO("self", groupUri.toString(), "Groups"));

        final URI portraitUri = baseUriBuilder.path("users").path(userVO.getKey().toString()).path("portrait").build();
        userVO.getLink().add(new LinkVO("self", portraitUri.toString(), "Portrait"));
    }
    return userVO;
}
 
Example 8
Source File: StoreResource.java    From resteasy-examples with Apache License 2.0 5 votes vote down vote up
@HEAD
public Response head(@Context UriInfo uriInfo)
{
   UriBuilder absolute = uriInfo.getBaseUriBuilder();
   URI customerUrl = absolute.clone().path(CustomerResource.class).build();
   URI orderUrl = absolute.clone().path(OrderResource.class).build();

   Response.ResponseBuilder builder = Response.ok();
   Link customers = Link.fromUri(customerUrl).rel("customers").type("application/xml").build();
   Link orders = Link.fromUri(orderUrl).rel("orders").type("application/xml").build();
   builder.links(customers, orders);
   return builder.build();
}
 
Example 9
Source File: ChangedUriInfo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
public ChangedUriInfo(String uri, UriInfo uriInfo) {
    this.uri = URI.create(uri);
    this.original = uriInfo;
    if (uriInfo != null) {
        this.baseUriBuilder = uriInfo.getBaseUriBuilder();
        if (uriInfo instanceof WebApplicationContext) {
            originalUri = uriInfo.getBaseUri() + ((WebApplicationContext) uriInfo).getProperties().get(ORIGINAL_REQUEST_KEY).toString();
        }
    }
}
 
Example 10
Source File: CellEsImpl.java    From io with Apache License 2.0 5 votes vote down vote up
private static String getBaseUri(final UriInfo uriInfo, String cellName) {
    // URLを生成してSet
    StringBuilder urlSb = new StringBuilder();
    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
    uriBuilder.scheme(DcCoreConfig.getUnitScheme());
    urlSb.append(uriBuilder.build().toASCIIString());
    urlSb.append(cellName);
    urlSb.append("/");
    return urlSb.toString();
}
 
Example 11
Source File: AcknowledgedQueueConsumer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static void setAcknowledgeNextLink(LinkStrategy linkStrategy,
                                          Response.ResponseBuilder response,
                                          UriInfo info,
                                          String basePath,
                                          String index) {
   if (index == null)
      throw new IllegalArgumentException("index cannot be null");
   UriBuilder builder = info.getBaseUriBuilder();
   builder.path(basePath).path("acknowledge-next" + index);
   String uri = builder.build().toString();
   linkStrategy.setLinkHeader(response, "acknowledge-next", "acknowledge-next", uri, MediaType.APPLICATION_FORM_URLENCODED);
}
 
Example 12
Source File: PostMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Response internalPostWithId(String dupId,
                                    Boolean durable,
                                    Long ttl,
                                    Long expiration,
                                    Integer priority,
                                    HttpHeaders headers,
                                    UriInfo uriInfo,
                                    byte[] body) {
   String matched = uriInfo.getMatchedURIs().get(1);
   UriBuilder nextBuilder = uriInfo.getBaseUriBuilder();
   String nextId = generateDupId();
   nextBuilder.path(matched).path(nextId);
   URI next = nextBuilder.build();

   boolean isDurable = defaultDurable;
   if (durable != null) {
      isDurable = durable.booleanValue();
   }
   try {
      publish(headers, body, dupId, isDurable, ttl, expiration, priority);
   } catch (Exception e) {
      Response error = Response.serverError().entity("Problem posting message: " + e.getMessage()).type("text/plain").build();
      throw new WebApplicationException(e, error);
   }
   Response.ResponseBuilder builder = Response.status(201);
   serviceManager.getLinkStrategy().setLinkHeader(builder, "create-next", "create-next", next.toString(), "*/*");
   return builder.build();
}
 
Example 13
Source File: CatalogVOFactory.java    From olat with Apache License 2.0 5 votes vote down vote up
public static CatalogEntryVO link(final CatalogEntryVO entryVo, final UriInfo uriInfo) {
    if (uriInfo != null) {
        final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        final URI getUri = baseUriBuilder.path("catalog").path(entryVo.getKey().toString()).build();
        entryVo.getLink().add(new LinkVO("self", getUri.toString(), ""));
        entryVo.getLink().add(new LinkVO("jumpin", Settings.getServerContextPathURI() + "/url/CatalogEntry/" + entryVo.getKey(), ""));
        entryVo.getLink().add(new LinkVO("edit", getUri.toString(), ""));
        entryVo.getLink().add(new LinkVO("delete", getUri.toString(), ""));

        final URI childrenUri = baseUriBuilder.path("catalog").path(entryVo.getKey().toString()).path("children").build();
        entryVo.getLink().add(new LinkVO("children", childrenUri.toString(), ""));
    }
    return entryVo;
}
 
Example 14
Source File: CatalogVOFactory.java    From olat with Apache License 2.0 5 votes vote down vote up
public static CatalogEntryVO link(final CatalogEntryVO entryVo, final UriInfo uriInfo) {
    if (uriInfo != null) {
        final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
        final URI getUri = baseUriBuilder.path("catalog").path(entryVo.getKey().toString()).build();
        entryVo.getLink().add(new LinkVO("self", getUri.toString(), ""));
        entryVo.getLink().add(new LinkVO("jumpin", Settings.getServerContextPathURI() + "/url/CatalogEntry/" + entryVo.getKey(), ""));
        entryVo.getLink().add(new LinkVO("edit", getUri.toString(), ""));
        entryVo.getLink().add(new LinkVO("delete", getUri.toString(), ""));

        final URI childrenUri = baseUriBuilder.path("catalog").path(entryVo.getKey().toString()).path("children").build();
        entryVo.getLink().add(new LinkVO("children", childrenUri.toString(), ""));
    }
    return entryVo;
}
 
Example 15
Source File: OIDCLoginProtocolService.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static UriBuilder tokenServiceBaseUrl(UriInfo uriInfo) {
    UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    return tokenServiceBaseUrl(baseUriBuilder);
}
 
Example 16
Source File: DockerV2LoginProtocolService.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static UriBuilder authUrl(final UriInfo uriInfo) {
    final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    return authUrl(baseUriBuilder);
}
 
Example 17
Source File: RealmsResource.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static UriBuilder realmBaseUrl(UriInfo uriInfo) {
    UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    return realmBaseUrl(baseUriBuilder);
}
 
Example 18
Source File: AcknowledgedQueueConsumer.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void setAcknowledgementLink(Response.ResponseBuilder response, UriInfo info, String basePath) {
   UriBuilder builder = info.getBaseUriBuilder();
   builder.path(basePath).path("acknowledgement").path(getAckToken());
   String uri = builder.build().toString();
   serviceManager.getLinkStrategy().setLinkHeader(response, "acknowledgement", "acknowledgement", uri, MediaType.APPLICATION_FORM_URLENCODED);
}
 
Example 19
Source File: OIDCLoginProtocolService.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static UriBuilder logoutUrl(UriInfo uriInfo) {
    UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    return logoutUrl(baseUriBuilder);
}
 
Example 20
Source File: LoginActionsService.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static UriBuilder loginActionsBaseUrl(UriInfo uriInfo) {
    UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    return loginActionsBaseUrl(baseUriBuilder);
}