Skip navigation links

Package io.cdap.http

Service and components to build Netty based Http web service.

See: Description

Package io.cdap.http Description

Service and components to build Netty based Http web service. NettyHttpService sets up the necessary pipeline and manages starting, stopping, state-management of the web service.

In-order to handle http requests, HttpHandler must be implemented. The methods in the classes implemented from HttpHandler must be annotated with Jersey annotations to specify http uri paths and http methods. Note: Only supports the following annotations: Path, PathParam, GET, PUT, POST, DELETE. Note: Doesn't support getting Annotations from base class if the HttpHandler implements also extends a class with annotation. Sample usage Handlers and Netty service setup:

 //Setup Handlers

  @Path("/common/v1/")
 public class ApiHandler implements HttpHandler {

    @Path("widgets")
    @GET
   public void widgetHandler(HttpRequest request, HttpResponder responder) {
     responder.sendJson(HttpResponseStatus.OK, "{\"key\": \"value\"}");
   }

    @Override
   public void init(HandlerContext context) {
     //Perform bootstrap operations before any of the handlers in this class gets called.
   }

    @Override
   public void destroy(HandlerContext context) {
    //Perform teardown operations the server shuts down.
   }
 }

 //Set up and start the http service
 NettyHttpService service = NettyHttpService.builder()
                                            .addHttpHandlers(ImmutableList.of(new Handler())
                                            .setPort(8989)
                                            .build();
 service.start();

 // ....

 //Stop the web-service
 service.shutdown();

 
Skip navigation links

Copyright 2019 Cask, Inc. Licensed under the Apache License, Version 2.0