use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse 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);
}
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse 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.ServiceTunnelResponse 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.ServiceTunnelResponse in project scout.rt by eclipse.
the class ServiceTunnelServletCall method run.
@Override
public void run() {
try {
URL url = new URL(m_serverUrl + "/process");
final IServiceTunnelContentHandler contentHandler = BEANS.get(IServiceTunnelContentHandler.class);
contentHandler.initialize();
//
HttpRequestFactory requestFactory = BEANS.get(HttpServiceTunnelTransportManager.class).getHttpRequestFactory();
HttpRequest req = requestFactory.buildPostRequest(new GenericUrl(url), new HttpContent() {
@Override
public void writeTo(OutputStream out) throws IOException {
contentHandler.writeRequest(out, m_req);
}
@Override
public boolean retrySupported() {
return false;
}
@Override
public String getType() {
return null;
}
@Override
public long getLength() throws IOException {
return 0;
}
});
req.getHeaders().setAuthorization("Basic " + Base64Utility.encode("admin:manager".getBytes()));
HttpResponse resp = req.execute();
m_res = contentHandler.readResponse(resp.getContent());
} catch (Throwable e) {
m_res = new ServiceTunnelResponse(e);
}
}
use of org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse 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());
}
Aggregations