protected ClientResponseFailure mockForbiddenResponse() { ClientResponseFailure error = mock(ClientResponseFailure.class); ClientResponse response = mock(ClientResponse.class); Response.Status responseStatus = Response.Status.FORBIDDEN; when(error.getResponse()).thenReturn(response); when(response.getResponseStatus()).thenReturn(responseStatus); return error; }
public ClientResponseFailure createResponseFailure(String message, Exception e) { setException(e); this.returnType = byte[].class; this.genericReturnType = null; this.annotations = null; return new ClientResponseFailure(message, e, (ClientResponse<byte[]>) this); }
protected ClientResponseFailure mockForbiddenResponse() { ClientResponseFailure error = mock(ClientResponseFailure.class); ClientResponse response = mock(ClientResponse.class); Response.Status responseStatus = Response.Status.FORBIDDEN; when(error.getResponse()).thenReturn(response); when(response.getResponseStatus()).thenReturn(responseStatus); return error; }
public ClientResponseFailure createResponseFailure(String message, Exception e) { setException(e); this.returnType = byte[].class; this.genericReturnType = null; this.annotations = null; return new ClientResponseFailure(message, e, (ClientResponse<byte[]>) this); }
protected void consumeRealm(final Consumer<RealmResource> consumer) { try { consumer.accept(getRealmResource()); } catch (ClientResponseFailure e) { if (STATUS_NOT_AUTHORIZED == e.getResponse().getResponseStatus().getStatusCode()) { throw new RealmManagementNotAuthorizedException(getKeyCloakInstance().getRealm()); } else { throw new SecurityManagementException(e); } } }
/** * Automatically does POST/Create pattern. Will throw a ClientResponseFailure * if status is something other than 201 * * @return Link to created resource * @throws Exception, ClientResponseFailure */ public Link create() throws Exception, ClientResponseFailure { BaseClientResponse response = (BaseClientResponse) post(); if (response.getStatus() != 201) throw new ClientResponseFailure(response); return response.getLocationLink(); }
protected void consumeRealm(final Consumer<RealmResource> consumer) { try { consumer.accept(getRealmResource()); } catch (ClientResponseFailure e) { if (STATUS_NOT_AUTHORIZED == e.getResponse().getResponseStatus().getStatusCode()) { throw new RealmManagementNotAuthorizedException(getKeyCloakInstance().getRealm()); } else { throw new SecurityManagementException(e); } } }
/** * Automatically does POST/Create pattern. Will throw a ClientResponseFailure * if status is something other than 201 * * @return Link to created resource * @throws Exception, ClientResponseFailure */ public Link create() throws Exception, ClientResponseFailure { BaseClientResponse response = (BaseClientResponse) post(); if (response.getStatus() != 201) throw new ClientResponseFailure(response); return response.getLocationLink(); }
protected RoleRepresentation getRoleRepresentation(String name, RoleResource roleResource) { if (roleResource != null) { try { return roleResource.toRepresentation(); } catch (NotFoundException e) { throw new GroupNotFoundException(name); } catch (ClientResponseFailure clientResponseFailure) { int status = clientResponseFailure.getResponse().getResponseStatus().getStatusCode(); if (404 == status) { throw new GroupNotFoundException(name); } } catch (Exception e) { throw new SecurityManagementException(e); } } throw new GroupNotFoundException(name); }
public <T> T postTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) post(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
protected RoleRepresentation getRoleRepresentation(String name, RoleResource roleResource) { if (roleResource != null) { try { return roleResource.toRepresentation(); } catch (NotFoundException e) { throw new GroupNotFoundException(name); } catch (ClientResponseFailure clientResponseFailure) { int status = clientResponseFailure.getResponse().getResponseStatus().getStatusCode(); if (404 == status) { throw new GroupNotFoundException(name); } } catch (Exception e) { throw new SecurityManagementException(e); } } throw new GroupNotFoundException(name); }
public <T> T postTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) post(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
/** * Get resources */ @Test(dependsOnMethods = {"getOneResource"}) public void getResources() throws Exception { showTitle("getResources"); List<String> resources = null; try { resources = getResourceService().getResourceList("Bearer " + pat.getAccessToken(), ""); } catch (ClientResponseFailure ex) { System.err.println(ex.getResponse().getEntity(String.class)); throw ex; } assertNotNull(resources, "Resources is null"); assertTrue(resources.contains(this.resourceId), "Resource list doesn't contain added resource"); }
/** * Tries to automatically unmarshal to target type. * * @param returnType * @param <T> * @return * @throws Exception */ public <T> T getTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) get(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
protected RuntimeException handleException(final Exception e) { if (e instanceof ClientResponseFailure) { final ClientResponseFailure crf = ((ClientResponseFailure) e); final ClientResponse response = crf.getResponse(); final int status = response.getStatus(); switch (status) { case HttpURLConnection.HTTP_BAD_REQUEST: return new BadRequestException(e); case HttpURLConnection.HTTP_INTERNAL_ERROR: return new InternalServerErrorException(e); case HttpURLConnection.HTTP_UNAUTHORIZED: return new UnauthorisedException(e); case 426: return new UpgradeException(e); case HttpURLConnection.HTTP_NOT_FOUND: return new NotFoundException(e); case HttpURLConnection.HTTP_FORBIDDEN: return new ForbiddenException(e); default: return crf; } } else if (e instanceof ProviderException) { return (ProviderException) e; } else if (e instanceof RuntimeException) { return (RuntimeException) e; } else { return new RuntimeException(e); } } }
/** * Tries to automatically unmarshal to target type. * * @param returnType * @param <T> * @return * @throws Exception */ public <T> T getTarget(Class<T> returnType) throws Exception { BaseClientResponse<T> response = (BaseClientResponse<T>) get(returnType); if (response.getStatus() == 204) return null; if (response.getStatus() != 200) throw new ClientResponseFailure(response); T obj = response.getEntity(); if (obj instanceof InputStream) { response.setWasReleased(true); } return obj; }
String entity = (String) ex.getResponse().getEntity(String.class); System.out.println(entity); assertEquals(ex.getResponse().getStatus(), Response.Status.FORBIDDEN.getStatusCode(), "Unexpected response status");
if (is == null) throw new ClientResponseFailure(Messages.MESSAGES.inputStreamEmpty(), this);
/** * Test UMA resource description modification with invalid PAT */ @Test(dependsOnMethods = {"modifyResource"}) public void testModifyResourceWithInvalidPat() throws Exception { showTitle("testModifyResourceWithInvalidPat"); UmaResourceResponse resourceStatus = null; try { UmaResource resource = new UmaResource(); resource.setName("Photo Album 4"); resource.setIconUri("http://www.example.com/icons/flower.png"); resource.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all")); resourceStatus = getResourceService().updateResource("Bearer " + pat.getAccessToken() + "_invalid", this.resourceId + "_invalid", resource); } catch (ClientResponseFailure ex) { System.err.println(ex.getResponse().getEntity(String.class)); assertEquals(ex.getResponse().getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "Unexpected response status"); } assertNull(resourceStatus, "Resource status is not null"); }
if (is == null) throw new ClientResponseFailure(Messages.MESSAGES.inputStreamEmpty(), this);