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);
}
}
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;
}
}
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));
}
}
Aggregations