use of javax.servlet.ServletRequestAttributeEvent in project jetty.project by eclipse.
the class Request method setAttribute.
/* ------------------------------------------------------------ */
/*
* Set a request attribute. if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then the value is also passed in a call to
* {@link #setQueryEncoding}.
*
* @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
*/
@Override
public void setAttribute(String name, Object value) {
Object old_value = _attributes == null ? null : _attributes.getAttribute(name);
if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name))
setQueryEncoding(value == null ? null : value.toString());
else if ("org.eclipse.jetty.server.sendContent".equals(name))
LOG.warn("Deprecated: org.eclipse.jetty.server.sendContent");
if (_attributes == null)
_attributes = new AttributesMap();
_attributes.setAttribute(name, value);
if (!_requestAttributeListeners.isEmpty()) {
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context, this, name, old_value == null ? value : old_value);
for (ServletRequestAttributeListener l : _requestAttributeListeners) {
if (old_value == null)
l.attributeAdded(event);
else if (value == null)
l.attributeRemoved(event);
else
l.attributeReplaced(event);
}
}
}
use of javax.servlet.ServletRequestAttributeEvent in project felix by apache.
the class ServletRequestWrapper method setAttribute.
@Override
public void setAttribute(final String name, final Object value) {
if (value == null) {
this.removeAttribute(name);
}
final Object oldValue = this.getAttribute(name);
super.setAttribute(name, value);
if (this.servletContext.getServletRequestAttributeListener() != null) {
if (oldValue == null) {
this.servletContext.getServletRequestAttributeListener().attributeAdded(new ServletRequestAttributeEvent(this.servletContext, this, name, value));
} else {
this.servletContext.getServletRequestAttributeListener().attributeReplaced(new ServletRequestAttributeEvent(this.servletContext, this, name, oldValue));
}
}
}
use of javax.servlet.ServletRequestAttributeEvent in project Payara by payara.
the class Request method removeAttribute.
/**
* Remove the specified request attribute if it exists.
*
* @param name Name of the request attribute to remove
*/
@Override
public void removeAttribute(String name) {
Object value = null;
boolean found = attributes.containsKey(name);
if (found) {
value = attributes.get(name);
attributes.remove(name);
} else {
return;
}
// Notify interested application event listeners
List<EventListener> listeners = context.getApplicationEventListeners();
if (listeners.isEmpty()) {
return;
}
ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(servletContext, getRequest(), name, value);
Iterator<EventListener> iter = listeners.iterator();
while (iter.hasNext()) {
EventListener eventListener = iter.next();
if (!(eventListener instanceof ServletRequestAttributeListener)) {
continue;
}
ServletRequestAttributeListener listener = (ServletRequestAttributeListener) eventListener;
try {
listener.attributeRemoved(event);
} catch (Throwable t) {
log(rb.getString(LogFacade.ATTRIBUTE_EVENT_LISTENER_EXCEPTION), t);
// Error valve will pick this exception up and display it to user
attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
}
}
}
use of javax.servlet.ServletRequestAttributeEvent in project Payara by payara.
the class Request method setAttribute.
/**
* Set the specified request attribute to the specified value.
*
* @param name Name of the request attribute to set
* @param value The associated value
*/
@Override
public void setAttribute(String name, Object value) {
// Name cannot be null
if (name == null) {
throw new IllegalArgumentException(rb.getString(LogFacade.NULL_ATTRIBUTE_NAME_EXCEPTION));
}
// Null value is the same as removeAttribute()
if (value == null) {
removeAttribute(name);
return;
}
if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
dispatcherTypeAttr = value;
return;
} else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
requestDispatcherPath = value;
return;
}
boolean replaced = false;
// Do the security check before any updates are made
if (Globals.IS_SECURITY_ENABLED && name.equals("org.apache.tomcat.sendfile.filename")) {
// Use the canonical file name to avoid any possible symlink and
// relative path issues
String canonicalPath;
try {
canonicalPath = new File(value.toString()).getCanonicalPath();
} catch (IOException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.UNABLE_DETERMINE_CANONICAL_NAME), value);
throw new SecurityException(msg, e);
}
// Sendfile is performed in Tomcat's security context so need to
// check if the web app is permitted to access the file while still
// in the web app's security context
System.getSecurityManager().checkRead(canonicalPath);
// Update the value so the canonical path is used
value = canonicalPath;
}
Object oldValue = attributes.put(name, value);
if (oldValue != null) {
replaced = true;
}
// Pass special attributes to the ngrizzly layer
if (name.startsWith("grizzly.")) {
coyoteRequest.setAttribute(name, value);
}
// END SJSAS 6231069
// Notify interested application event listeners
List<EventListener> listeners = context.getApplicationEventListeners();
if (listeners.isEmpty()) {
return;
}
ServletRequestAttributeEvent event = null;
if (replaced) {
event = new ServletRequestAttributeEvent(servletContext, getRequest(), name, oldValue);
} else {
event = new ServletRequestAttributeEvent(servletContext, getRequest(), name, value);
}
Iterator<EventListener> iter = listeners.iterator();
while (iter.hasNext()) {
EventListener eventListener = iter.next();
if (!(eventListener instanceof ServletRequestAttributeListener)) {
continue;
}
ServletRequestAttributeListener listener = (ServletRequestAttributeListener) eventListener;
try {
if (replaced) {
listener.attributeReplaced(event);
} else {
listener.attributeAdded(event);
}
} catch (Throwable t) {
log(rb.getString(LogFacade.ATTRIBUTE_EVENT_LISTENER_EXCEPTION), t);
// Error valve will pick this exception up and display it to user
attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
}
}
}
use of javax.servlet.ServletRequestAttributeEvent in project tomcat70 by apache.
the class Request method notifyAttributeAssigned.
/**
* Notify interested listeners that attribute has been assigned a value.
*/
private void notifyAttributeAssigned(String name, Object value, Object oldValue) {
Object[] listeners = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0)) {
return;
}
boolean replaced = (oldValue != null);
ServletRequestAttributeEvent event = null;
if (replaced) {
event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, oldValue);
} else {
event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value);
}
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletRequestAttributeListener)) {
continue;
}
ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i];
try {
if (replaced) {
listener.attributeReplaced(event);
} else {
listener.attributeAdded(event);
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
// Error valve will pick this exception up and display it to user
attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
}
}
}
Aggregations