0 Replies - 611 Views - Last Post: 29 November 2018 - 04:50 PM

#1 gudda887   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-November 18

Need help with Servlets and REST API

Posted 29 November 2018 - 04:49 PM

Hello guys,

I've came here in order to get some clear information or help regarding my project. First of all, I have basic Java and HTML knowledge, I'm studying Cyber Security(first years) so I'm not too familiar with web apps however these are the easier parts which I can figure out myself. I have no experience in JSON and Java Servlets.

For my project we need to work with a Raspberry Pi 3 which needs to be configured to work as a Wifi AP. I got that to work.

Next step is Installing Apache HTTP server on the RPi and putting my landing page in the /html file. So whenever I go to localhost on my Pi, it'll show the landing page, which works too.

3rd step(or maybe a step which I have to do after the servlet issue) is (for now) adjust the iptables so all traffic gets sent to the localhost. So whenever they go to google.com, it sends them to my localhost (landing page). I'll have to add iptables rules later with connection states, when user is verified etc.

Now comes the step which my study (in my opinion) doesn't explain that well and this is done on my mac, NOT on the raspberry pi.
I've downloaded and installed Tomcat 9(on my mac), which is up and running.
I've downloaded IntelliJ ultimate which supports Java servlets.

Now my "Landing Page" folder consist out of:

image1.png, image1.jpg, index.html, style.css. This is what I use for my landing page for now. It has a login form(the index.html) with ticketnumber and lastname and it doesn't check anything yet.

Now since I don't want people to make my homework, I'll just list some problems I really can't figure out myself. I've done some searching but I just need it explained in baby language tbh, lol.

Where do I actually program in? Do I work with JSON inside the Servlet.java file?

How can I invoke servlets or the statements in the HTML login form or atleast where do I program that? So when X user enters wrong/correct info they get "Login failed" or they get redirected to google.com (using iptables)

What do I save in my "Landing Page" Folder? Can I just transfer those files onto my RPi to get them working on my RPi later on?

2. Retrieving information from the flight information system
2.1 Check validity of ticket
Check if a certain combination of ticket number and passenger name are valid.
URL: http://fys.securidoc.nl:11111/Ticket
Method: POST
Function: Check

One of the aspects I need to program, I can invoke the URL in Postman to see the information.
This is the body:

"function": "List",
"teamId": "********",
"teamKey": "1b3741ccf6d9ec524505537012******",
"requestId": "1"

This is one of the parameters(I've censored teamId and teamKey)
    "tickets": {
        "33645d9b-ee8d-cf72-6012-0a01bd02104d": {
            "tid": "33645d9b-ee8d-cf72-6012-0a01bd02104d",
            "ticketNumber": "8ac5-7c6c-ba14",
            "pid": "8ac6e319-38a3-6c82-a64e-fdcde4ffe61f",
            "fid": "4217a101-b502-86a4-9d17-1b0d01ff8f95",
            "********": null

So when I POST the URL request in Postman
I get information like that above, sent back to me.
Do I need to work with the URL(if so, do I put that in
 @WebServlet(name = "Servlet", urlPatterns = "http://fys.securidoc.nl/:11111") 
, or do I need to make the body with JSON inside my servlet(in the doGet method)?

When do/should I use the web.xml file?

Do I put the "Landing Page" folder on the Tomcat server(including the files I need for the Servlet and API, or just first the basic landing page I got now) if I want to test it? Now it shows a blank page on localhost:8080.

and final, are there any good, recommended guides that explains this/teaches the basic in order do this kind of stuff?

I hope I made this a little bit clear, and I'm sorry if this is too much to be asked, but I just don't know where to look, and what I need to use to program this, and I doubt you'll need months/years coding experience with JSON as long as you have a basic understanding how everything communicates with eachother. I just want to be on the right tracks, which makes searching and learning much easier. If anything is unclear I'll be glad to make it more clearer. Thanks.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1