Skip to content

Commit

Permalink
Merge 457f080 into 92d21db
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0092 committed Dec 12, 2017
2 parents 92d21db + 457f080 commit 7084943
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public Object getValue(HttpServletRequest request) throws Exception {

@Override
public void setValue(RestClientRequest clientRequest, Object arg) throws Exception {
if (null == arg) {
// null header should not be set to clientRequest to avoid NullPointerException in Netty.
return;
}
clientRequest.putHeader(paramPath, RestObjectMapper.INSTANCE.convertToString(arg));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public void testSetValue() throws Exception {
Assert.assertEquals("h1v", headers.get("h1"));
}

@Test
public void testSetValueNull() throws Exception {
createClientRequest();
HeaderProcessor processor = createProcessor("h1", String.class);
processor.setValue(clientRequest, null);
Assert.assertEquals(0, headers.size());
}

@Test
public void testSetValueDate() throws Exception {
Date date = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void beforeSendRequest(Invocation invocation, HttpServletRequestEx reques

httpHeaders.forEach((key, values) -> {
for (String value : values) {
// null args should not be set to requestEx to avoid NullPointerException in Netty.
if (null == value) {
continue;
}
requestEx.addHeader(key, value);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ public void beforeSendRequestNoHeader(@Mocked Invocation invocation) {
Assert.assertFalse(requestEx.getHeaderNames().hasMoreElements());
}

@Test
public void beforeSendRequestWithNullHeader(@Mocked Invocation invocation) {
Map<String, Object> context = new HashMap<>(1);
HttpHeaders httpHeaders = new HttpHeaders();
context.put(RestConst.CONSUMER_HEADER, httpHeaders);
httpHeaders.add("headerName0", "headerValue0");
httpHeaders.add("headerName1", null);
httpHeaders.add("headerName2", "headerValue2");
new Expectations() {
{
invocation.getHandlerContext();
result = context;
}
};

HttpServletRequestEx requestEx = new CommonToHttpServletRequest(null, null, new HttpHeaders(), null, false);
filter.beforeSendRequest(invocation, requestEx);
Assert.assertEquals("headerValue0", requestEx.getHeader("headerName0"));
Assert.assertEquals("headerValue2", requestEx.getHeader("headerName2"));
Assert.assertNull(requestEx.getHeader("headerName1"));
}

@Test
public void beforeSendRequestHaveHeader(@Mocked Invocation invocation) {
HttpHeaders httpHeaders = new HttpHeaders();
Expand Down

0 comments on commit 7084943

Please sign in to comment.