Search in sources :

Example 1 with MinijaxUriInfo

use of org.minijax.rs.MinijaxUriInfo in project minijax by minijax.

the class Connection method process.

private void process() throws IOException {
    final MinijaxApplication application = minijax.getDefaultApplication();
    try (final MinijaxNioRequestContext ctx = new MinijaxNioRequestContext(application, method, new MinijaxUriInfo(uri), new MinijaxNioHttpHeaders(requestHeaders), requestEntityStream)) {
        response = application.handle(ctx);
        if (onlyHeader) {
            bufferedOutputStream = null;
        } else {
            bufferedOutputStream = new ByteArrayOutputStream();
            EntityUtils.writeEntity(response.getEntity(), response.getMediaType(), ctx.getProviders(), bufferedOutputStream);
        }
    }
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MinijaxUriInfo(org.minijax.rs.MinijaxUriInfo)

Example 2 with MinijaxUriInfo

use of org.minijax.rs.MinijaxUriInfo in project minijax by minijax.

the class MinijaxTestInvocationBuilder method method.

@Override
public Response method(final String name) {
    final Minijax container = target.getServer();
    final MinijaxApplication application = container.getApplication(target.getUri());
    final MinijaxUriInfo uriInfo = new MinijaxUriInfo(target.getUri());
    if (!cookies.isEmpty()) {
        headers.add("Cookie", cookies.values().stream().map(c -> c.getName() + "=" + c.getValue()).collect(Collectors.joining("; ")));
    }
    try (final MinijaxRequestContext clientContext = new MinijaxTestRequestContext(application, name, uriInfo);
        final InputStream entityStream = EntityUtils.writeEntity(entity, clientContext.getProviders());
        final MinijaxRequestContext serverContext = new MinijaxTestRequestContext(application, name, new MinijaxUriInfo(target.getUri()), new MinijaxTestHttpHeaders(headers), entityStream)) {
        return application.handle(serverContext);
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) InputStream(java.io.InputStream) IOException(java.io.IOException) MinijaxUriInfo(org.minijax.rs.MinijaxUriInfo)

Aggregations

MinijaxApplication (org.minijax.rs.MinijaxApplication)2 MinijaxUriInfo (org.minijax.rs.MinijaxUriInfo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Minijax (org.minijax.Minijax)1 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)1