use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest in project scout.rt by eclipse.
the class RemoteServiceInvocationCallable method cancel.
/**
* Cancels the remote service operation on server side.
*/
public void cancel() {
try {
final String sessionId = m_serviceRequest.getSessionId();
if (sessionId == null) {
// cannot cancel an event without session. The IRunMonitorCancelService requires a session.
return;
}
final Method serviceMethod = IRunMonitorCancelService.class.getMethod(IRunMonitorCancelService.CANCEL_METHOD, long.class);
final Object[] serviceArgs = new Object[] { m_serviceRequest.getRequestSequence() };
ServiceTunnelRequest request = m_tunnel.createRequest(IRunMonitorCancelService.class, serviceMethod, serviceArgs);
request.setClientNodeId(m_serviceRequest.getClientNodeId());
request.setSessionId(sessionId);
request.setUserAgent(m_serviceRequest.getUserAgent());
m_tunnel.invokeService(request);
} catch (final FutureCancelledError | ThreadInterruptedError e) {
// NOSONAR
// NOOP: Do not cancel 'cancel-request' to prevent loop.
} catch (RuntimeException | NoSuchMethodException e) {
LOG.warn("Failed to cancel server processing [requestSequence={}]", m_serviceRequest.getRequestSequence(), e);
}
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest in project scout.rt by eclipse.
the class HttpServiceTunnelTest method getTestContentHandler.
private IServiceTunnelContentHandler getTestContentHandler() {
return new IServiceTunnelContentHandler() {
@Override
public void writeResponse(OutputStream out, ServiceTunnelResponse msg) throws IOException {
}
@Override
public void writeRequest(OutputStream out, ServiceTunnelRequest msg) throws IOException {
}
@Override
public ServiceTunnelResponse readResponse(InputStream in) throws IOException, ClassNotFoundException {
ByteArrayInputStream bi = (ByteArrayInputStream) in;
ObjectInputStream in2 = new ObjectInputStream(bi);
Object o = in2.readObject();
return (ServiceTunnelResponse) o;
}
@Override
public ServiceTunnelRequest readRequest(InputStream in) throws IOException, ClassNotFoundException {
return null;
}
@Override
public void initialize() {
}
@Override
public String getContentType() {
return null;
}
};
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest in project scout.rt by eclipse.
the class HttpServiceTunnelTest method testTunnel.
@Test
public void testTunnel() throws IOException {
when(mockUrl.getValue()).thenReturn("http://localhost");
final MockLowLevelHttpResponse expectedResponse = new MockLowLevelHttpResponse().setContent(getInputStream(new ServiceTunnelResponse("testData", new Object[] {})));
HttpServiceTunnel tunnel = new HttpServiceTunnel() {
@Override
protected IHttpTransportManager getHttpTransportManager() {
return new IHttpTransportManager() {
private MockHttpTransport m_transport = new MockHttpTransport.Builder().setLowLevelHttpResponse(expectedResponse).build();
@Override
public HttpTransport getHttpTransport() {
return m_transport;
}
@Override
public HttpRequestFactory getHttpRequestFactory() {
return m_transport.createRequestFactory();
}
@Override
public void interceptNewHttpTransport(IHttpTransportBuilder builder) {
// nop
}
};
}
};
tunnel.setContentHandler(getTestContentHandler());
ServiceTunnelRequest request = new ServiceTunnelRequest("IPingService", "ping", null, null);
ServiceTunnelResponse response = tunnel.tunnel(request);
assertNotNull(response);
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest in project scout.rt by eclipse.
the class PiggyBackClientNotificationTest method testPiggyBack.
@Test
public void testPiggyBack() throws ServletException, IOException {
ServiceTunnelServlet s = new ServiceTunnelServlet();
Class[] parameterTypes = new Class[] { String.class };
Object[] args = new Object[] { "test" };
ServiceTunnelRequest req = new ServiceTunnelRequest(IPingService.class.getName(), "ping", parameterTypes, args);
req.setClientNodeId("testNodeId");
ServiceTunnelResponse res = s.doPost(req);
assertEquals("pong", res.getData());
assertNull(res.getException());
assertEquals(1, res.getNotifications().size());
assertEquals("testNotification", res.getNotifications().get(0).getNotification());
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest in project scout.rt by eclipse.
the class ServiceTunnelServletTest method testPostSuccessful.
@Test
public void testPostSuccessful() throws ServletException, IOException {
ServiceTunnelServlet s = new ServiceTunnelServlet();
Class[] parameterTypes = new Class[] { String.class };
Object[] args = new Object[] { "test" };
ServiceTunnelRequest req = new ServiceTunnelRequest(IPingService.class.getName(), "ping", parameterTypes, args);
ServiceTunnelResponse res = s.doPost(req);
assertEquals("test", res.getData());
assertNull(res.getException());
assertEquals(0, res.getNotifications().size());
}
Aggregations