Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
 import java.util.Map;
 import  org.osgi.service.http.HttpContext;
The SlingHttpContext implements the OSGi HttpContext used to register the SlingMainServlet with the OSGi HttpService.
 class SlingHttpContext implements HttpContext {

default log
     private static final Logger log = LoggerFactory.getLogger(SlingHttpContext.class);

Resolves MIME types

See also:
     private MimeTypeService mimeTypeService;

Handles security

See also:
handleSecurity(HttpServletRequest, HttpServletResponse)
     public void setMimeTypeService(MimeTypeService mimeTypeService) {
         this. = mimeTypeService;
     public void unsetMimeTypeService(MimeTypeService mimeTypeService) {
         if (this. == mimeTypeService) {
             this. = null;
     public void setAuthenticationSupport(
             AuthenticationSupport authenticationSupport) {
         this. = authenticationSupport;
     public void unsetAuthenticationSupport(
             AuthenticationSupport authenticationSupport) {
         if (this. == authenticationSupport) {
             this. = null;
     // ---------- HttpContext interface ----------------------------------------
Returns the MIME type as resolved by the MimeTypeService or null if the service is not available.
     public String getMimeType(String name) {
         MimeTypeService mtservice = ;
         if (mtservice != null) {
             return mtservice.getMimeType(name);
             "getMimeType: MimeTypeService not available, cannot resolve mime type for {}",
         return null;

Always returns null because resources are all provided through the SlingMainServlet.
    public URL getResource(String name) {
        return null;

Tries to authenticate the request using the SlingAuthenticator. If the authenticator or the Repository is missing this method returns false and sends a 503/SERVICE UNAVAILABLE status back to the client.
    public boolean handleSecurity(HttpServletRequest request,
            HttpServletResponse responsethrows IOException {
        final AuthenticationSupport authenticator = this.;
        if (authenticator != null) {
            // SLING-559: ensure correct parameter handling according to
            // ParameterSupport
            request = new HttpServletRequestWrapper(request) {
                public String getParameter(String name) {
                    return getParameterSupport().getParameter(name);
                public Map<StringString[]> getParameterMap() {
                    return getParameterSupport().getParameterMap();
                public Enumeration<StringgetParameterNames() {
                    return getParameterSupport().getParameterNames();
                public String[] getParameterValues(String name) {
                    return getParameterSupport().getParameterValues(name);
                private ParameterSupport getParameterSupport() {
                    return ParameterSupport.getInstance(getRequest());
            return authenticator.handleSecurity(requestresponse);
        .error("handleSecurity: AuthenticationSupport service missing. Cannot authenticate request.");
        .error("handleSecurity: Possible reason is missing Repository service. Check AuthenticationSupport dependencies.");
        // send 503/SERVICE UNAVAILABLE, flush to ensure delivery
            "AuthenticationSupport service missing. Cannot authenticate request.");
        // terminate this request now
        return false;
New to GrepCode? Check out our FAQ X