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:
HttpServletRequestHttpServletResponseHttpSessionHttpSessionContext(only available forjavax.servlet)ServletContextServletInputStreamServletOutputStreamServletPrintWriter
This library is for the legacy javax.servlet API. If you need to integrate with the jakarta.servlet API, use soklet-servlet-jakarta.
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.
Like Soklet, this library assumes Java 17+.
<dependency>
<groupId>com.soklet</groupId>
<artifactId>soklet-servlet-javax</artifactId>
<version>1.1.0</version>
</dependency>repositories {
mavenCentral()
}
dependencies {
implementation 'com.soklet:soklet-servlet-javax:1.1.0'
}A normal Servlet API integration looks like the following:
- Given a Soklet
Request, create both anHttpServletRequestand anHttpServletResponse. - Write whatever is needed to
HttpServletResponse - Convert the
HttpServletResponseto a SokletMarshaledResponse
@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.