Browse Source

Update test of setContentLengthLong to include param.

Otherwise useServlet31 was always returning false.

fixes gh-2196
pull/6/head
Spencer Gibb 7 years ago
parent
commit
c2aa60f292
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 7
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilter.java
  2. 5
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
  3. 6
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilterTests.java
  4. 40
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilterTests.java

7
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilter.java

@ -73,12 +73,17 @@ public class SendResponseFilter extends ZuulFilter { @@ -73,12 +73,17 @@ public class SendResponseFilter extends ZuulFilter {
super();
// To support Servlet API 3.1 we need to check if setContentLengthLong exists
try {
HttpServletResponse.class.getMethod("setContentLengthLong");
//TODO: remove in 2.0
HttpServletResponse.class.getMethod("setContentLengthLong", long.class);
} catch(NoSuchMethodException e) {
useServlet31 = false;
}
}
/* for testing */ boolean isUseServlet31() {
return useServlet31;
}
private ThreadLocal<byte[]> buffers = new ThreadLocal<byte[]>() {
@Override
protected byte[] initialValue() {

5
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java

@ -70,6 +70,7 @@ public class RibbonRoutingFilter extends ZuulFilter { @@ -70,6 +70,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
this.requestCustomizers = requestCustomizers;
// To support Servlet API 3.1 we need to check if getContentLengthLong exists
try {
//TODO: remove in 2.0
HttpServletRequest.class.getMethod("getContentLengthLong");
} catch(NoSuchMethodException e) {
useServlet31 = false;
@ -80,6 +81,10 @@ public class RibbonRoutingFilter extends ZuulFilter { @@ -80,6 +81,10 @@ public class RibbonRoutingFilter extends ZuulFilter {
this(new ProxyRequestHelper(), ribbonCommandFactory, null);
}
/* for testing */ boolean isUseServlet31() {
return useServlet31;
}
@Override
public String filterType() {
return ROUTE_TYPE;

6
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilterTests.java

@ -39,6 +39,7 @@ import com.netflix.zuul.constants.ZuulConstants; @@ -39,6 +39,7 @@ import com.netflix.zuul.constants.ZuulConstants;
import com.netflix.zuul.context.Debug;
import com.netflix.zuul.context.RequestContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@ -74,6 +75,11 @@ public class SendResponseFilterTests { @@ -74,6 +75,11 @@ public class SendResponseFilterTests {
runFilter(characterEncoding, content, false);
}
@Test
public void useServlet31Works() {
assertThat(new SendResponseFilter().isUseServlet31()).isTrue();
}
@Test
public void characterEncodingNotOverridden() throws Exception {
String characterEncoding = "UTF-16";

40
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilterTests.java

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
/*
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.springframework.cloud.netflix.zuul.filters.route;
import java.util.Collections;
import org.junit.Test;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* @author Spencer Gibb
*/
public class RibbonRoutingFilterTests {
@Test
public void useServlet31Works() {
RibbonCommandFactory factory = mock(RibbonCommandFactory.class);
RibbonRoutingFilter filter = new RibbonRoutingFilter(new ProxyRequestHelper(), factory,
Collections.<RibbonRequestCustomizer>emptyList());
assertThat(filter.isUseServlet31()).isTrue();
}
}
Loading…
Cancel
Save