Search in sources :

Example 1 with ServiceTunnelRequest

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);
    }
}
Also used : FutureCancelledError(org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError) ServiceTunnelRequest(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) Method(java.lang.reflect.Method)

Example 2 with ServiceTunnelRequest

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;
        }
    };
}
Also used : IServiceTunnelContentHandler(org.eclipse.scout.rt.shared.servicetunnel.IServiceTunnelContentHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) ServiceTunnelRequest(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with ServiceTunnelRequest

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);
}
Also used : MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) IHttpTransportManager(org.eclipse.scout.rt.shared.http.IHttpTransportManager) ServiceTunnelRequest(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) IHttpTransportBuilder(org.eclipse.scout.rt.shared.http.IHttpTransportBuilder) Test(org.junit.Test)

Example 4 with ServiceTunnelRequest

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());
}
Also used : IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) ServiceTunnelRequest(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) Test(org.junit.Test)

Example 5 with ServiceTunnelRequest

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());
}
Also used : IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) ServiceTunnelRequest(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) Test(org.junit.Test)

Aggregations

ServiceTunnelRequest (org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest)6 ServiceTunnelResponse (org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse)4 IPingService (org.eclipse.scout.rt.shared.services.common.ping.IPingService)3 Test (org.junit.Test)3 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)1 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 FutureCancelledError (org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError)1 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)1 IHttpTransportBuilder (org.eclipse.scout.rt.shared.http.IHttpTransportBuilder)1 IHttpTransportManager (org.eclipse.scout.rt.shared.http.IHttpTransportManager)1 IServiceTunnelContentHandler (org.eclipse.scout.rt.shared.servicetunnel.IServiceTunnelContentHandler)1