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

The following examples show how to use javax.ws.rs.core.UriInfo#getBaseUri() . 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: TechnologyEndpoint.java    From tool.accelerate.core with Apache License 2.0 6 votes vote down vote up
@GET
@Path("{tech}")
@Produces(MediaType.APPLICATION_JSON)
// Swagger annotations
@ApiOperation(value = "Retrieve a specific technology", httpMethod = "GET", notes = "Get the details for a currently registered set of technologies. This should not be cached as it may change at any time.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "The technology details"),
        @ApiResponse(code = 404, message = "The technology could not be found") })
public Response getTechnology(@PathParam("tech") String tech, @Context UriInfo info) {
    if (PatternValidation.checkPattern(PatternType.TECH, tech)) {
        ServiceConnector serviceConnector = new ServiceConnector(info.getBaseUri());
        Service service = serviceConnector.getServiceObjectFromId(tech);
        if (service == null) {
            return Response.status(Status.NOT_FOUND).build();
        } else {
            return Response.ok(service, MediaType.APPLICATION_JSON).build();
        }
    } else {
        return Response.status(Status.BAD_REQUEST).entity("Invalid technology type.").build();
    }
}
 
Example 2
Source File: Sample.java    From cf-java-logging-support with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/forward")
public Response forward(@Context UriInfo uriInfo, @QueryParam("q") String queryParam,
                        @Context HttpHeaders headers) {
    LoggerFactory.getLogger(Sample.class).info("forwarding request");
    URI baseUri = uriInfo.getBaseUri();
    StringBuilder targetUri = new StringBuilder(baseUri.toString().replace("/jersey", ""));
    if (queryParam != null) {
        targetUri.append("?").append(queryParam);
    }
    Invocation.Builder forwReq = ClientBuilder.newClient(clientConfig).target(targetUri.toString()).request();
    forwReq = ClientRequestUtils.propagate(forwReq, headers);
    return Response.status(200).entity(forwReq.get(String.class)).build();
}
 
Example 3
Source File: AlmApiStub.java    From alm-rest-api with GNU General Public License v3.0 5 votes vote down vote up
private static Response unauthorizedResponse(UriInfo uriInfo)
{
    URI baseUri = uriInfo.getBaseUri();

    String authenticateHeader = String.format(
            "LWSSO realm=%s", authenticationPoint(baseUri.getHost(), String.valueOf(baseUri.getPort())));

    return Response.status(Status.UNAUTHORIZED).header("WWW-Authenticate", authenticateHeader).build();
}
 
Example 4
Source File: RepositoryCallInterceptor.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
@GET
@Path("net/wasdev/wlp/starters/{tech}/{path: .*}")
public Response getArtifacts(@PathParam("tech") String tech, @PathParam("path") String path, @Context UriInfo info) throws IOException {
    if (PatternValidation.checkPattern(PatternType.TECH, tech)
        && PatternValidation.checkPattern(PatternType.PATH_EXTENSION, path)) {
        String fileExtension = "net/wasdev/wlp/starters/" + tech + "/" + path;
        System.out.println("Request for artifact file " + fileExtension);
        ServiceConnector serviceConnector = new ServiceConnector(info.getBaseUri());
        Service service;
        if ("ms-builder".equals(tech)) {
            service = serviceConnector.getServiceObjectFromId("msbuilder");
        } else {
            service = serviceConnector.getServiceObjectFromId(tech);
        }
        if (service == null) {
            return Response.status(Status.NOT_FOUND).entity("Tech type " + tech + " not found").build();
        }
        try {
            InputStream is = serviceConnector.getArtifactAsInputStream(service, fileExtension);
            return Response.ok(is).build();
        } catch (Exception e) {
            System.out.println("File " + fileExtension + " not found so returning a 404.");
            return Response.status(Status.NOT_FOUND).entity("File not found: " + fileExtension + " not found.").build();
        }
    } else {
        return Response.status(Status.BAD_REQUEST).entity("Invalid file request.").build();
    }

}
 
Example 5
Source File: TechnologyEndpoint.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
// Swagger annotations
@ApiOperation(value = "Retrieve a list of technologies", httpMethod = "GET", notes = "Get a list of the currently registered set of technologies. This should not be cached as it may change at any time.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "The list of technologies") })
public Response tech(@Context UriInfo info) {
    ServiceConnector serviceConnector = new ServiceConnector(info.getBaseUri());
    return Response.ok(serviceConnector.getServices().getServices(), MediaType.APPLICATION_JSON).build();
}
 
Example 6
Source File: CellEsImpl.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * @param uriInfo
 *            UriInfo
 * @return Cell オブジェクト 該当するCellが存在しないときはnull
 */
public static Cell load(final UriInfo uriInfo) {
    URI reqUri = uriInfo.getRequestUri();
    URI baseUri = uriInfo.getBaseUri();

    String rPath = reqUri.getPath();
    String bPath = baseUri.getPath();
    rPath = rPath.substring(bPath.length());
    String[] paths = StringUtils.split(rPath, "/");

    return findCell("s.Name.untouched", paths[0], uriInfo);
}
 
Example 7
Source File: DefaultHostnameProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private URI resolveUri(UriInfo originalUriInfo, UrlType type) {
    URI realmUri = getRealmUri();
    URI frontendUri = realmUri != null ? realmUri : this.frontendUri;

    // Use frontend URI for backend requests if forceBackendUrlToFrontendUrl is true
    if (type.equals(UrlType.BACKEND) && forceBackendUrlToFrontendUrl) {
        type = UrlType.FRONTEND;
    }

    // Use frontend URI for backend requests if request hostname matches frontend hostname
    if (type.equals(UrlType.BACKEND) && frontendUri != null && originalUriInfo.getBaseUri().getHost().equals(frontendUri.getHost())) {
        type = UrlType.FRONTEND;
    }

    // Use frontend URI for admin requests if adminUrl not set
    if (type.equals(UrlType.ADMIN)) {
        if (adminUri != null) {
            return adminUri;
        } else {
            type = UrlType.FRONTEND;
        }
    }

    if (type.equals(UrlType.FRONTEND) && frontendUri != null) {
        return frontendUri;
    }

    return originalUriInfo.getBaseUri();
}
 
Example 8
Source File: GetResponseBuilder.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private String getOriginalRequestPath(final UriInfo context) {
    if (context instanceof WebApplicationContext) {
        String originalUri = context.getBaseUri() + ((WebApplicationContext) context).getProperties().get(ORIGINAL_REQUEST_KEY).toString();
        return originalUri;
    } else if (context instanceof ChangedUriInfo) {
        return ((ChangedUriInfo)context).getOriginalUri();
    } else {
        return context.getRequestUri().toString();
    }
}
 
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: SampleResource.java    From jrestless-examples with Apache License 2.0 4 votes vote down vote up
BaseAndRequestUri(UriInfo uriInfo) {
	this(uriInfo.getBaseUri(), uriInfo.getRequestUri());
}
 
Example 11
Source File: AccountConsole.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@GET
@NoCache
public Response getMainPage() throws IOException, FreeMarkerException {
    if (!session.getContext().getUri().getRequestUri().getPath().endsWith("/")) {
        return Response.status(302).location(session.getContext().getUri().getRequestUriBuilder().path("/").build()).build();
    } else {
        Map<String, Object> map = new HashMap<>();

        UriInfo uriInfo = session.getContext().getUri(UrlType.FRONTEND);
        URI authUrl = uriInfo.getBaseUri();
        map.put("authUrl", authUrl.toString());
        map.put("baseUrl", uriInfo.getBaseUriBuilder().path(RealmsResource.class).path(realm.getName()).path(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).build(realm).toString());
        map.put("realm", realm);
        map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName());
        map.put("resourceVersion", Version.RESOURCES_VERSION);
        
        String[] referrer = getReferrer();
        if (referrer != null) {
            map.put("referrer", referrer[0]);
            map.put("referrerName", referrer[1]);
            map.put("referrer_uri", referrer[2]);
        }
        
        UserModel user = null;
        if (auth != null) user = auth.getUser();
        Locale locale = session.getContext().resolveLocale(user);
        map.put("locale", locale.toLanguageTag());
        Properties messages = theme.getMessages(locale);
        map.put("msg", new MessageFormatterMethod(locale, messages));
        map.put("msgJSON", messagesToJsonString(messages));
        map.put("supportedLocales", supportedLocales(messages));
        map.put("properties", theme.getProperties());
        map.put("theme", (Function<String, String>) file -> {
            try {
                final InputStream resource = theme.getResourceAsStream(file);
                return new Scanner(resource, "UTF-8").useDelimiter("\\A").next();
            } catch (IOException e) {
                throw new RuntimeException("could not load file", e);
            }
        });

        EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
        map.put("isEventsEnabled", eventStore != null && realm.isEventsEnabled());
        map.put("isAuthorizationEnabled", true);
        
        boolean isTotpConfigured = false;
        if (user != null) {
            isTotpConfigured = session.userCredentialManager().isConfiguredFor(realm, user, realm.getOTPPolicy().getType());
        }
        map.put("isTotpConfigured", isTotpConfigured);

        FreeMarkerUtil freeMarkerUtil = new FreeMarkerUtil();
        String result = freeMarkerUtil.processTemplate(map, "index.ftl", theme);
        Response.ResponseBuilder builder = Response.status(Response.Status.OK).type(MediaType.TEXT_HTML_UTF_8).language(Locale.ENGLISH).entity(result);
        return builder.build();
    }
}
 
Example 12
Source File: RealmResource.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private static String uriToString(UriInfo uri) {
    return uri.getBaseUri() + uri.getPath().replaceAll("/$", "");
}
 
Example 13
Source File: CustomRoleResource.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private static String uriToString(UriInfo uri) {
    return uri.getBaseUri() + uri.getPath().replaceAll("/$", "");
}