use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method httpCORSSpecificSimple.
@Test
public void httpCORSSpecificSimple() {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/v1/version");
req.headers().add(HttpHeaders.ORIGIN, "42.com");
handleHttpRpc(req, new Answer<ChannelFuture>() {
public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals("42.com", response.headers().get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
return null;
}
});
tsdb.getConfig().overrideConfig("tsd.http.request.cors_domains", "aurther.com,dent.net,42.com,beeblebrox.org");
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
rpc.messageReceived(ctx, message);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method httpOptionsCORSSpecific.
@Test
public void httpOptionsCORSSpecific() {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/api/v1/version");
req.headers().add(HttpHeaders.ORIGIN, "42.com");
handleHttpRpc(req, new Answer<ChannelFuture>() {
public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals("42.com", response.headers().get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
return null;
}
});
tsdb.getConfig().overrideConfig("tsd.http.request.cors_domains", "aurther.com,dent.net,42.com,beeblebrox.org");
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
rpc.messageReceived(ctx, message);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method httpOptionsCORSPublic.
@Test
public void httpOptionsCORSPublic() {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/api/v1/version");
req.headers().add(HttpHeaders.ORIGIN, "42.com");
handleHttpRpc(req, new Answer<ChannelFuture>() {
public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals("42.com", response.headers().get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
return null;
}
});
tsdb.getConfig().overrideConfig("tsd.http.request.cors_domains", "*");
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
rpc.messageReceived(ctx, message);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project bagheera by mozilla-metrics.
the class ContentLengthFilterTest method createMockEvent.
private MessageEvent createMockEvent(Channel channel, HttpVersion protocolVersion, HttpMethod method, String uri, byte[] contentBytes) {
MessageEvent event = createMock(UpstreamMessageEvent.class);
expect(event.getChannel()).andReturn(channel).anyTimes();
expect(event.getFuture()).andReturn(new DefaultChannelFuture(channel, false)).anyTimes();
expect(event.getRemoteAddress()).andReturn(remoteAddr);
HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
req.setChunked(false);
req.setContent(ChannelBuffers.copiedBuffer(contentBytes));
expect(event.getMessage()).andReturn(req);
replay(channel, event);
return event;
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.
the class AppFabricClient method getRuntimeArgs.
public Map<String, String> getRuntimeArgs(ProgramId programId) throws Exception {
DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s/%s/%s/runtimeargs", getNamespacePath(programId.getNamespace()), programId.getApplication(), programId.getType().getCategoryName(), programId.getProgram()));
request.setHeader(Constants.Gateway.API_KEY, "api-key-example");
MockResponder mockResponder = new MockResponder();
programLifecycleHttpHandler.getProgramRuntimeArgs(request, mockResponder, programId.getNamespace(), programId.getApplication(), programId.getType().getCategoryName(), programId.getProgram());
verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting runtime arguments failed");
return mockResponder.decodeResponseContent(MAP_TYPE);
}
Aggregations