Search in sources :

Example 1 with ServiceUtility

use of org.eclipse.scout.rt.shared.servicetunnel.ServiceUtility in project scout.rt by eclipse.

the class MockServiceTunnel method mockServiceCall.

/**
 * @return the service response You may call callTargetService() to simply call a service for test purpose (without a
 *         transaction!)
 */
protected ServiceTunnelResponse mockServiceCall(ServiceTunnelRequest req) throws Exception {
    try {
        ServiceUtility serviceUtility = BEANS.get(ServiceUtility.class);
        Class<?> serviceInterface = Class.forName(req.getServiceInterfaceClassName());
        Method serviceOperation = serviceUtility.getServiceOperation(serviceInterface, req.getOperation(), req.getParameterTypes());
        Object service = null;
        for (Object t : BEANS.all(serviceInterface)) {
            if (Proxy.isProxyClass(t.getClass())) {
                continue;
            }
            service = t;
            break;
        }
        Object result = serviceUtility.invoke(service, serviceOperation, req.getArgs());
        return new ServiceTunnelResponse(result, null, null);
    } catch (Throwable t) {
        return new ServiceTunnelResponse(null, null, t);
    }
}
Also used : Method(java.lang.reflect.Method) ServiceUtility(org.eclipse.scout.rt.shared.servicetunnel.ServiceUtility) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)

Example 2 with ServiceUtility

use of org.eclipse.scout.rt.shared.servicetunnel.ServiceUtility in project scout.rt by eclipse.

the class ServiceOperationInvoker method invokeInternal.

protected ServiceTunnelResponse invokeInternal(ServiceTunnelRequest serviceReq) throws ClassNotFoundException {
    IServerSession serverSession = ServerSessionProvider.currentSession();
    if (LOG.isDebugEnabled()) {
        String userId = serverSession != null ? serverSession.getUserId() : "";
        LOG.debug("started {}.{} by {} at {}", serviceReq.getServiceInterfaceClassName(), serviceReq.getOperation(), userId, new Date());
    }
    CallInspector callInspector = getCallInspector(serviceReq, serverSession);
    ServiceTunnelResponse serviceRes = null;
    try {
        ServiceUtility serviceUtility = BEANS.get(ServiceUtility.class);
        Class<?> serviceInterfaceClass = SerializationUtility.getClassLoader().loadClass(serviceReq.getServiceInterfaceClassName());
        Method serviceOp = serviceUtility.getServiceOperation(serviceInterfaceClass, serviceReq.getOperation(), serviceReq.getParameterTypes());
        Object[] args = serviceReq.getArgs();
        Object service = getValidatedServiceAccess(serviceInterfaceClass, serviceOp, args);
        Object data = serviceUtility.invoke(service, serviceOp, args);
        Object[] outParameters = serviceUtility.extractHolderArguments(args);
        serviceRes = new ServiceTunnelResponse(data, outParameters);
        return serviceRes;
    } finally {
        updateInspector(callInspector, serviceRes);
    }
}
Also used : CallInspector(org.eclipse.scout.rt.server.admin.inspector.CallInspector) Method(java.lang.reflect.Method) ServiceUtility(org.eclipse.scout.rt.shared.servicetunnel.ServiceUtility) Date(java.util.Date) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)

Aggregations

Method (java.lang.reflect.Method)2 ServiceTunnelResponse (org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)2 ServiceUtility (org.eclipse.scout.rt.shared.servicetunnel.ServiceUtility)2 Date (java.util.Date)1 CallInspector (org.eclipse.scout.rt.server.admin.inspector.CallInspector)1