Skip to content

Commit

Permalink
Fixes #1732
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Oct 3, 2014
1 parent bf1a053 commit 334bb98
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ public Enumeration getHeaders(String name) {

if (isNotNoOps()) {
if (list.size() == 0 && name.startsWith(X_ATMOSPHERE)) {
if (b.request.getAttribute(name) != null) {
list.add(b.request.getAttribute(name));
if (attributeWithoutException(b.request, name) != null) {
list.add(attributeWithoutException(b.request, name));
}
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ public String getHeader(String s, boolean checkCase) {
if (s.startsWith(X_ATMOSPHERE) && isNotNoOps()) {
// Craziness with Struts 2 who wraps String attribute as BigDecimal
// https://github.com/Atmosphere/atmosphere/issues/1367
Object o = b.request.getAttribute(s);
Object o = attributeWithoutException(b.request, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = String.class.cast(o);
} else {
Expand All @@ -409,7 +409,7 @@ public String getHeader(String s, boolean checkCase) {
HttpServletRequest hsr = HttpServletRequestWrapper.class.cast(b.request);
while (hsr instanceof HttpServletRequestWrapper) {
hsr = (HttpServletRequest) ((HttpServletRequestWrapper) hsr).getRequest();
o = hsr.getAttribute(s);
o = attributeWithoutException(hsr, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = String.class.cast(o);
break;
Expand Down Expand Up @@ -717,7 +717,7 @@ public AsyncContext getAsyncContext() {
*/
@Override
public Object getAttribute(String s) {
return b.localAttributes.get(s) != null ? b.localAttributes.get(s) : (isNotNoOps() ? b.request.getAttribute(s) : null);
return b.localAttributes.get(s) != null ? b.localAttributes.get(s) : (isNotNoOps() ? attributeWithoutException(b.request, s) : null);
}

/**
Expand Down Expand Up @@ -1033,6 +1033,16 @@ public Enumeration<String> getAttributeNames() {
return Collections.enumeration(l);
}

private static Object attributeWithoutException(HttpServletRequest request, String attribute) {
try {
return request.getAttribute(attribute);
} catch(NullPointerException ex) {
// https://github.com/Atmosphere/atmosphere/issues/1732
logger.trace("Unexpected NPE", ex);
return "";
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1857,7 +1867,7 @@ public final static AtmosphereRequest wrap(HttpServletRequest request) {
String s;
while (e.hasMoreElements()) {
s = e.nextElement();
b.localAttributes.put(s, request.getAttribute(s));
b.localAttributes.put(s, attributeWithoutException(request, s));
}
return b.request(request).build();
}
Expand Down Expand Up @@ -1919,7 +1929,7 @@ public final static AtmosphereRequest cloneRequest(HttpServletRequest request, b
.isSSecure(request.isSecure());

if (loadInMemory) {
String s = (String) request.getAttribute(FrameworkConfig.THROW_EXCEPTION_ON_CLONED_REQUEST);
String s = (String) attributeWithoutException(request, FrameworkConfig.THROW_EXCEPTION_ON_CLONED_REQUEST);
boolean throwException = s != null && Boolean.parseBoolean(s);
r = new NoOpsRequest(throwException);
if (isWrapped) {
Expand All @@ -1944,7 +1954,7 @@ private static void load(HttpServletRequest request, Builder b) {
e = request.getAttributeNames();
while (e.hasMoreElements()) {
s = e.nextElement();
b.localAttributes.put(s, request.getAttribute(s));
b.localAttributes.put(s, attributeWithoutException(request, s));
}

e = request.getParameterNames();
Expand Down

0 comments on commit 334bb98

Please sign in to comment.