use of org.wso2.carbon.identity.core.URLBuilderException in project identity-api-server by wso2.
the class ContextLoader method buildURIForHeader.
/**
* Build the complete URI prepending the user API context without the proxy context path, to the endpoint.
* Ex: https://localhost:9443/t/<tenant-domain>/api/users/<endpoint>
*
* @param endpoint relative endpoint path.
* @return Fully qualified and complete URI.
*/
public static URI buildURIForHeader(String endpoint) {
URI loc;
String context = getContext(endpoint);
try {
String url = ServiceURLBuilder.create().addPath(context).build().getAbsolutePublicURL();
loc = URI.create(url);
} catch (URLBuilderException e) {
String errorDescription = "Server encountered an error while building URL for response header.";
throw buildInternalServerError(e, errorDescription);
}
return loc;
}
use of org.wso2.carbon.identity.core.URLBuilderException in project carbon-identity-framework by wso2.
the class ConfigurationEndpointUtils method buildURIForHeader.
/**
* Build the complete URI prepending the user API context without the proxy context path, to the endpoint.
* Ex: https://localhost:9443/t/<tenant-domain>/api/users/<endpoint>
*
* @param endpoint relative endpoint path.
* @return Fully qualified and complete URI.
*/
public static URI buildURIForHeader(String endpoint) {
String url = null;
if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
try {
url = ServiceURLBuilder.create().addPath(SERVER_API_PATH_COMPONENT + endpoint).build().getRelativePublicURL();
} catch (URLBuilderException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while building URI for header.", e);
}
}
}
if (StringUtils.isBlank(url)) {
String tenantQualifiedRelativePath = String.format(TENANT_CONTEXT_PATH_COMPONENT, getTenantDomainFromContext()) + SERVER_API_PATH_COMPONENT;
url = IdentityUtil.getEndpointURIPath(tenantQualifiedRelativePath + endpoint, false, true);
}
URI loc = URI.create(url);
if (!loc.isAbsolute()) {
Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
if (currentMessage != null) {
UriInfo ui = new UriInfoImpl(currentMessage.getExchange().getInMessage(), null);
try {
return new URI(ui.getBaseUri().getScheme(), ui.getBaseUri().getAuthority(), url, null, null);
} catch (URISyntaxException e) {
log.error("Server encountered an error while building the location URL with scheme: " + ui.getBaseUri().getScheme() + ", authority: " + ui.getBaseUri().getAuthority() + ", url: " + url, e);
}
}
}
return loc;
}
use of org.wso2.carbon.identity.core.URLBuilderException in project carbon-identity-framework by wso2.
the class DefaultServiceURLBuilder method getResolvedParamString.
private String getResolvedParamString(Map<String, String> parameters) throws URLBuilderException {
StringJoiner joiner = new StringJoiner("&");
if (MapUtils.isNotEmpty(parameters)) {
for (Map.Entry<String, String> entry : parameters.entrySet()) {
StringBuilder paramBuilder = new StringBuilder();
try {
paramBuilder.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.name())).append("=").append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new URLBuilderException(String.format("Error while trying to build url. %s is not supported" + ".", StandardCharsets.UTF_8.name()), e);
}
joiner.add(paramBuilder.toString());
}
}
return joiner.toString();
}
use of org.wso2.carbon.identity.core.URLBuilderException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class IdentityResourceURLBuilderTest method testBuildThrowingNotFoundException.
@Test(expectedExceptions = NotFoundException.class, dataProvider = "dataProviderForBuildThrowingNotFoundException")
public void testBuildThrowingNotFoundException(boolean isTenantQualifiedUrlsEnabled, String resource) throws URLBuilderException, NotFoundException {
when(IdentityTenantUtil.isTenantQualifiedUrlsEnabled()).thenReturn(isTenantQualifiedUrlsEnabled);
when(mockServiceURLBuilder.build()).thenThrow(new URLBuilderException("Protocol of service URL is not available."));
IdentityResourceURLBuilder identityResourceURLBuilder = new IdentityResourceURLBuilder();
identityResourceURLBuilder.build(resource);
}
use of org.wso2.carbon.identity.core.URLBuilderException in project identity-inbound-auth-oauth by wso2-extensions.
the class OIDCLogoutServletTest method mockServiceURLBuilder.
private void mockServiceURLBuilder(String context) throws URLBuilderException {
mockStatic(ServiceURLBuilder.class);
ServiceURLBuilder serviceURLBuilder = mock(ServiceURLBuilder.class);
when(ServiceURLBuilder.create()).thenReturn(serviceURLBuilder);
when(serviceURLBuilder.addPath(any())).thenReturn(serviceURLBuilder);
ServiceURL serviceURL = mock(ServiceURL.class);
when(serviceURL.getRelativeInternalURL()).thenReturn(context);
when(serviceURLBuilder.build()).thenReturn(serviceURL);
}
Aggregations