Skip to content

Commit

Permalink
Merge pull request #3 from mattcorey/revert-2-profile-support
Browse files Browse the repository at this point in the history
Revert "Profile support"
  • Loading branch information
mattcorey authored Mar 1, 2017
2 parents 7205220 + 054c2b0 commit 19ce263
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 168 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
```

### Spring support
The library supports Spring applications that are configured using annotations (in code) rather than in an XML file. The simplest possible configuration uses the `@ComponentScan` annotation to load all controller classes from a package. For example, our unit test application has the following configuration class.
The library supports Spring applications that are configured using annotations (in code) rather than in an XML file. The simplest possible configuration uses the `@ComponentScan` annotation to load all controller classes from a package. For example, our unit test application has the following configuuration class.

```java
@Configuration
Expand All @@ -57,9 +57,6 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
}
```

#### Spring Profiles
You can enable Spring Profiles (as defined with the `@Profile` annotation) by deploying your Lambda under a stage name that matches the profile name. This will allow you to create a single package with support for different resources for dev, test, prod, etc. See [@Profile documentation](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Profile.html) for details.

### Spark support
The library also supports applications written with the [Spark framework](http://sparkjava.com/). When using the library with Spark, it's important to initialize the `SparkLambdaContainerHandler` before defining routes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ public String getVirtualServerName() {
return null;
}

public String getStage() {
return awsProxyRequest.getRequestContext().getStage();
}

public static ServletContext getInstance(AwsProxyRequest request, Context lambdaContext) {
if (instance == null) {
Expand All @@ -421,8 +418,4 @@ public static ServletContext getInstance(AwsProxyRequest request, Context lambda

return instance;
}

public static void clearServletContextCache() {
instance = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class LambdaSpringApplicationInitializer implements WebApplicationInitial
private ConfigurableWebApplicationContext applicationContext;
private boolean refreshContext = true;
private List<ServletContextListener> contextListeners;
private String lambdaStage;

// Dynamically instantiated properties
private ServletConfig dispatcherConfig;
Expand Down Expand Up @@ -85,13 +84,8 @@ public void dispatch(HttpServletRequest request, HttpServletResponse response)
dispatcherServlet.service(request, response);
}

public void setLambdaStage(String lambdaStage) {
this.lambdaStage = lambdaStage;
}

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
applicationContext.getEnvironment().setActiveProfiles(lambdaStage);
applicationContext.setServletContext(servletContext);

dispatcherConfig = new DefaultDispatcherConfig(servletContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import com.amazonaws.serverless.proxy.internal.*;
import com.amazonaws.serverless.proxy.internal.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.internal.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.internal.servlet.*;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletResponse;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletResponseWriter;
import com.amazonaws.services.lambda.runtime.Context;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
Expand Down Expand Up @@ -109,7 +112,6 @@ protected void handleRequest(AwsProxyHttpServletRequest containerRequest, AwsHtt

// wire up the application context on the first invocation
if (!initialized) {
initializer.setLambdaStage(((AwsProxyServletContext) containerRequest.getServletContext()).getStage());
ServletContext context = containerRequest.getServletContext();
initializer.onStartup(context);
initialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext;
import com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer;
import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.context.ConfigurableWebApplicationContext;

@Configuration
@ComponentScan("com.amazonaws.serverless.proxy.spring.echoapp")
@PropertySource("classpath:application.properties")
public class EchoSpringAppConfig {

@Autowired
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 19ce263

Please sign in to comment.