All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.yaas.servicesdk.apiconsole.web.RootApiConsoleEndpoint Maven / Gradle / Ivy

There is a newer version: 4.17.1
Show newest version
/*
 * © 2016 SAP SE or an SAP affiliate company.
 * All rights reserved.
 * Please see http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and
 * notices.
 */
package com.sap.cloud.yaas.servicesdk.apiconsole.web;

import com.sap.cloud.yaas.servicesdk.apiconsole.utils.ApiConsoleLocationProvider;
import com.sap.cloud.yaas.servicesdk.ramlrewriter.filter.ExternalUrlHeaderUtil;

import java.net.URI;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;


/**
 * Root resource definition which redirects to api-console resource with configured RAML resource path when someone
 * tries to access the service root path.
 */
@Path("/")
public class RootApiConsoleEndpoint
{
	/**
	 * The suffix that should be appended when someone tries to access the API Console from root path of the service.
	 */
	private static final String PATH_SUFFIX = "api-console/index.html";

	private final ApiConsoleLocationProvider apiConsoleLocationProvider = new ApiConsoleLocationProvider();

	/**
	 * Redirects to the raml resource path.
	 *
	 * @param uriInfo uri from jax-rx context to get the base uri
	 * @param externalUrlHeader the external header
	 * @return redirect to raml resource path
	 */
	@GET
	public final Response redirectFromRoot(@Context final UriInfo uriInfo,
			@HeaderParam(ExternalUrlHeaderUtil.HYBRIS_EXTERNAL_URL) final String externalUrlHeader)
	{
		final URI uri = UriBuilder
				.fromUri(apiConsoleLocationProvider.getApiConsoleUri(uriInfo, externalUrlHeader))
				.path(PATH_SUFFIX)
				.build();
		return apiConsoleLocationProvider.processRedirect(uri);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy