/*
 * Copyright (c) 2012, Inversoft Inc., All Rights Reserved
 *
 * Licensed 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
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.primeframework.mvc.servlet.guice;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import org.primeframework.mvc.servlet.HTTPMethod;
import org.primeframework.mvc.servlet.ServletObjectsHolder;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;

/**
 * This class is a Guice module for the Prime MVC servlet object support.
 *
 * @author Brian Pontarelli
 */
public class ServletModule extends AbstractModule {
  @Override
  protected void configure() {
    bind(ServletContext.class).toInstance(ServletObjectsHolder.getServletContext());
  }
  
  @Provides
  public HttpServletRequest request() {
    return ServletObjectsHolder.getServletRequest();
  }

  @Provides
  public HttpServletRequestWrapper requestWrapper() {
    return ServletObjectsHolder.getServletRequest();
  }

  @Provides
  public HttpServletResponse response() {
    return ServletObjectsHolder.getServletResponse();
  }

  @Provides
  public HTTPMethod method() {
    return HTTPMethod.valueOf(ServletObjectsHolder.getServletRequest().getMethod().toUpperCase());
  }
}

@@ -17,16 +17,21 @@
 (c) 2012
+-2017
 , Invers
@@ -1243,24 +1243,99 @@
 nfigure() %7B%0A
+    // bind to a provider so we can override w/out getting a null binding.%0A
     bind(Ser
@@ -1359,16 +1359,16 @@
 ).to
-Instance
+Provider
 (Ser
@@ -1376,33 +1376,34 @@
 letObjectsHolder
-.
+::
 getServletContex
@@ -1403,18 +1403,16 @@
 tContext
-()
 );%0A  %7D%0A 

use a provider for javax.servlet.ServletContext