Skip to content

Commit 4fcde7d

Browse files
committed
Merge branch 'dmetzler-master' into core from PR #253
2 parents 9098e3e + e48449c commit 4fcde7d

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

aws-serverless-java-container-jersey/src/main/java/com/amazonaws/serverless/proxy/jersey/JerseyLambdaContainerHandler.java

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.amazonaws.services.lambda.runtime.Context;
3535

3636
import org.glassfish.jersey.internal.inject.AbstractBinder;
37+
import org.glassfish.jersey.internal.inject.InjectionManager;
3738
import org.glassfish.jersey.process.internal.RequestScoped;
3839
import org.glassfish.jersey.server.ResourceConfig;
3940

@@ -196,4 +197,12 @@ public void initialize() {
196197
Timer.stop("JERSEY_COLD_START_INIT");
197198
initialized = true;
198199
}
200+
201+
202+
public InjectionManager getInjectionManager() {
203+
if (!initialized) {
204+
initialize();
205+
}
206+
return jerseyFilter.getApplicationHandler().getInjectionManager();
207+
}
199208
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0/
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.amazonaws.serverless.proxy.jersey;
14+
15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertNotNull;
17+
18+
import javax.inject.Singleton;
19+
20+
import org.glassfish.jersey.internal.inject.AbstractBinder;
21+
import org.glassfish.jersey.media.multipart.MultiPartFeature;
22+
import org.glassfish.jersey.server.ResourceConfig;
23+
import org.junit.Test;
24+
25+
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
26+
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
27+
28+
/**
29+
* Test that one can access the Jersey injection manager
30+
*/
31+
public class JerseyInjectionTest {
32+
33+
// Test ressource binder
34+
private static class ResourceBinder extends AbstractBinder {
35+
36+
@Override
37+
protected void configure() {
38+
bind(new JerseyInjectionTest()).to(JerseyInjectionTest.class).in(Singleton.class);
39+
}
40+
41+
}
42+
43+
private static ResourceConfig app = new ResourceConfig().register(MultiPartFeature.class)
44+
.register(new ResourceBinder());
45+
46+
private static JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = JerseyLambdaContainerHandler.getAwsProxyHandler(
47+
app);
48+
49+
@Test
50+
public void can_get_injected_resources() throws Exception {
51+
52+
JerseyInjectionTest instance1 = handler.getInjectionManager().getInstance(JerseyInjectionTest.class);
53+
assertNotNull(instance1);
54+
55+
JerseyInjectionTest instance2 = handler.getInjectionManager().getInstance(JerseyInjectionTest.class);
56+
assertEquals(instance1, instance2);
57+
58+
}
59+
}

0 commit comments

Comments
 (0)