Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public ServerInfoSupplier(String logName) {
public String get() {
// log server, port, app name, module name -- server:80/app/module
StringBuilder appInfo = new StringBuilder();
HttpServletRequest request = ESAPI.currentRequest();
if (request != null && logServerIP) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
if (logServerIP) {
HttpServletRequest request = ESAPI.currentRequest();
if (request != null) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
}
}
if (logAppName) {
appInfo.append("/").append(applicationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class ServerInfoSupplierTest {
private HttpServletRequest request;

@Before
public void buildStaticMocks() throws Exception {
public void buildStaticMocks() {
request = mock(HttpServletRequest.class);
mockStatic(ESAPI.class);
when(ESAPI.class, "currentRequest").thenReturn(request);
}

@Test
public void verifyFullOutput() {
public void verifyFullOutput() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand All @@ -57,7 +57,8 @@ public void verifyOutputNullRequest() throws Exception {
}

@Test
public void verifyOutputNoAppName() {
public void verifyOutputNoAppName() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand All @@ -70,7 +71,8 @@ public void verifyOutputNoAppName() {
}

@Test
public void verifyOutputNullAppName() {
public void verifyOutputNullAppName() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand Down