Skip to content

soklet/soklet-servlet-jakarta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Soklet

Soklet Servlet Integration (jakarta)

Soklet is not a Servlet Container - it has its own in-process HTTP server, its own approach to request and response constructs, and so forth. Soklet applications are intended to be "vanilla" Java applications, as opposed to a WAR file deployed onto a Java EE App Server.

However, there is a large body of existing code that relies on the Servlet API. To support it, Soklet provides its own implementations of the following Servlet interfaces, which enable interoperability for many common use cases:

This library is for the jakarta.servlet API. If you need to integrate with the legacy javax.servlet API, use soklet-servlet-javax.

This library has zero dependencies (not counting Soklet). Just add the JAR to your project and you're good to go.

Note: this README provides a high-level overview of Soklet's Servlet Integration.
For details, please refer to the official documentation at https://www.soklet.com/docs/servlet-integration.

Installation

Like Soklet, this library assumes Java 17+.

Maven

<dependency>
  <groupId>com.soklet</groupId>
  <artifactId>soklet-servlet-jakarta</artifactId>
  <version>1.1.0</version>
</dependency>

Gradle

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.soklet:soklet-servlet-jakarta:1.1.0'
}

Usage

A normal Servlet API integration looks like the following:

  1. Given a Soklet Request, create both an HttpServletRequest and an HttpServletResponse.
  2. Write whatever is needed to HttpServletResponse
  3. Convert the HttpServletResponse to a Soklet MarshaledResponse
@GET("/servlet-example")
public MarshaledResponse servletExample(Request request) {
  // Create an HttpServletRequest from the Soklet Request
  HttpServletRequest httpServletRequest =
    SokletHttpServletRequest.fromRequest(request);

  // Create an HttpServletResponse from the HttpServletRequest
  SokletHttpServletResponse httpServletResponse = 
    SokletHttpServletResponse.fromRequest(httpServletRequest);

  // Write some data to the response using Servlet APIs
  Cookie cookie = new Cookie("name", "value");
  cookie.setDomain("soklet.com");
  cookie.setMaxAge(60);
  cookie.setPath("/");

  httpServletResponse.setStatus(200);
  httpServletResponse.addHeader("test", "one");
  httpServletResponse.addHeader("test", "two");
  httpServletResponse.addCookie(cookie);
  httpServletResponse.setCharacterEncoding("ISO-8859-1");
  httpServletResponse.getWriter().print("test");    
  
  // Convert HttpServletResponse into a Soklet MarshaledResponse and return it
  return httpServletResponse.toMarshaledResponse();
}

Additional documentation is available at https://www.soklet.com/docs/servlet-integration.

About

Soklet Servlet Integration (jakarta.servlet)

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages