Search in sources :

Example 1 with DefaultHttpCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse in project kie-wb-common by kiegroup.

the class RestUtils method readDefaultCompilationResponseFromBytes.

public static HttpCompilationResponse readDefaultCompilationResponseFromBytes(byte[] bytes) {
    ObjectInput in = null;
    ByteArrayOutputStream bos = null;
    try {
        in = new ObjectInputStream(new ByteArrayInputStream(bytes));
        Object newObj = in.readObject();
        return (HttpCompilationResponse) newObj;
    } catch (NotSerializableException nse) {
        logger.warn("Object is not serializable {}", nse.getMessage());
        StringBuilder sb = new StringBuilder("NotSerializableException:").append(nse.getMessage());
        logger.error(sb.toString());
    } catch (IOException ioe) {
        StringBuilder sb = new StringBuilder("IOException:").append(ioe.getMessage());
        logger.error(sb.toString());
    } catch (ClassNotFoundException cnfe) {
        StringBuilder sb = new StringBuilder("ClassNotFoundException:").append(cnfe.getMessage());
        logger.error(sb.toString());
    } catch (Exception e) {
        StringBuilder sb = new StringBuilder("Exception:").append(e.getMessage());
        logger.error(sb.toString());
    } finally {
        try {
            if (bos != null) {
                bos.close();
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            logger.error(ex.getMessage());
        }
    }
    return new DefaultHttpCompilationResponse(Boolean.FALSE);
}
Also used : NotSerializableException(java.io.NotSerializableException) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) DefaultHttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse) ObjectInput(java.io.ObjectInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with DefaultHttpCompilationResponse

use of org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse in project kie-wb-common by kiegroup.

the class MavenRestHandler method postAsync.

/**
 * Endpoint to ask an async build
 */
@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public void postAsync(@Suspended AsyncResponse ar, @HeaderParam("project") String projectRepo, @HeaderParam("mavenrepo") String mavenRepoPath, @HeaderParam("settings_xml") String settingsXmlPath) throws Exception {
    CompletableFuture<KieCompilationResponse> response = compilerService.build(projectRepo, mavenRepoPath, settingsXmlPath);
    response.whenCompleteAsync((kieCompilationResponse, throwable) -> {
        if (throwable != null) {
            logger.error(throwable.getMessage());
            ar.resume(Response.serverError().build());
        } else {
            byte[] bytes = RestUtils.serialize(new DefaultHttpCompilationResponse(kieCompilationResponse));
            ar.resume(Response.ok(bytes).build());
        }
    });
}
Also used : DefaultHttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse) KieCompilationResponse(org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

DefaultHttpCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.DefaultHttpCompilationResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 HttpCompilationResponse (org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse)1 KieCompilationResponse (org.kie.workbench.common.services.backend.compiler.impl.kie.KieCompilationResponse)1