Search in sources :

Example 1 with AttributesMap

use of org.eclipse.jetty.util.AttributesMap in project jetty.project by eclipse.

the class App method getContextHandler.

/* ------------------------------------------------------------ */
/**
     * Get ContextHandler for the App.
     * 
     * Create it if needed.
     * 
     * @return the {@link ContextHandler} to use for the App when fully started.
     *         (Portions of which might be ignored when App is not yet 
     *         {@link AppLifeCycle#DEPLOYED} or {@link AppLifeCycle#STARTED})
     * @throws Exception if unable to get the context handler
     */
public ContextHandler getContextHandler() throws Exception {
    if (_context == null) {
        _context = getAppProvider().createContextHandler(this);
        AttributesMap attributes = _manager.getContextAttributes();
        if (attributes != null && attributes.size() > 0) {
            // Merge the manager attributes under the existing attributes
            attributes = new AttributesMap(attributes);
            attributes.addAll(_context.getAttributes());
            _context.setAttributes(attributes);
        }
    }
    return _context;
}
Also used : AttributesMap(org.eclipse.jetty.util.AttributesMap)

Example 2 with AttributesMap

use of org.eclipse.jetty.util.AttributesMap 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);
        }
    }
}
Also used : ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) ServletRequestAttributeEvent(javax.servlet.ServletRequestAttributeEvent) AttributesMap(org.eclipse.jetty.util.AttributesMap)

Aggregations

AttributesMap (org.eclipse.jetty.util.AttributesMap)2 ServletRequestAttributeEvent (javax.servlet.ServletRequestAttributeEvent)1 ServletRequestAttributeListener (javax.servlet.ServletRequestAttributeListener)1