use of org.eclipse.scout.rt.shared.servicetunnel.HttpException in project scout.rt by eclipse.
the class RemoteServiceInvocationCallable method call.
/**
* Invokes the remote service operation.
*
* @return {@link IServiceTunnelResponse}; is never <code>null</code>.
*/
@Override
public ServiceTunnelResponse call() throws Exception {
long nBytes = 0;
final long tStart = LOG.isDebugEnabled() ? System.nanoTime() : 0L;
try {
// Create the request.
final ByteArrayOutputStream requestMessage = new ByteArrayOutputStream();
m_tunnel.getContentHandler().writeRequest(requestMessage, m_serviceRequest);
requestMessage.close();
final byte[] requestData = requestMessage.toByteArray();
nBytes = requestData.length;
// Send the request to the server.
HttpResponse resp = m_tunnel.executeRequest(m_serviceRequest, requestData);
// Receive the response.
m_tunnel.interceptHttpResponse(resp, m_serviceRequest);
if (resp.getStatusCode() != 0 && (resp.getStatusCode() < 200 || resp.getStatusCode() > 299)) {
// request failed
return new ServiceTunnelResponse(new HttpException(resp.getStatusCode()));
}
try (InputStream in = resp.getContent()) {
return m_tunnel.getContentHandler().readResponse(in);
}
} catch (IOException e) {
if (Thread.currentThread().isInterrupted()) {
LOG.debug("Ignoring IOException for interrupted thread.", e);
return new ServiceTunnelResponse(new ThreadInterruptedError("Thread is interrupted.", e));
} else if (RunMonitor.CURRENT.get().isCancelled()) {
LOG.debug("Ignoring IOException for cancelled thread.", e);
return new ServiceTunnelResponse(new FutureCancelledError("RunMonitor is cancelled.", e));
}
throw e;
} finally {
if (LOG.isDebugEnabled()) {
final long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - tStart);
LOG.debug("TIME {}.{} {}ms {} bytes", m_serviceRequest.getServiceInterfaceClassName(), m_serviceRequest.getOperation(), elapsedMillis, nBytes);
}
}
}
Aggregations