Jetty handler swing handler differences

Jetty handler swing handler differences

How to add servlet handlers for jetty server ?

Jetty handler :  Add a class extending HttpServlet as handler for a path.


Swing handler:

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new ServletContainer(new MSLifeCycleApplication())), “/*”);

Pass context as an argument to setHandler

register(new AbstractBinder() {
protected void configure() {

* Specify where resource classes are located. These are the classes that constitute the API.
packages(true, “com.microservice.api”);
All classes in above package path constitutes the API

Get data from swing api:


public Response api1(String requestJson, public Response api1(String requestJson,                                  @Context HttpHeaders httpHeaders)


String h1 = httpHeaders.getHeaderString(“h1”);

switch (h1) {

case “1”: {

if (h1 != null) {

if (validateJsonSyntax(requestJson)) {

ObjectMapper objectMapper = new ObjectMapper();                                try {

Object1 obj = objectMapper.readValue(requestJson, json1.class);        return Response.status(Response.Status.ACCEPTED).build();                                }

catch (Exception e) {

return Response.status(Response.Status.BAD_REQUEST).build();                                }



default:            {            }            break;
}        return Response.status(Response.Status.BAD_REQUEST).build();


Get data from HttpServet handlers:
public class c1 extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

//super.doPost(request, response);

String h1 = request.getHeader(“h1”);
String h2 = request.getHeader(“h2”);

switch (h1) {

case “one”: {

if (h2 != null) {
InputStream inStrReqBody = request.getInputStream();
if (inStrReqBody != null) {
String strReqBody = IOUtils.toString(inStrReqBody,
if (validateJsonSyntax(strReqBody)) {
ObjectMapper objectMapper = new ObjectMapper();
try {
Object1 obj1 = objectMapper.readValue(strReqBody,Object1.class);
} catch (Exception e) {




Calling swing api:

Response response =“http://localhost:8082”)
.header(“h1”, “”)
.header(“h2”, “”)
.header(“h3”, “”)
.post(Entity.entity(request, MediaType.APPLICATION_JSON));

Resolving technical problems:

Solve your technical problems instantly

We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM

Mail your problem details at along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.