use of org.apache.pulsar.common.util.RestException in project pulsar by apache.
the class WebSocketProxyStatsBase method internalGetStats.
protected ProxyTopicStat internalGetStats(TopicName topicName) {
validateUserAccess(topicName);
ProxyTopicStat stats = getStat(topicName);
if (stats == null) {
throw new RestException(Status.NOT_FOUND, "Topic does not exist");
}
return stats;
}
use of org.apache.pulsar.common.util.RestException in project pulsar by apache.
the class WebSocketWebResource method clientAppId.
/**
* Gets a caller id (IP + role).
*
* @return the web service caller identification
*/
public String clientAppId() {
if (isBlank(clientId)) {
try {
String authMethodName = httpRequest.getHeader(AuthenticationFilter.PULSAR_AUTH_METHOD_NAME);
if (authMethodName != null && service().getAuthenticationService().getAuthenticationProvider(authMethodName) != null) {
authenticationDataSource = service().getAuthenticationService().getAuthenticationProvider(authMethodName).newHttpAuthState(httpRequest).getAuthDataSource();
clientId = service().getAuthenticationService().authenticateHttpRequest(httpRequest, authenticationDataSource);
} else {
clientId = service().getAuthenticationService().authenticateHttpRequest(httpRequest);
authenticationDataSource = new AuthenticationDataHttps(httpRequest);
}
} catch (AuthenticationException e) {
if (service().getConfig().isAuthenticationEnabled()) {
throw new RestException(Status.UNAUTHORIZED, "Failed to get clientId from request");
}
}
if (isBlank(clientId) && service().getConfig().isAuthenticationEnabled()) {
throw new RestException(Status.UNAUTHORIZED, "Failed to get auth data from the request");
}
}
return clientId;
}
use of org.apache.pulsar.common.util.RestException in project pulsar by apache.
the class FunctionApiV2ResourceTest method testRegisterFunctionUploadFailure.
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testRegisterFunctionUploadFailure() throws Exception {
try {
mockWorkerUtils(ctx -> {
ctx.when(() -> WorkerUtils.uploadFileToBookkeeper(anyString(), any(File.class), any(Namespace.class))).thenThrow(new IOException("upload failure"));
});
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
registerDefaultFunction();
} catch (RestException re) {
assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
throw re;
}
}
use of org.apache.pulsar.common.util.RestException in project pulsar by apache.
the class FunctionApiV2ResourceTest method testUpdateFunctionUploadFailure.
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testUpdateFunctionUploadFailure() throws Exception {
try {
mockWorkerUtils(ctx -> {
ctx.when(() -> WorkerUtils.uploadFileToBookkeeper(anyString(), any(File.class), any(Namespace.class))).thenThrow(new IOException("upload failure"));
});
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
updateDefaultFunction();
} catch (RestException re) {
assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
throw re;
}
}
use of org.apache.pulsar.common.util.RestException in project pulsar by apache.
the class SinkApiV3ResourceTest method testUpdateSinkFailedWithWrongPackageName.
@Test(timeOut = 20000)
public void testUpdateSinkFailedWithWrongPackageName() throws Exception {
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
try {
doThrow(new PulsarAdminException("package name is invalid")).when(mockedPackages).download(anyString(), anyString());
updateDefaultSinkWithPackageUrl("function://");
} catch (RestException e) {
// expected exception
assertEquals(e.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
}
}
Aggregations