Search in sources :

Example 1 with InvokeMethodRequest

use of fish.payara.ejb.http.protocol.InvokeMethodRequest in project Payara by payara.

the class ObjectStreamInvokeMethodMessageBodyReader method readFrom.

@Override
public InvokeMethodRequest readFrom(Class<InvokeMethodRequest> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    try {
        InvokeMethodRequest request = (InvokeMethodRequest) new ObjectInputStream(entityStream).readObject();
        request.argDeserializer = (args, method, types, classloader) -> {
            try (ObjectInputStream ois = new ClassLoaderObjectInputStream(classloader, new ByteArrayInputStream((byte[]) args))) {
                return (Object[]) ois.readObject();
            } catch (Exception ex) {
                throw new InternalServerErrorException("Failed to de-serialise method arguments from binary representation.", ex);
            }
        };
        return request;
    } catch (ClassNotFoundException ex) {
        throw new InternalServerErrorException("Class not found while de-serialising object stream as " + type.getSimpleName() + " : " + ex.getMessage(), ex);
    }
}
Also used : InvokeMethodRequest(fish.payara.ejb.http.protocol.InvokeMethodRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.apache.commons.io.input.ClassLoaderObjectInputStream)

Example 2 with InvokeMethodRequest

use of fish.payara.ejb.http.protocol.InvokeMethodRequest in project Payara by payara.

the class EjbOverHttpResourceTest method invokeExpectError.

private static ErrorResponse invokeExpectError(String mediaType, String jndiName, String method, String[] argTypes, Object argValues) {
    Entity<InvokeMethodRequest> entity = invokeBody(mediaType, jndiName, method, argTypes, argValues);
    try (Response response = target.path("jndi/invoke").request(mediaType).buildPost(entity).invoke()) {
        assertNotEquals(Status.OK.getStatusCode(), response.getStatus());
        if (mediaType.equals(response.getMediaType().toString())) {
            return response.readEntity(ErrorResponse.class);
        }
        fail("Unexpected error response in media type " + response.getMediaType() + ": " + response.readEntity(String.class));
        return null;
    }
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(fish.payara.ejb.http.protocol.ErrorResponse) LookupResponse(fish.payara.ejb.http.protocol.LookupResponse) InvokeMethodResponse(fish.payara.ejb.http.protocol.InvokeMethodResponse) InvokeMethodRequest(fish.payara.ejb.http.protocol.InvokeMethodRequest)

Example 3 with InvokeMethodRequest

use of fish.payara.ejb.http.protocol.InvokeMethodRequest in project Payara by payara.

the class JsonbInvokeMethodMessageBodyReader method readFrom.

@Override
public InvokeMethodRequest readFrom(Class<InvokeMethodRequest> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    try (JsonReader jsonReader = Json.createReader(entityStream)) {
        JsonObject json = jsonReader.readObject();
        String[] argTypeNames = json.getJsonArray("argTypes").stream().map(JsonbInvokeMethodMessageBodyReader::text).toArray(String[]::new);
        JsonArray actualTypes = json.getJsonArray("argActualTypes");
        String[] argActualTypeNames = actualTypes == null ? argTypeNames : actualTypes.stream().map(JsonbInvokeMethodMessageBodyReader::text).toArray(String[]::new);
        return new InvokeMethodRequest(json.getString("java.naming.security.principal", ""), json.getString("java.naming.security.credentials", ""), json.getString("lookup"), json.getString("method"), argTypeNames, argActualTypeNames, json.get("argValues"), (args, method, argActualTypes, classloader) -> toObjects(method, argActualTypes, args));
    }
}
Also used : JsonArray(javax.json.JsonArray) InvokeMethodRequest(fish.payara.ejb.http.protocol.InvokeMethodRequest) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString)

Aggregations

InvokeMethodRequest (fish.payara.ejb.http.protocol.InvokeMethodRequest)3 ErrorResponse (fish.payara.ejb.http.protocol.ErrorResponse)1 InvokeMethodResponse (fish.payara.ejb.http.protocol.InvokeMethodResponse)1 LookupResponse (fish.payara.ejb.http.protocol.LookupResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 JsonReader (javax.json.JsonReader)1 JsonString (javax.json.JsonString)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 ClassLoaderObjectInputStream (org.apache.commons.io.input.ClassLoaderObjectInputStream)1