30
30
import com .amazonaws .auth .PropertiesCredentials ;
31
31
import com .amazonaws .internal .StaticCredentialsProvider ;
32
32
import com .amazonaws .regions .RegionUtils ;
33
+ import com .amazonaws .services .dynamodb .sessionmanager .converters .DefaultDynamoSessionItemConverter ;
33
34
import com .amazonaws .services .dynamodb .sessionmanager .converters .DefaultTomcatSessionConverter ;
34
- import com .amazonaws .services .dynamodb .sessionmanager .converters .LegacyDynamoDBSessionItemConverter ;
35
35
import com .amazonaws .services .dynamodb .sessionmanager .converters .LegacyTomcatSessionConverter ;
36
36
import com .amazonaws .services .dynamodb .sessionmanager .converters .SessionConverter ;
37
37
import com .amazonaws .services .dynamodb .sessionmanager .converters .TomcatSessionConverterChain ;
@@ -49,9 +49,9 @@ public class DynamoDBSessionManager extends PersistentManagerBase {
49
49
50
50
public static final String DEFAULT_TABLE_NAME = "Tomcat_SessionState" ;
51
51
52
- private static final String USER_AGENT = "DynamoSessionManager/1.1 " ;
52
+ private static final String USER_AGENT = "DynamoSessionManager/2.0 " ;
53
53
private static final String name = "AmazonDynamoDBSessionManager" ;
54
- private static final String info = name + "/1.1 " ;
54
+ private static final String info = name + "/2.0 " ;
55
55
56
56
private String regionId = "us-east-1" ;
57
57
private String endpoint ;
@@ -87,10 +87,6 @@ public String getName() {
87
87
return name ;
88
88
}
89
89
90
- //
91
- // Context.xml Configuration Members
92
- //
93
-
94
90
public void setRegionId (String regionId ) {
95
91
this .regionId = regionId ;
96
92
}
@@ -135,10 +131,6 @@ public void setProxyPort(Integer proxyPort) {
135
131
this .proxyPort = proxyPort ;
136
132
}
137
133
138
- //
139
- // Private Interface
140
- //
141
-
142
134
@ Override
143
135
protected void initInternal () throws LifecycleException {
144
136
this .setDistributable (true );
@@ -170,16 +162,16 @@ private AWSCredentialsProvider initCredentials() {
170
162
if (credentialsInContextConfigAreValid ()) {
171
163
throw new AmazonClientException ("Incomplete AWS security credentials specified in context.xml." );
172
164
}
173
- debug ("Using AWS access key ID and secret key from context.xml" );
165
+ logger . debug ("Using AWS access key ID and secret key from context.xml" );
174
166
return new StaticCredentialsProvider (new BasicAWSCredentials (accessKey , secretKey ));
175
167
}
176
168
177
169
// Use any explicitly specified credentials properties file next
178
170
if (credentialsFile != null ) {
179
171
try {
180
- debug ("Reading security credentials from properties file: " + credentialsFile );
172
+ logger . debug ("Reading security credentials from properties file: " + credentialsFile );
181
173
PropertiesCredentials credentials = new PropertiesCredentials (credentialsFile );
182
- debug ("Using AWS credentials from file: " + credentialsFile );
174
+ logger . debug ("Using AWS credentials from file: " + credentialsFile );
183
175
return new StaticCredentialsProvider (credentials );
184
176
} catch (Exception e ) {
185
177
throw new AmazonClientException (
@@ -191,13 +183,13 @@ private AWSCredentialsProvider initCredentials() {
191
183
// Fall back to the default credentials chain provider if credentials weren't explicitly set
192
184
AWSCredentialsProvider defaultChainProvider = new DefaultAWSCredentialsProviderChain ();
193
185
if (defaultChainProvider .getCredentials () == null ) {
194
- debug ("Loading security credentials from default credentials provider chain." );
186
+ logger . debug ("Loading security credentials from default credentials provider chain." );
195
187
throw new AmazonClientException (
196
188
"Unable find AWS security credentials. "
197
189
+ "Searched JVM system properties, OS env vars, and EC2 instance roles. "
198
190
+ "Specify credentials in Tomcat's context.xml file or put them in one of the places mentioned above." );
199
191
}
200
- debug ("Using default AWS credentials provider chain to load credentials" );
192
+ logger . debug ("Using default AWS credentials provider chain to load credentials" );
201
193
return defaultChainProvider ;
202
194
}
203
195
@@ -223,12 +215,12 @@ private ClientConfiguration initClientConfiguration() {
223
215
224
216
// Attempt to use an explicit proxy configuration
225
217
if (proxyHost != null || proxyPort != null ) {
226
- debug ("Reading proxy settings from context.xml" );
218
+ logger . debug ("Reading proxy settings from context.xml" );
227
219
if (proxyHost == null || proxyPort == null ) {
228
220
throw new AmazonClientException ("Incomplete proxy settings specified in context.xml."
229
221
+ " Both proxy hot and proxy port needs to be specified" );
230
222
}
231
- debug ("Using proxy host and port from context.xml" );
223
+ logger . debug ("Using proxy host and port from context.xml" );
232
224
clientConfiguration .withProxyHost (proxyHost ).withProxyPort (proxyPort );
233
225
}
234
226
@@ -260,9 +252,9 @@ private SessionConverter getSessionConverter() {
260
252
LegacyTomcatSessionConverter legacyConverter = new LegacyTomcatSessionConverter (this , classLoader ,
261
253
maxInactiveInterval );
262
254
DefaultTomcatSessionConverter defaultConverter = new DefaultTomcatSessionConverter (this , classLoader );
263
- // Converter compatible with the legacy schema but can understand new schema
264
- return new SessionConverter (TomcatSessionConverterChain .wrap (legacyConverter , defaultConverter ),
265
- new LegacyDynamoDBSessionItemConverter ());
255
+ // Converter that 'writes' with the new schema but can still read the legacy schema
256
+ return new SessionConverter (TomcatSessionConverterChain .wrap (defaultConverter , legacyConverter ),
257
+ new DefaultDynamoSessionItemConverter ());
266
258
}
267
259
268
260
/**
@@ -283,28 +275,4 @@ private Context getAssociatedContext() {
283
275
throw new IllegalStateException (e );
284
276
}
285
277
}
286
-
287
- //
288
- // Logger Utility Functions
289
- //
290
-
291
- public static void debug (String s ) {
292
- logger .debug (s );
293
- }
294
-
295
- public static void warn (String s ) {
296
- logger .warn (s );
297
- }
298
-
299
- public static void warn (String s , Exception e ) {
300
- logger .warn (s , e );
301
- }
302
-
303
- public static void error (String s ) {
304
- logger .error (s );
305
- }
306
-
307
- public static void error (String s , Exception e ) {
308
- logger .error (s , e );
309
- }
310
278
}
0 commit comments