Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-335: migrate from Java EE to Jakarta EE #334

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions ask-sdk-servlet-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<version>2.86.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,27 @@

package com.amazon.ask.servlet;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;

import com.amazon.ask.Skill;
import com.amazon.ask.exception.AskSdkException;
import com.amazon.ask.model.RequestEnvelope;
import com.amazon.ask.model.services.Serializer;
import com.amazon.ask.request.impl.BaseSkillRequest;
import com.amazon.ask.response.SkillResponse;
import com.amazon.ask.servlet.util.ServletUtils;
import com.amazon.ask.servlet.verifiers.AlexaHttpRequest;
import com.amazon.ask.servlet.verifiers.ServletRequest;
import com.amazon.ask.servlet.verifiers.SkillRequestSignatureVerifier;
import com.amazon.ask.servlet.verifiers.SkillRequestTimestampVerifier;
import com.amazon.ask.servlet.verifiers.SkillServletVerifier;
import com.amazon.ask.servlet.verifiers.*;
import com.amazon.ask.util.JacksonSerializer;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;

import static com.amazon.ask.servlet.ServletConstants.DEFAULT_TOLERANCE_MILLIS;

/**
Expand All @@ -58,7 +46,6 @@
* invocation of the right method of the provided {@code Skill} . It also handles sending back
* modified session attributes, user attributes and authentication tokens when needed and handles
* exception cases.
*
*/
public class SkillServlet extends HttpServlet {
/**
Expand Down Expand Up @@ -90,6 +77,7 @@ public class SkillServlet extends HttpServlet {

/**
* Constructor to build an instance of SkillServlet.
*
* @param skill an Alexa skill instance.
*/
public SkillServlet(final Skill skill) {
Expand All @@ -106,7 +94,8 @@ public SkillServlet(final Skill skill) {

/**
* Constructor to build an instance of SkillServlet.
* @param skill instance of {@link Skill}.
*
* @param skill instance of {@link Skill}.
* @param verifiers list of {@link SkillServletVerifier}.
*/
SkillServlet(final Skill skill, final List<SkillServletVerifier> verifiers) {
Expand Down Expand Up @@ -166,7 +155,7 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons
* {@code SkillServlet} determines the type of request and passes the request to
* the configured {@code Skill}.
*
* @param input - input stream of the request.
* @param input - input stream of the request.
* @param output - output stream of the response.
* @throws IOException if an input or output error is detected when the servlet handles the request
*/
Expand Down Expand Up @@ -198,8 +187,9 @@ public void setProxy(final Proxy proxy) {

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

/**
* Method throws an {@link NotSerializableException} if the servlet is not serializable.
*
* @param out instance of {@link ObjectOutputStream}.
* @throws IOException I/O exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import com.amazon.ask.model.RequestEnvelope;
import com.amazon.ask.servlet.ServletConstants;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

/**
* Servlet specific implementation of {@link AlexaHttpRequest}.
Expand Down Expand Up @@ -45,8 +44,9 @@ public class ServletRequest implements AlexaHttpRequest {

/**
* Constructor to build an instance of ServletRequest.
* @param httpServletRequest instance of type {@link HttpServletRequest}.
* @param serializedRequestEnvelope serialized request envelope.
*
* @param httpServletRequest instance of type {@link HttpServletRequest}.
* @param serializedRequestEnvelope serialized request envelope.
* @param deserializedRequestEnvelope de-serialized request envelope.
*/
public ServletRequest(final HttpServletRequest httpServletRequest, final byte[] serializedRequestEnvelope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,16 @@

package com.amazon.ask.servlet;

import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.doThrow;

import javax.servlet.http.HttpServletResponse;

import com.amazon.ask.Skill;
import com.amazon.ask.exception.AskSdkException;
import com.amazon.ask.model.LaunchRequest;
import com.amazon.ask.model.Response;
import com.amazon.ask.model.ResponseEnvelope;
import com.amazon.ask.response.impl.BaseSkillResponse;
import com.amazon.ask.servlet.verifiers.SkillRequestSignatureVerifier;
import com.amazon.ask.servlet.verifiers.SkillServletVerifier;
import com.amazon.ask.response.impl.BaseSkillResponse;
import com.amazon.ask.util.impl.JacksonJsonMarshaller;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -49,6 +38,12 @@
import java.util.Collections;
import java.util.Date;

import static com.amazon.ask.util.SdkConstants.FORMAT_VERSION;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.doThrow;

/**
* Tests that the {@link SkillServlet} respects the provided environment variables controlling
* its behavior.
Expand Down