Skip to content

Commit

Permalink
Fixes #2501
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 18, 2024
1 parent 61c0401 commit 39c318b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,12 @@ public static AtmosphereRequest wrap(HttpServletRequest request) {
String s;
while (e.hasMoreElements()) {
s = e.nextElement();
b.localAttributes.put(s, attributeWithoutException(request, s));
Object value = attributeWithoutException(request, s);
if (value != null) { // Check for null values
b.localAttributes.put(s, value);
} else {
logger.warn("Attribute {} is null", s);
}
}
return b.request(request).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@
*/
package org.atmosphere.cpr;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import org.atmosphere.container.BlockingIOCometSupport;
import org.atmosphere.handler.AbstractReflectorAtmosphereHandler;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
Expand Down Expand Up @@ -335,4 +339,17 @@ public void testForceContentType() throws Exception {
assertNull(request.getContentType());
}

@Test
public void testWrapMethodWithNullAttributeValue() throws IOException, ServletException {
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
when(mockRequest.getAttributeNames()).thenReturn(Collections.enumeration(Arrays.asList("org.eclipse.jetty.multipartConfig")));
when(mockRequest.getAttribute("org.eclipse.jetty.multipartConfig")).thenReturn(null);

AtmosphereRequest wrappedRequest = AtmosphereRequestImpl.wrap(mockRequest);

assertNotNull(wrappedRequest, "Wrapped request should not be null");
assertNull(wrappedRequest.getAttribute("org.eclipse.jetty.multipartConfig"), "Attribute value should be null");
}


}

0 comments on commit 39c318b

Please sign in to comment.