Alfie Danger
Alfie Danger

Reputation: 469

Deploy Java Website to AWS Elastic Beanstalk

I am trying to deploy a web app that consists of 1 html, 1 jsp, and 3 servlets (and some css and images). The web app uses a mysql database that I am hosting in a AWS RDS instance. I used this guide

I deploy the web app and receive no errors, however only the html page loads. I am deploying directly from eclipse using the tool belt.

Deploying and testing locally on a tomcat v9 server works fine and the flow between the pages is fine. However, when I deploy to a AWS elastic beanstalk server that runs a platform using: Tomcat 8 with Java 8 running on 64bit Amazon Linux/3.1.5 (the latest version of tomcat it lets me use is v8 could this be a problem?), then the only page that can be loaded is the html. When trying to load the jsp or submit a servlet it eventually says this page is not working.

File Overview:

The html is just a form that submits to the servlet sendRequest. The jsp displays a table in the mySQL database and also lets you change a column in the table by sending it to fillRequest, also it lets you download a file that is stored in the db as a BLOB using the download.java servlet.

This is the first time I am deploying to AWS beanstalk and I am unsure if I did something wrong in the process. Since the code works locally I am unsure what code I should include, please let me know what other information would be helpful to post and then I will edit my question. Any help with where I should look to find what is going wrong and how I can fix this is greatly appreciated!

Logs:

Summary of Logs: 1.

17-Jun-2019 09:22:05.095 SEVERE [http-nio-8080-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [sendRequest] in context with path [] threw exception
 java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to java.io.FileInputStream
    at requests.sendRequest.doPost(sendRequest.java:65)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:684)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1152)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

What I tried to fix it:

I looked at this post: Why did Servlet.service() for servlet jsp throw this exception?

As a result I added the following to my pom.xml:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
  <scope>provided</scope>
</dependency>

However, nothing changed. I also looked at this post: I need save some picture,how can I fix that ByteArrayInputStream to FileInputStream?

As a results I changed: (ps is a preparedStatement)

FileInputStream fileContent = (FileInputStream) filePart.getInputStream();
ps.setBinaryStream(10, fileContent);

to

InputStream fileContent = filePart.getInputStream();
ps.setBinaryStream(10, fileContent);

Still nothing changed...

2.

17-Jun-2019 12:10:59.411 INFO [http-nio-8080-exec-10] org.apache.coyote.http11.AbstractHttp11Processor.process Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
    at org.apache.coyote.http11.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:287)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1065)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

3.

com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
  1. [proxy:error] [pid 3655:tid 139803953698560] [client 172.31.3.93:48782] AH00898: Error reading from remote server returned by /requests.jsp, referer: ...../orderform.html

Upvotes: 0

Views: 1777

Answers (1)

Alfie Danger
Alfie Danger

Reputation: 469

I managed to fix my problem by following this guide.

What I had forgotten to do is to connect my web app to the RDS database.

So in order to fix it I launched the RDS in a default VPC. I then modified the inbound rules on the RDS instance's security group. The modifications I made were to add a new rule for the security group of the elastic beanstalk instance.

Upvotes: 1

Related Questions