use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse in project scout.rt by eclipse.
the class ServiceOperationInvokerTest method testInvokeWithSession.
@Test
public void testInvokeWithSession() {
when(m_pingSvc.ping(any(String.class))).thenReturn(m_testData);
ServiceTunnelResponse res = invokePingService(createRunContextWithSession());
assertValidResponse(res, m_testData);
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse in project scout.rt by eclipse.
the class ServiceOperationInvoker method invoke.
/**
* Invoke the service associated with the {@link ServiceTunnelRequest}. <br>
* Must be called within a transaction.
*/
@SuppressWarnings("squid:S1193")
public ServiceTunnelResponse invoke(final RunContext runContext, final ServiceTunnelRequest serviceReq) {
final long t0 = System.nanoTime();
ServiceTunnelResponse response;
try {
response = runContext.call(new Callable<ServiceTunnelResponse>() {
@Override
public ServiceTunnelResponse call() throws Exception {
return invokeInternal(serviceReq);
}
}, DefaultExceptionTranslator.class);
} catch (Exception e) {
// Associate the exception with context information about the service call.
if (e instanceof PlatformException) {
((PlatformException) e).withContextInfo("service.name", serviceReq.getServiceInterfaceClassName()).withContextInfo("service.operation", serviceReq.getOperation());
}
// Handle the exception.
handleException(e);
// Prepare ServiceTunnelResponse.
response = new ServiceTunnelResponse(interceptException(e));
}
response.setProcessingDuration(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t0));
LOG.debug("TIME {}.{} {}ms", serviceReq.getServiceInterfaceClassName(), serviceReq.getOperation(), response.getProcessingDuration());
return response;
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse 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);
}
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse in project scout.rt by eclipse.
the class ServiceTunnelServlet method doPost.
protected ServiceTunnelResponse doPost(ServiceTunnelRequest serviceRequest) throws ServletException {
ClientNotificationCollector collector = new ClientNotificationCollector();
ServerRunContext serverRunContext = ServerRunContexts.copyCurrent().withLocale(serviceRequest.getLocale()).withUserAgent(UserAgents.createByIdentifier(serviceRequest.getUserAgent())).withClientNotificationCollector(collector).withClientNodeId(serviceRequest.getClientNodeId());
if (serviceRequest.getSessionId() != null) {
serverRunContext.withSession(lookupServerSessionOnHttpSession(serviceRequest.getSessionId(), serverRunContext));
}
final IRegistrationHandle registrationHandle = registerForCancellation(serverRunContext, serviceRequest);
try {
ServiceTunnelResponse serviceResponse = invokeService(serverRunContext, serviceRequest);
// include client notifications in response (piggyback)
serviceResponse.setNotifications(collector.consume());
return serviceResponse;
} finally {
registrationHandle.unregister();
}
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse in project scout.rt by eclipse.
the class HttpServiceTunnel method tunnel.
@Override
protected ServiceTunnelResponse tunnel(final ServiceTunnelRequest serviceRequest) {
final long requestSequence = serviceRequest.getRequestSequence();
// Create the Callable to be given to the job manager for execution.
final RemoteServiceInvocationCallable remoteInvocationCallable = createRemoteServiceInvocationCallable(serviceRequest);
// Register the execution monitor as child monitor of the current monitor so that the service request is cancelled once the current monitor gets cancelled.
// Invoke the service operation asynchronously (to enable cancellation) and wait until completed or cancelled.
final IFuture<ServiceTunnelResponse> future = Jobs.schedule(remoteInvocationCallable, Jobs.newInput().withRunContext(RunContext.CURRENT.get().copy()).withName(createServiceRequestName(requestSequence)).withExceptionHandling(null, // do not handle uncaught exceptions because typically invoked from within a model job (might cause a deadlock, because ClientExceptionHandler schedules and waits for a model job to visualize the exception).
false)).whenDone(new IDoneHandler<ServiceTunnelResponse>() {
@Override
public void onDone(DoneEvent<ServiceTunnelResponse> event) {
if (event.isCancelled()) {
remoteInvocationCallable.cancel();
}
}
}, RunContext.CURRENT.get().copy().withRunMonitor(// separate monitor to not cancel this cancellation action.
BEANS.get(RunMonitor.class)));
try {
return future.awaitDoneAndGet();
} catch (ThreadInterruptedError e) {
// NOSONAR
// Ensure the monitor to be cancelled once this thread is interrupted to cancel the remote call.
future.cancel(true);
// Interruption has precedence over computation result or computation error.
return new ServiceTunnelResponse(new ThreadInterruptedError(TEXTS.get("UserInterrupted")));
} catch (FutureCancelledError e) {
// Cancellation has precedence over computation result or computation error.
return new ServiceTunnelResponse(new FutureCancelledError(TEXTS.get("UserInterrupted")));
}
}
Aggregations