Search in sources :

Example 6 with SimpleResponse

use of org.openscoring.common.SimpleResponse in project openscoring by openscoring.

the class Undeployer method run.

@Override
public void run() throws Exception {
    SimpleResponse response = undeploy();
    String message = (response != null ? response.getMessage() : null);
    if (message != null) {
        logger.warn("Undeployment failed: {}", message);
        return;
    }
    logger.info("Undeployment succeeded");
}
Also used : SimpleResponse(org.openscoring.common.SimpleResponse)

Example 7 with SimpleResponse

use of org.openscoring.common.SimpleResponse in project openscoring by openscoring.

the class WebApplicationExceptionMapper method toResponse.

@Override
public Response toResponse(WebApplicationException exception) {
    Response response = exception.getResponse();
    Throwable throwable = exception;
    for (Throwable cause = throwable.getCause(); (cause != null && cause != throwable); throwable = cause) {
    // Empty block
    }
    String message = throwable.getMessage();
    if (message == null || ("").equals(message)) {
        Response.Status status = (Response.Status) response.getStatusInfo();
        message = status.getReasonPhrase();
    }
    // End if
    // Strip the HTTP status code prefix
    message = message.replaceFirst("HTTP\\s(\\d)+\\s", "");
    SimpleResponse entity = new SimpleResponse();
    entity.setMessage(message);
    return (Response.fromResponse(response).entity(entity).type(MediaType.APPLICATION_JSON)).build();
}
Also used : Response(javax.ws.rs.core.Response) SimpleResponse(org.openscoring.common.SimpleResponse) SimpleResponse(org.openscoring.common.SimpleResponse)

Example 8 with SimpleResponse

use of org.openscoring.common.SimpleResponse in project openscoring by openscoring.

the class CsvEvaluator method evaluate.

/**
 * @return <code>null</code> If the operation was successful.
 */
public SimpleResponse evaluate() throws Exception {
    Operation<SimpleResponse> operation = new Operation<SimpleResponse>() {

        @Override
        public SimpleResponse perform(WebTarget target) throws Exception {
            String delimiterChar = getDelimiterChar();
            String quoteChar = getQuoteChar();
            if (delimiterChar != null) {
                target = target.queryParam("delimiterChar", delimiterChar);
                if (quoteChar != null) {
                    target = target.queryParam("quoteChar", quoteChar);
                }
            }
            try (InputStream is = new FileInputStream(getInput())) {
                try (OutputStream os = new FileOutputStream(getOutput())) {
                    Invocation invocation = target.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).buildPost(Entity.text(is));
                    Response response = invocation.invoke();
                    Response.StatusType status = response.getStatusInfo();
                    switch(status.getFamily()) {
                        case CLIENT_ERROR:
                        case SERVER_ERROR:
                            return response.readEntity(SimpleResponse.class);
                        default:
                            break;
                    }
                    try (InputStream result = response.readEntity(InputStream.class)) {
                        ByteStreams.copy(result, os);
                        return null;
                    }
                }
            }
        }
    };
    return execute(operation);
}
Also used : SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SimpleResponse(org.openscoring.common.SimpleResponse) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) WebTarget(javax.ws.rs.client.WebTarget) FileInputStream(java.io.FileInputStream)

Example 9 with SimpleResponse

use of org.openscoring.common.SimpleResponse in project openscoring by openscoring.

the class ModelResourceTest method undeployForm.

private SimpleResponse undeployForm(String id) {
    Response response = target("model/" + id).request(MediaType.APPLICATION_JSON).header("X-HTTP-Method-Override", "DELETE").post(null);
    assertEquals(200, response.getStatus());
    return response.readEntity(SimpleResponse.class);
}
Also used : EvaluationResponse(org.openscoring.common.EvaluationResponse) BatchEvaluationResponse(org.openscoring.common.BatchEvaluationResponse) BatchModelResponse(org.openscoring.common.BatchModelResponse) ModelResponse(org.openscoring.common.ModelResponse) SimpleResponse(org.openscoring.common.SimpleResponse) Response(javax.ws.rs.core.Response)

Aggregations

SimpleResponse (org.openscoring.common.SimpleResponse)9 Response (javax.ws.rs.core.Response)6 Invocation (javax.ws.rs.client.Invocation)2 WebTarget (javax.ws.rs.client.WebTarget)2 BatchEvaluationResponse (org.openscoring.common.BatchEvaluationResponse)2 BatchModelResponse (org.openscoring.common.BatchModelResponse)2 EvaluationResponse (org.openscoring.common.EvaluationResponse)2 ModelResponse (org.openscoring.common.ModelResponse)2 Metric (com.codahale.metrics.Metric)1 MetricFilter (com.codahale.metrics.MetricFilter)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 DELETE (javax.ws.rs.DELETE)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1