Search in sources :

Example 11 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class ContactCardTest method getBaseUri.

@Override
protected URI getBaseUri() {
    final UriBuilder baseUriBuilder = UriBuilder.fromUri(super.getBaseUri()).path("bean-validation-webapp");
    final boolean externalFactoryInUse = getTestContainerFactory() instanceof ExternalTestContainerFactory;
    return externalFactoryInUse ? baseUriBuilder.path("api").build() : baseUriBuilder.build();
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) ExternalTestContainerFactory(org.glassfish.jersey.test.external.ExternalTestContainerFactory)

Example 12 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class BookmarksResource method getBookmarksAsJsonArray.

@GET
@Produces(MediaType.APPLICATION_JSON)
public JSONArray getBookmarksAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (BookmarkEntity bookmarkEntity : getBookmarks()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI bookmarkUri = ub.path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
        uriArray.put(bookmarkUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) BookmarkEntity(org.glassfish.jersey.examples.bookmark.entity.BookmarkEntity) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class UsersResource method getUsersAsJsonArray.

@GET
@Produces("application/json")
public JSONArray getUsersAsJsonArray() {
    JSONArray uriArray = new JSONArray();
    for (UserEntity userEntity : getUsers()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI userUri = ub.path(userEntity.getUserid()).build();
        uriArray.put(userUri.toASCIIString());
    }
    return uriArray;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UserEntity(org.glassfish.jersey.examples.bookmark.entity.UserEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class WadlApplicationContextImpl method attachExternalGrammar.

/**
     * Update the application object to include the generated grammar objects.
     */
private void attachExternalGrammar(final Application application, final ApplicationDescription applicationDescription, URI requestURI) {
    try {
        final String requestURIPath = requestURI.getPath();
        if (requestURIPath.endsWith("application.wadl")) {
            requestURI = UriBuilder.fromUri(requestURI).replacePath(requestURIPath.substring(0, requestURIPath.lastIndexOf('/') + 1)).build();
        }
        final String root = application.getResources().get(0).getBase();
        final UriBuilder extendedPath = root != null ? UriBuilder.fromPath(root).path("/application.wadl/") : UriBuilder.fromPath("./application.wadl/");
        final URI rootURI = root != null ? UriBuilder.fromPath(root).build() : null;
        // Add a reference to this grammar
        //
        final Grammars grammars;
        if (application.getGrammars() != null) {
            LOGGER.info(LocalizationMessages.ERROR_WADL_GRAMMAR_ALREADY_CONTAINS());
            grammars = application.getGrammars();
        } else {
            grammars = new Grammars();
            application.setGrammars(grammars);
        }
        for (final String path : applicationDescription.getExternalMetadataKeys()) {
            final URI schemaURI = extendedPath.clone().path(path).build();
            final String schemaPath = rootURI != null ? requestURI.relativize(schemaURI).toString() : schemaURI.toString();
            final Include include = new Include();
            include.setHref(schemaPath);
            final Doc doc = new Doc();
            doc.setLang("en");
            doc.setTitle("Generated");
            include.getDoc().add(doc);
            // Finally add to list
            grammars.getInclude().add(include);
        }
    } catch (final Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_EXTERNAL_GRAMMAR(), e);
    }
}
Also used : Include(com.sun.research.ws.wadl.Include) Doc(com.sun.research.ws.wadl.Doc) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Grammars(com.sun.research.ws.wadl.Grammars) JAXBException(javax.xml.bind.JAXBException) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 15 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project hadoop by apache.

the class WebAppProxyServlet method buildTrackingUrl.

/**
   * Return a URL based on the {@code trackingUri} that includes the
   * user-provided path and query parameters.
   *
   * @param trackingUri the base tracking URI
   * @param req the service request
   * @param rest the user-provided path
   * @return the new tracking URI
   * @throws UriBuilderException if there's an error building the URL
   */
private URI buildTrackingUrl(URI trackingUri, final HttpServletRequest req, String rest) throws UriBuilderException {
    UriBuilder builder = UriBuilder.fromUri(trackingUri);
    String queryString = req.getQueryString();
    if (queryString != null) {
        List<NameValuePair> queryPairs = URLEncodedUtils.parse(queryString, null);
        for (NameValuePair pair : queryPairs) {
            builder.queryParam(pair.getName(), pair.getValue());
        }
    }
    return builder.path(rest).build();
}
Also used : NameValuePair(org.apache.http.NameValuePair) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)167 URI (java.net.URI)78 Test (org.junit.Test)58 HashMap (java.util.HashMap)21 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)12 PUT (javax.ws.rs.PUT)11 Produces (javax.ws.rs.Produces)9 URL (java.net.URL)8 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 Timed (com.codahale.metrics.annotation.Timed)7 POST (javax.ws.rs.POST)7 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 ServerException (org.eclipse.che.api.core.ServerException)6 List (java.util.List)5