use of fish.payara.ejb.http.protocol.InvokeMethodResponse in project Payara by payara.
the class EjbOverHttpResource method doInvoke.
private Object doInvoke(InvokeMethodRequest request, BiFunction<Type, InvokeMethodResponse, Object> resultMapper) throws Exception {
return excuteInAppContext(request.jndiName, ejb -> {
// resource will not be changed.
if (!request.principal.isEmpty()) {
new ProgrammaticLogin().login(base64Decode(request.principal), base64Decode(request.credentials), null, true);
}
Class<?>[] argTypes = toClasses(request.argTypes);
Class<?>[] argActualTypes = toClasses(request.argActualTypes);
Method method = findBusinessMethodDeclaration(ejb, request.method, argTypes);
Object result = method.invoke(ejb, request.argDeserializer.deserialise(request.argValues, method, argActualTypes, Thread.currentThread().getContextClassLoader()));
return resultMapper.apply(method.getGenericReturnType(), new InvokeMethodResponse(result));
});
}
use of fish.payara.ejb.http.protocol.InvokeMethodResponse in project Payara by payara.
the class EjbOverHttpResourceTest method invoke_SuccessWithComplexResult.
@Test
public void invoke_SuccessWithComplexResult() {
InvokeMethodResponse response = invokeExpectSuccess(mediaType, EJB_NAME, "getSettings", new String[0], pack(new Object[0]));
@SuppressWarnings("unchecked") Map<String, Object> settings = (Map<String, Object>) response.result;
if (isJavaObjectSerialisation()) {
assertSame(UUID.class, settings.get("uuid").getClass());
} else {
// this shows that JSONB is not capable of preserving the UUID while java serialisation is
assertSame(String.class, settings.get("uuid").getClass());
}
@SuppressWarnings("unchecked") List<Object> list = (List<Object>) settings.get("list");
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(42, ((Number) list.get(0)).intValue());
}
use of fish.payara.ejb.http.protocol.InvokeMethodResponse in project Payara by payara.
the class EjbOverHttpResourceTest method invoke_SuccessWithArguments.
@Test
public void invoke_SuccessWithArguments() {
InvokeMethodResponse response = invokeExpectSuccess(mediaType, EJB_NAME, "add", new String[] { int.class.getName(), int.class.getName() }, pack(1, 2));
assertEquals("Actual type should be wrapper of int", Integer.class.getName(), response.type);
assertEquals(3, response.result);
}
use of fish.payara.ejb.http.protocol.InvokeMethodResponse in project Payara by payara.
the class EjbOverHttpResourceTest method invoke_CyclicResult.
@Test
public void invoke_CyclicResult() {
if (isJavaObjectSerialisation()) {
InvokeMethodResponse response = invokeExpectSuccess(mediaType, EJB_NAME, "cyclic", new String[0], pack(new Object[0]));
@SuppressWarnings("unchecked") List<Object> result = (List<Object>) response.result;
assertEquals(1, result.size());
assertSame(result, result.get(0));
} else {
ErrorResponse response = invokeExpectError(mediaType, EJB_NAME, "cyclic", new String[0], pack(new Object[0]));
assertEquals("java.lang.StackOverflowError", response.exceptionType);
}
}
Aggregations