@Override public String toString() { return getStatus().toString(); }
/** * Asks the resource to delete itself and all its representations.The * default behavior is to invoke the {@link #removeRepresentations()} * method. * * @deprecated Use the {@link #removeRepresentations()} method instead. */ @Deprecated public void delete() { try { removeRepresentations(); } catch (ResourceException re) { getResponse().setStatus(re.getStatus(), re); } }
/** * Posts a representation to the resource. The default behavior is to invoke * the {@link #acceptRepresentation(Representation)} method. * * @param entity * The representation posted. * @deprecated Use the {@link #acceptRepresentation(Representation)} method * instead. */ @Deprecated public void post(Representation entity) { try { acceptRepresentation(entity); } catch (ResourceException re) { getResponse().setStatus(re.getStatus(), re); } }
/** * Puts a representation in the resource. The default behavior is to invoke * the {@link #storeRepresentation(Representation)} method. * * @param entity * The representation put. * @deprecated Use the {@link #storeRepresentation(Representation)} method * instead. */ @Deprecated public void put(Representation entity) { try { storeRepresentation(entity); } catch (ResourceException re) { getResponse().setStatus(re.getStatus(), re); } }
/** * Returns the preferred representation according to the client preferences * specified in the request. * * @return The preferred representation. * @deprecated Use the {@link #represent()} method instead. * @see #getPreferredVariant() */ @Deprecated public Representation getPreferredRepresentation() { Representation result = null; try { result = represent(); } catch (ResourceException re) { getResponse().setStatus(re.getStatus(), re); } return result; }
/** * Send user activation request for specified username * @param username username * @return ClientResource result */ protected ClientResource sendActivationRequest(String username){ String url = activationUrl + "?username=" + username; ClientResource clientResource = createClientResource(url, false); addCredentialsIfAny(clientResource); writeRequestInfoToLog(clientResource); try { clientResource.get(); } catch (ResourceException e) { logger.warn("Poulpe activation request error: {}", e.getStatus()); } return clientResource; }
@Override public void removeRepresentations() throws ResourceException { try { super.removeRepresentations(); } catch ( ResourceException e ) { if ( Status.isServerError( e.getStatus().getCode() ) ) { handleError( e ); } throw e; } catch ( RuntimeException e ) { handleError( e ); throw e; } }
@Override public void acceptRepresentation( Representation representation ) throws ResourceException { try { super.acceptRepresentation( representation ); } catch ( ResourceException e ) { if ( Status.isServerError( e.getStatus().getCode() ) ) { handleError( e ); } throw e; } catch ( RuntimeException e ) { handleError( e ); throw e; } }
@Override public void storeRepresentation( Representation representation ) throws ResourceException { try { super.storeRepresentation( representation ); } catch ( ResourceException e ) { if ( Status.isServerError( e.getStatus().getCode() ) ) { handleError( e ); } throw e; } catch ( RuntimeException e ) { handleError( e ); throw e; } }
@Override public void removeRepresentations() throws ResourceException { try { super.removeRepresentations(); } catch (ResourceException e) { if (Status.isServerError(e.getStatus().getCode())) { handleError(e); } throw e; } catch (RuntimeException e) { handleError(e); throw e; } }
@Override public void acceptRepresentation(Representation representation) throws ResourceException { try { super.acceptRepresentation(representation); } catch (ResourceException e) { if (Status.isServerError(e.getStatus().getCode())) { handleError(e); } throw e; } catch (RuntimeException e) { handleError(e); throw e; } }
@Test public void testGetWhoAmIUnauthenticated() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_WHOAMI_PATH, OasProps.DEF_WHOAMI_PATH))); try { creationClientResource.get(); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogUnauthenticatedTurtle() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { creationClientResource.get(MediaType.APPLICATION_RDF_TURTLE); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogUnauthenticatedHtml() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { creationClientResource.get(MediaType.TEXT_HTML); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogAuthenticatedNonAdminHtml() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, MediaType.TEXT_HTML, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogAuthenticatedNonAdminRdfXml() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, MediaType.APPLICATION_RDF_XML, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogAuthenticatedNonAdminTurtle() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, MediaType.APPLICATION_RDF_TURTLE, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogUnauthenticatedRdfJson() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { creationClientResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogUnauthenticatedRdfXml() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { creationClientResource.get(MediaType.APPLICATION_RDF_XML); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
@Test public void testGetAuditLogAuthenticatedNonAdminRdfJson() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, RestletUtilMediaType.APPLICATION_RDF_JSON, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }