protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
protected <T> T getAPI(final Class<T> apiClass) { ensureSessionExists(); try { final ClientInterceptor clientInterceptor = new ClientInterceptor(apiClass.getName(), getServerAPI(), session); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, clientInterceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
/** * This methods serves the purpose to remove confusion between getAPI() when a session is mandatory, and this one, where no session is needed to access the * API class. * * @param apiClass the API to retrieve * @param <T> The type of the API, extending {@link org.bonitasoft.engine.api.LoginAPI} * @return the retrieved API * @throws IllegalStateException if the API cannot be retrieved. */ protected <T extends LoginAPI> T getLoginAPI(Class<T> apiClass) { try { final ClientInterceptor interceptor = new ClientInterceptor(apiClass.getName(), getServerAPI()); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, interceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
/** * This methods serves the purpose to remove confusion between getAPI() when a session is mandatory, and this one, where no session is needed to access the * API class. * * @param apiClass the API to retrieve * @param <T> The type of the API, extending {@link org.bonitasoft.engine.api.LoginAPI} * @return the retrieved API * @throws IllegalStateException if the API cannot be retrieved. */ protected <T extends LoginAPI> T getLoginAPI(Class<T> apiClass) { try { final ClientInterceptor interceptor = new ClientInterceptor(apiClass.getName(), getServerAPI()); @SuppressWarnings("unchecked") final T api = (T) Proxy.newProxyInstance(APIAccessor.class.getClassLoader(), new Class[] { apiClass }, interceptor); return api; } catch (ServerAPIException | UnknownAPITypeException e) { throw new IllegalStateException(e.getMessage(), e); } }
@Before public void before() throws IOException, BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException, ServerWrappedException { doReturn(server).when(client).getServerAPI(); doReturn(session).when(server).invokeMethod(anyMap(), eq("org.bonitasoft.engine.api.LoginAPI"), eq("login"), anyList(), eq(new Object[] { VALID_USERNAME, VALID_PASSWORD })); }