use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilter method run.
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
this.helper.addIgnoredHeaders();
try {
RibbonCommandContext commandContext = buildCommandContext(context);
ClientHttpResponse response = forward(commandContext);
setResponse(response);
return response;
} catch (ZuulException ex) {
throw new ZuulRuntimeException(ex);
} catch (Exception ex) {
throw new ZuulRuntimeException(ex);
}
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class RestClientRibbonCommandTests method testNullEntity.
@Test
public void testNullEntity() throws Exception {
String uri = "http://example.com";
LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("my-header", "my-value");
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("myparam", "myparamval");
RestClientRibbonCommand command = new RestClientRibbonCommand("cmd", null, new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>()), zuulProperties);
HttpRequest request = command.createRequest();
assertThat("uri is wrong", request.getUri().toString(), startsWith(uri));
assertThat("my-header is wrong", request.getHttpHeaders().getFirstValue("my-header"), is(equalTo("my-value")));
assertThat("myparam is missing", request.getQueryParams().get("myparam").iterator().next(), is(equalTo("myparamval")));
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilterTests method testNullLoadBalancerKeyToRibbonCommandContext.
@Test
public void testNullLoadBalancerKeyToRibbonCommandContext() throws Exception {
requestContext.set(LOAD_BALANCER_KEY, null);
RibbonCommandContext commandContext = filter.buildCommandContext(requestContext);
assertThat(commandContext.getLoadBalancerKey()).isNull();
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testHystrixDefaultAndRibbonSetting.
@Test
public void testHystrixDefaultAndRibbonSetting() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 30);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ConnectTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.ReadTimeout", 1000);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetries", 1);
ConfigurationManager.getConfigInstance().setProperty("service.ribbon.MaxAutoRetriesNextServer", 2);
SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
ZuulProperties zuulProperties = new ZuulProperties();
RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
IClientConfig clientConfig = new DefaultClientConfigImpl();
clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(), eq(RibbonLoadBalancingHttpClient.class));
doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
assertEquals(30, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
use of org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext in project spring-cloud-netflix by spring-cloud.
the class HttpClientRibbonCommandFactoryTest method testHystrixTimeoutValue.
@Test
public void testHystrixTimeoutValue() throws Exception {
RibbonCommandContext context = mock(RibbonCommandContext.class);
doReturn("service").when(context).getServiceId();
HttpClientRibbonCommand ribbonCommand = this.ribbonCommandFactory.create(context);
assertEquals(4000, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
Aggregations