Skip to content

Commit 9034697

Browse files
committed
migrate from Java EE to Jakarta EE
1 parent 95acad2 commit 9034697

File tree

7 files changed

+135
-176
lines changed

7 files changed

+135
-176
lines changed

ask-sdk-servlet-support/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
<version>2.86.0</version>
4141
</dependency>
4242
<dependency>
43-
<groupId>javax.servlet</groupId>
44-
<artifactId>javax.servlet-api</artifactId>
45-
<version>3.0.1</version>
43+
<groupId>jakarta.servlet</groupId>
44+
<artifactId>jakarta.servlet-api</artifactId>
45+
<version>6.0.0</version>
4646
<scope>provided</scope>
4747
</dependency>
4848
<dependency>

ask-sdk-servlet-support/src/com/amazon/ask/servlet/SkillServlet.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,27 @@
1313

1414
package com.amazon.ask.servlet;
1515

16-
import javax.servlet.http.HttpServlet;
17-
import javax.servlet.http.HttpServletRequest;
18-
import javax.servlet.http.HttpServletResponse;
19-
20-
import java.io.ByteArrayInputStream;
21-
import java.io.ByteArrayOutputStream;
22-
import java.io.InputStream;
23-
import java.io.IOException;
24-
import java.io.NotSerializableException;
25-
import java.io.ObjectInputStream;
26-
import java.io.ObjectOutputStream;
27-
import java.io.OutputStream;
28-
import java.net.Proxy;
29-
import java.util.ArrayList;
30-
import java.util.List;
31-
3216
import com.amazon.ask.Skill;
3317
import com.amazon.ask.exception.AskSdkException;
3418
import com.amazon.ask.model.RequestEnvelope;
3519
import com.amazon.ask.model.services.Serializer;
3620
import com.amazon.ask.request.impl.BaseSkillRequest;
3721
import com.amazon.ask.response.SkillResponse;
3822
import com.amazon.ask.servlet.util.ServletUtils;
39-
import com.amazon.ask.servlet.verifiers.AlexaHttpRequest;
40-
import com.amazon.ask.servlet.verifiers.ServletRequest;
41-
import com.amazon.ask.servlet.verifiers.SkillRequestSignatureVerifier;
42-
import com.amazon.ask.servlet.verifiers.SkillRequestTimestampVerifier;
43-
import com.amazon.ask.servlet.verifiers.SkillServletVerifier;
23+
import com.amazon.ask.servlet.verifiers.*;
4424
import com.amazon.ask.util.JacksonSerializer;
25+
import jakarta.servlet.http.HttpServlet;
26+
import jakarta.servlet.http.HttpServletRequest;
27+
import jakarta.servlet.http.HttpServletResponse;
4528
import org.apache.commons.io.IOUtils;
4629
import org.slf4j.Logger;
4730
import org.slf4j.LoggerFactory;
4831

32+
import java.io.*;
33+
import java.net.Proxy;
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
4937
import static com.amazon.ask.servlet.ServletConstants.DEFAULT_TOLERANCE_MILLIS;
5038

5139
/**
@@ -58,7 +46,6 @@
5846
* invocation of the right method of the provided {@code Skill} . It also handles sending back
5947
* modified session attributes, user attributes and authentication tokens when needed and handles
6048
* exception cases.
61-
*
6249
*/
6350
public class SkillServlet extends HttpServlet {
6451
/**
@@ -90,6 +77,7 @@ public class SkillServlet extends HttpServlet {
9077

9178
/**
9279
* Constructor to build an instance of SkillServlet.
80+
*
9381
* @param skill an Alexa skill instance.
9482
*/
9583
public SkillServlet(final Skill skill) {
@@ -106,7 +94,8 @@ public SkillServlet(final Skill skill) {
10694

10795
/**
10896
* Constructor to build an instance of SkillServlet.
109-
* @param skill instance of {@link Skill}.
97+
*
98+
* @param skill instance of {@link Skill}.
11099
* @param verifiers list of {@link SkillServletVerifier}.
111100
*/
112101
SkillServlet(final Skill skill, final List<SkillServletVerifier> verifiers) {
@@ -166,7 +155,7 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons
166155
* {@code SkillServlet} determines the type of request and passes the request to
167156
* the configured {@code Skill}.
168157
*
169-
* @param input - input stream of the request.
158+
* @param input - input stream of the request.
170159
* @param output - output stream of the response.
171160
* @throws IOException if an input or output error is detected when the servlet handles the request
172161
*/
@@ -198,8 +187,9 @@ public void setProxy(final Proxy proxy) {
198187

199188
/**
200189
* Method throws an {@link NotSerializableException} if the servlet is not serializable.
190+
*
201191
* @param in instance of {@link ObjectInputStream}.
202-
* @throws IOException I/O exception.
192+
* @throws IOException I/O exception.
203193
* @throws ClassNotFoundException cannot a class through its fully-qualified name and can not find its definition on the classpath.
204194
*/
205195
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
@@ -208,6 +198,7 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot
208198

209199
/**
210200
* Method throws an {@link NotSerializableException} if the servlet is not serializable.
201+
*
211202
* @param out instance of {@link ObjectOutputStream}.
212203
* @throws IOException I/O exception.
213204
*/

ask-sdk-servlet-support/src/com/amazon/ask/servlet/verifiers/ServletRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
import com.amazon.ask.model.RequestEnvelope;
1717
import com.amazon.ask.servlet.ServletConstants;
18-
19-
import javax.servlet.http.HttpServletRequest;
18+
import jakarta.servlet.http.HttpServletRequest;
2019

2120
/**
2221
* Servlet specific implementation of {@link AlexaHttpRequest}.
@@ -45,8 +44,9 @@ public class ServletRequest implements AlexaHttpRequest {
4544

4645
/**
4746
* Constructor to build an instance of ServletRequest.
48-
* @param httpServletRequest instance of type {@link HttpServletRequest}.
49-
* @param serializedRequestEnvelope serialized request envelope.
47+
*
48+
* @param httpServletRequest instance of type {@link HttpServletRequest}.
49+
* @param serializedRequestEnvelope serialized request envelope.
5050
* @param deserializedRequestEnvelope de-serialized request envelope.
5151
*/
5252
public ServletRequest(final HttpServletRequest httpServletRequest, final byte[] serializedRequestEnvelope,

ask-sdk-servlet-support/tst/com/amazon/ask/servlet/SkillServletTest.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,16 @@
1313

1414
package com.amazon.ask.servlet;
1515

16-
import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
17-
import static org.junit.Assert.assertTrue;
18-
import static org.mockito.ArgumentMatchers.any;
19-
import static org.mockito.ArgumentMatchers.anyString;
20-
import static org.mockito.ArgumentMatchers.eq;
21-
import static org.mockito.Mockito.mock;
22-
import static org.mockito.Mockito.verify;
23-
import static org.mockito.Mockito.when;
24-
import static org.powermock.api.mockito.PowerMockito.doThrow;
25-
26-
import javax.servlet.http.HttpServletResponse;
27-
2816
import com.amazon.ask.Skill;
2917
import com.amazon.ask.exception.AskSdkException;
3018
import com.amazon.ask.model.LaunchRequest;
3119
import com.amazon.ask.model.Response;
3220
import com.amazon.ask.model.ResponseEnvelope;
21+
import com.amazon.ask.response.impl.BaseSkillResponse;
3322
import com.amazon.ask.servlet.verifiers.SkillRequestSignatureVerifier;
3423
import com.amazon.ask.servlet.verifiers.SkillServletVerifier;
35-
import com.amazon.ask.response.impl.BaseSkillResponse;
3624
import com.amazon.ask.util.impl.JacksonJsonMarshaller;
25+
import jakarta.servlet.http.HttpServletResponse;
3726
import org.junit.Before;
3827
import org.junit.Test;
3928
import org.junit.runner.RunWith;
@@ -49,6 +38,12 @@
4938
import java.util.Collections;
5039
import java.util.Date;
5140

41+
import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
42+
import static org.junit.Assert.assertTrue;
43+
import static org.mockito.ArgumentMatchers.*;
44+
import static org.mockito.Mockito.*;
45+
import static org.powermock.api.mockito.PowerMockito.doThrow;
46+
5247
/**
5348
* Tests that the {@link SkillServlet} respects the provided environment variables controlling
5449
* its behavior.

ask-sdk-servlet-support/tst/com/amazon/ask/servlet/SkillServletTestBase.java

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,38 @@
1313

1414
package com.amazon.ask.servlet;
1515

16-
import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
17-
import static org.mockito.Mockito.when;
18-
19-
import java.io.ByteArrayInputStream;
20-
import java.io.ByteArrayOutputStream;
21-
import java.io.IOException;
22-
import java.io.InputStream;
23-
import java.io.OutputStream;
24-
25-
import javax.servlet.ServletInputStream;
26-
import javax.servlet.ServletOutputStream;
27-
import javax.servlet.http.HttpServletRequest;
28-
import javax.servlet.http.HttpServletResponse;
29-
30-
import com.amazon.ask.model.Application;
31-
import com.amazon.ask.model.Request;
32-
import com.amazon.ask.model.RequestEnvelope;
33-
import com.amazon.ask.model.Session;
34-
import com.amazon.ask.model.User;
16+
import com.amazon.ask.model.*;
17+
import com.fasterxml.jackson.annotation.JsonInclude;
18+
import com.fasterxml.jackson.databind.ObjectMapper;
3519
import com.fasterxml.jackson.databind.SerializationFeature;
3620
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21+
import jakarta.servlet.ServletInputStream;
22+
import jakarta.servlet.ServletOutputStream;
23+
import jakarta.servlet.http.HttpServletRequest;
24+
import jakarta.servlet.http.HttpServletResponse;
3725
import org.mockito.Mockito;
3826

39-
import com.fasterxml.jackson.annotation.JsonInclude;
40-
import com.fasterxml.jackson.databind.ObjectMapper;
27+
import java.io.*;
28+
29+
import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
30+
import static org.mockito.Mockito.when;
4131

4232
public class SkillServletTestBase {
4333
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
34+
4435
static {
4536
OBJECT_MAPPER.registerModule(new JavaTimeModule());
4637
OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
4738
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
4839
}
4940

50-
/**
51-
* Tuple for useful parameters for a servlet invocation.
52-
*/
53-
protected static final class ServletInvocationParameters {
54-
public final HttpServletRequest request;
55-
public final HttpServletResponse response;
56-
public final ByteArrayOutputStream output;
57-
58-
public ServletInvocationParameters(final HttpServletRequest request,
59-
final HttpServletResponse response, final ByteArrayOutputStream output) {
60-
this.request = request;
61-
this.response = response;
62-
this.output = output;
63-
}
64-
}
65-
66-
/**
67-
* Trivial implementation of the ServletInputStream that wraps an InputStream.
68-
*/
69-
private static class MyServletInputStream extends ServletInputStream {
70-
private final InputStream in;
71-
72-
public MyServletInputStream(final InputStream in) {
73-
this.in = in;
74-
}
75-
76-
@Override
77-
public int read() throws IOException {
78-
return in.read();
79-
}
80-
}
81-
82-
/**
83-
* Trivial implementation of the ServletOutputStream that wraps an OutputStream.
84-
*/
85-
private static class MyServletOutputStream extends ServletOutputStream {
86-
private final OutputStream out;
87-
88-
public MyServletOutputStream(final OutputStream out) {
89-
this.out = out;
90-
}
91-
92-
@Override
93-
public void write(int b) throws IOException {
94-
out.write(b);
95-
}
96-
}
97-
98-
// ------------------------------
99-
// Helper methods for subclasses
100-
10141
/**
10242
* Common logic for all the tests.
10343
*
104-
* @param version
105-
* the envelope version for the request envelope
106-
* @param request
107-
* a SkillRequest
108-
* @param session
109-
* a session for this invocation
44+
* @param version the envelope version for the request envelope
45+
* @param request a SkillRequest
46+
* @param session a session for this invocation
11047
* @return invocation parameters for a Skill
111-
*
11248
* @throws IOException
11349
*/
11450
protected ServletInvocationParameters build(final String version, final Request request, final Session session) throws IOException {
@@ -143,12 +79,9 @@ protected ServletInvocationParameters build(final String version, final Request
14379
* <li>The current SDK version as a version</li>
14480
* </ul>
14581
*
146-
* @param request
147-
* a SkillRequest or OnSessionEndedRequest
148-
* @param session
149-
* a session for this invocation
82+
* @param request a SkillRequest or OnSessionEndedRequest
83+
* @param session a session for this invocation
15084
* @return invocation parameters for a Skill
151-
*
15285
* @throws IOException
15386
*/
15487
protected ServletInvocationParameters build(final Request request,
@@ -159,17 +92,18 @@ protected ServletInvocationParameters build(final Request request,
15992
/**
16093
* Same as above using a simple Session and User.
16194
*
162-
* @param request
163-
* a skill request
95+
* @param request a skill request
16496
* @return invocation parameters for a Skill
165-
*
16697
* @throws IOException
16798
*/
16899
protected ServletInvocationParameters build(final Request request)
169100
throws IOException {
170101
return build(request, buildSession());
171102
}
172103

104+
// ------------------------------
105+
// Helper methods for subclasses
106+
173107
/**
174108
* @return a test session.
175109
*/
@@ -186,4 +120,52 @@ protected Session buildSession(String applicationId) {
186120
.build();
187121
}
188122

123+
/**
124+
* Tuple for useful parameters for a servlet invocation.
125+
*/
126+
protected static final class ServletInvocationParameters {
127+
public final HttpServletRequest request;
128+
public final HttpServletResponse response;
129+
public final ByteArrayOutputStream output;
130+
131+
public ServletInvocationParameters(final HttpServletRequest request,
132+
final HttpServletResponse response, final ByteArrayOutputStream output) {
133+
this.request = request;
134+
this.response = response;
135+
this.output = output;
136+
}
137+
}
138+
139+
/**
140+
* Trivial implementation of the ServletInputStream that wraps an InputStream.
141+
*/
142+
private static class MyServletInputStream extends ServletInputStream {
143+
private final InputStream in;
144+
145+
public MyServletInputStream(final InputStream in) {
146+
this.in = in;
147+
}
148+
149+
@Override
150+
public int read() throws IOException {
151+
return in.read();
152+
}
153+
}
154+
155+
/**
156+
* Trivial implementation of the ServletOutputStream that wraps an OutputStream.
157+
*/
158+
private static class MyServletOutputStream extends ServletOutputStream {
159+
private final OutputStream out;
160+
161+
public MyServletOutputStream(final OutputStream out) {
162+
this.out = out;
163+
}
164+
165+
@Override
166+
public void write(int b) throws IOException {
167+
out.write(b);
168+
}
169+
}
170+
189171
}

0 commit comments

Comments
 (0)