Simple HTTP server in Java using only Java SE API

0 votes

Is there a way to create a very basic HTTP server (supporting only GET/POST) in Java using just the Java SE API, without writing code to manually parse HTTP requests and manually format HTTP responses? 

Just to be clear, the problem I have with a lot of ServerSocket examples I've seen online is that they do their own request parsing/response formatting and error handling, which is tedious, error-prone, and not likely to be comprehensive, and I'm trying to avoid it for those reasons.

As an example of the manual HTTP manipulation that I'm trying to avoid:

http://java.sun.com/developer/technicalArticles/Networking/Webserver/WebServercode.html

Aug 29, 2018 in Java by samarth295
• 2,220 points
1,647 views

1 answer to this question.

0 votes

You can write a pretty simple embedded Jetty Java server.

Embedded Jetty means that the server (Jetty) shipped together with the application as opposed of deploying the application on external Jetty server.

So if in non-embedded approach your webapp built into WAR file which deployed to some external server (Tomcat / Jetty / etc), in embedded Jetty, you write the webapp and instantiate the jetty server in the same code base.

An example for embedded Jetty Java server you can git clone and use: https://github.com/stas-slu/embedded-jetty-java-server-example

answered Aug 29, 2018 by Parth
• 4,630 points

Related Questions In Java

0 votes
1 answer

simple HTTP server in Java using only Java SE API

The com.sun.net.httpserver solution is not portable across JREs. Its ...READ MORE

answered Jan 4, 2019 in Java by Daisy
• 8,120 points
2,173 views
0 votes
1 answer

Http Basic Authentication in Java using HttpClient?

String encoding = Base64Encoder.encode ("test1:test1"); HttpPost httppost = ...READ MORE

answered Dec 20, 2018 in Java by Daisy
• 8,120 points
3,621 views
0 votes
1 answer

how to read csv file form sftp connection and store into string object in java code and convert into json.....post it using rest api

Hey, @Pooja, Before starting with anything you should ...READ MORE

answered May 13, 2020 in Java by Roshni
• 10,520 points
3,497 views
0 votes
0 answers

I need to Post api to database using java in intellij. After testing sample api through postman i got an Sql exception saying Syntax error at or near ',' Please tell me where i made a mistake

public Result setModelMasterParams(){         try{             long tenantId = request().getHeader("tenant_id")==null                     || request().getHeader("tenant_id").equalsIgnoreCase("")                     || ...READ MORE

Aug 19, 2020 in Java by Sriram
• 120 points

recategorized Aug 19, 2020 by Niroj 1,253 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 79,554 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,964 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
16,990 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,389 views
0 votes
2 answers

How can I sort values of a Map in Java using its key

Assuming TreeMap is not good for you ...READ MORE

answered Oct 10, 2018 in Java by Sushmita
• 6,910 points
920 views
0 votes
2 answers

Give an example for encryption and decryption in AES using Java

getfullstring: Splashscreen.text >>> READ MORE

answered May 8, 2019 in Java by anonymous
6,583 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP