/** * Constructor. * * @param status * The status to associate. * @param cause * The wrapped cause error or exception. */ public ResourceException(Status status, Throwable cause, Resource resource) { super((status == null) ? null : status.toString(), cause); this.status = status; this.resource = resource; }
public NotSuccessException(Status status) { super(status.toString()); this.status = status; }
@Override protected void describeMismatchSafely(Status status, Description mismatchDescription) { mismatchDescription.appendText("was ").appendText(status.toString()); } }
@Override protected void describeMismatchSafely( Status status, Description mismatchDescription ) { mismatchDescription.appendText( "was " ).appendText( status.toString() ); } }
@Override public String toString() { return getStatus().toString(); }
@Override public Representation getRepresentation(Status status, Request request, Response response) { StringBuilder sb = new StringBuilder(); Throwable throwable = status.getThrowable(); if (throwable != null) { sb.append(throwable.getMessage()); return new StringRepresentation(String.format("Http Status = %s\n + Error = %s", new Object[]{status.toString(), sb.toString()})); } else { return new StringRepresentation(String.format("Http Status = %s", new Object[]{status.toString()})); } }
/** * Holds execution until all tasks of a given type stop running * * @param taskType task type * @param maxAttempts how many times check for tasks being stopped */ public void waitForAllTasksToStop( int maxAttempts, String taskType ) throws Exception { String uri = "service/local/taskhelper?attempts=" + maxAttempts; if ( taskType != null ) { uri += "&taskType=" + taskType; } final Status status = nexusRestClient.doGetForStatus( uri ); if ( !status.isSuccess() ) { throw new IOException( "The taskhelper REST resource reported an error (" + status.toString() + "), bailing out!" ); } }
/** * Hold execution until asynchronous events at nexus side stop running */ public void waitForCalmPeriod(final long waitMillis) throws IOException, InterruptedException { Thread.yield(); if (waitMillis > 0) { Thread.sleep(waitMillis); } final Status status = nexusRestClient.doGetForStatus("service/local/eventInspectors/isCalmPeriod?waitForCalm=true"); if (status.getCode() != Status.SUCCESS_OK.getCode()) { throw new IOException("The isCalmPeriod REST resource reported an error (" + status.toString() + "), bailing out!"); } }
/** * Holds execution until all tasks of a given type stop running * * @param taskType task type * @param maxAttempts how many times check for tasks being stopped */ public void waitForAllTasksToStop(int maxAttempts, String taskType) throws Exception { String uri = "service/local/taskhelper?attempts=" + maxAttempts; if (taskType != null) { uri += "&taskType=" + taskType; } final Status status = nexusRestClient.doGetForStatus(uri); if (!status.isSuccess()) { throw new IOException("The taskhelper REST resource reported an error (" + status.toString() + "), bailing out!"); } }
/** * Hold execution until asynchronous events at nexus side stop running */ public void waitForCalmPeriod( final long waitMillis ) throws IOException, InterruptedException { Thread.yield(); if ( waitMillis > 0 ) { Thread.sleep( waitMillis ); } final Status status = nexusRestClient.doGetForStatus( "service/local/eventInspectors/isCalmPeriod?waitForCalm=true" ); if ( status.getCode() != Status.SUCCESS_OK.getCode() ) { throw new IOException( "The isCalmPeriod REST resource reported an error (" + status.toString() + "), bailing out!" ); } }
public Error(Status status) { this.httpcode = status.getCode(); this.message = status.toString(); this.description = status.getDescription(); if (status.getThrowable() != null) { Throwable t = status.getThrowable(); if (t instanceof OntopiaRestException) { code = ((OntopiaRestException) t).getOntopiaCode(); } Set<String> c = new HashSet<>(); while (t.getCause() != null) { t = t.getCause(); c.add(t.getClass().getName() + ": " + (t.getMessage() != null ? t.getMessage() : "")); } if (!c.isEmpty()) { causes = c.toArray(causes); } } }
@Override protected void describeMismatchSafely(Response item, Description mismatchDescription) { mismatchDescription.appendText(item.getStatus().toString()); // provide some more info if it's validation error if (item.getStatus().getCode() == 400) { try { mismatchDescription.appendText(item.getEntity().getText()); } catch (IOException e) { mismatchDescription.appendText("response entity could not be converted to text: " + e.getMessage()); } } } }
public static void log(String loggerName, String level, String message, String exceptionType, String exceptionMessage) throws Exception { String uri = ""; if (loggerName != null) { uri += "&loggerName=" + loggerName; } if (level != null) { uri += "&level=" + level; } if (message != null) { uri += "&message=" + message; } if (exceptionType != null) { uri += "&exceptionType=" + exceptionType; } if (exceptionMessage != null) { uri += "&exceptionMessage=" + exceptionMessage; } if (!uri.equals("")) { uri = uri.substring(1); } uri = BASE_URI + "?" + uri; final Status status = RequestFacade.doGetForStatus(uri); if (!status.isSuccess()) { throw new IOException("The loghelper REST resource reported an error (" + status.toString() + "), bailing out!"); } }
public static StatusResourceResponse getNexusStatus() throws IOException { Response response = RequestFacade.doGetRequest( "service/local/status" ); if ( !response.getStatus().isSuccess() ) { throw new ConnectException( response.getStatus().toString() ); } XStream xstream = XStreamFactory.getXmlXStream(); String entityText = response.getEntity().getText(); Assert.assertNotNull( "Invalid server response: " + new XStream().toXML( response ), entityText ); StatusResourceResponse status = (StatusResourceResponse) xstream.fromXML( entityText ); return status; }
@Override protected void describeMismatchSafely( Response item, Description mismatchDescription ) { mismatchDescription.appendText( item.getStatus().toString() ); // provide some more info if it's validation error if ( item.getStatus().getCode() == 400 ) { try { mismatchDescription.appendText( item.getEntity().getText() ); } catch ( IOException e ) { mismatchDescription.appendText( "response entity could not be converted to text: " + e.getMessage() ); } } } }
public void waitForTask(String name, int maxAttempts, boolean failIfNotFinished) throws Exception { if (maxAttempts == 0) { return; } String uri = "service/local/taskhelper?attempts=" + maxAttempts; if (name != null) { uri += "&name=" + name; } final Status status = nexusRestClient.doGetForStatus(uri); if (failIfNotFinished) { if (Status.SUCCESS_NO_CONTENT.equals(status)) { throw new IOException("The taskhelper REST resource reported that task named '" + name + "' still running after '" + maxAttempts + "' cycles! This may indicate a performance issue."); } } else { if (!status.isSuccess()) { throw new IOException("The taskhelper REST resource reported an error (" + status.toString() + "), bailing out!"); } } }
public void waitForTask( String name, int maxAttempts, boolean failIfNotFinished ) throws Exception { if ( maxAttempts == 0 ) { return; } String uri = "service/local/taskhelper?attempts=" + maxAttempts; if ( name != null ) { uri += "&name=" + name; } final Status status = nexusRestClient.doGetForStatus( uri ); if ( failIfNotFinished ) { if ( Status.SUCCESS_NO_CONTENT.equals( status ) ) { throw new IOException( "The taskhelper REST resource reported that task named '" + name + "' still running after '" + maxAttempts + "' cycles! This may indicate a performance issue." ); } } else { if ( !status.isSuccess() ) { throw new IOException( "The taskhelper REST resource reported an error (" + status.toString() + "), bailing out!" ); } } }
/** * Gets authentication result from response entity. * * @param clientResource response container * @return map with user details * @throws org.jtalks.jcommune.plugin.api.exceptions.NoConnectionException * */ private Map<String, String> getAuthResult(ClientResource clientResource) throws NoConnectionException, JAXBException, IOException { if (clientResource.getStatus().getCode() == Status.SUCCESS_OK.getCode() && clientResource.getResponseEntity() != null) { return parseUserDetails(clientResource.getResponseEntity()); } else if (clientResource.getStatus().getCode() == Status.CLIENT_ERROR_NOT_FOUND.getCode()) { return Collections.emptyMap(); } else { throw new NoConnectionException(clientResource.getStatus().toString()); } }
/** * Gets errors from response if request wasn't successful, otherwise return null. * * @param clientResource response container * @param locale locale * @return errors * @throws org.jtalks.jcommune.plugin.api.exceptions.NoConnectionException * * @throws java.io.IOException */ private Map<String, String> getRegistrationResult(ClientResource clientResource, Locale locale) throws NoConnectionException, IOException, JAXBException, UnexpectedErrorException { if (clientResource.getStatus().getCode() == Status.SUCCESS_OK.getCode() && clientResource.getResponseEntity() != null) { return Collections.emptyMap(); } else if (clientResource.getStatus().getCode() == Status.CLIENT_ERROR_BAD_REQUEST.getCode()) { return parseErrors(clientResource.getResponseEntity(), locale); } else if (clientResource.getStatus().getCode() == Status.SERVER_ERROR_INTERNAL.getCode()) { throw new UnexpectedErrorException(); } else { throw new NoConnectionException(clientResource.getStatus().toString()); } }