gmugra / net.cactusthorn.routing Goto Github PK
View Code? Open in Web Editor NEWLightweight JAX-RS implementation for HTTP requests routing
License: BSD 3-Clause "New" or "Revised" License
Lightweight JAX-RS implementation for HTTP requests routing
License: BSD 3-Clause "New" or "Revised" License
SUBJ.
RoutingConfig must support javax.ws.rs.core.Application as an initialisation source:
ComponentProvider provider = ... ;
RoutingConfig config = RoutingConfig.builder(provider).setApplication(MyApplication.class).build();
Warning: getSingletons() also contains singltones-resources, not only providers.
FYI: https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/content/en/part1/chapter4/path.html (see "Precedence rules")
Using public static methods is not a good style.
FYI : https://docs.oracle.com/javaee/7/api/javax/ws/rs/container/ResourceInfo.html
javax.ws.rs.container.ResourceInfo
in constructor instead of clazz & methodSUBJ.
needs a new method setIOBufferSize to set buffer size, which is used to read/write data from the input/output streams.
The buffer size is now hardcoded with a value of 1024 (which should be the default value).
It is not critical for the major goals of the library, but nice to have. To be more JAX-RS compatible.
(At the moment UriBuilder related methods throw UnsupportedOperationException)
DO TO
Specification:
Binds the value(s) of a HTTP header to a resource method parameter, resource class field, or resource class bean property. A default value can be specified using the DefaultValue annotation. The type T of the annotated parameter, field or property must either:
- Be a primitive type
- Have a constructor that accepts a single String argument
- Have a static method named valueOf or fromString that accepts a single String argument (see, for example, > Integer.valueOf(String))
- Have a registered implementation of ParamConverterProvider JAX-RS extension SPI that returns a ParamConverter instance capable of a "from string" conversion for the type.
- Be List<T>, Set<T> or SortedSet<T>, where T satisfies 2, 3 or 4 above. The resulting collection is read-only.
Need it to support javax.ws.rs.core.Cookie, which need to solve #15 and #2
Specification RFC 2109:
The syntax for the header is:
cookie = "Cookie:" cookie-version
1*((";" | ",") cookie-value)
cookie-value = NAME "=" VALUE [";" path] [";" domain]
cookie-version = "$Version" "=" value
NAME = attr
VALUE = value
path = "$Path" "=" value
domain = "$Domain" "=" value
4.4 How an Origin Server Interprets the Cookie Header
A user agent returns much of the information in the Set-Cookie header
to the origin server when the Path attribute matches that of a new
request. When it receives a Cookie header, the origin server should
treat cookies with NAMEs whose prefix is $ specially, as an attribute
for the adjacent cookie. The value for such a NAME is to be
interpreted as applying to the lexically (left-to-right) most recent
cookie whose name does not have the $ prefix. If there is no
previous cookie, the value applies to the cookie mechanism as a
whole. For example, consider the cookieCookie: $Version="1"; Customer="WILE_E_COYOTE";
$Path="/acme"$Version applies to the cookie mechanism as a whole (and gives the
version number for the cookie mechanism). $Path is an attribute
whose value (/acme) defines the Path attribute that was used when the
Customer cookie was defined in a Set-Cookie response header.
@Context
Now:
@GET @Path("upload")
public Response showUpload(@Context HttpServletRequest request, @Context HttpServletResponse response) {
Templated templated = new Templated(request, response, "/fileupload.html", null);
return Response.ok(templated).type(MediaType.TEXT_HTML_TYPE).build();
}
Should be:
@GET @Path("upload")
public Response showUpload() {
Templated templated = new Templated("/fileupload.html");
return Response.ok(templated).type(MediaType.TEXT_HTML_TYPE).build();
}
should work:
@GET
public String getAllOrders(@Context Application app) {
Map<String, Object> properties = app.getProperties();
}
RoutingConfig
internally should keep javax.ws.rs.core.Application instance.RoutingConfig
should provide methods to specify providers from Class
addBodyWriter(SimpleGsonBodyWriter.class)
RoutingConfig
should provide new method putApplicationProperty
, related to javax.ws.rs.core.Application -> getProperties() methodThe method was implemeneted as alternative for javax.ws.rs.ApplicationPath
annotation.
ApplicationPath javadoc:
Identifies the application path that serves as the base URI for all resource URIs provided by Path.
May only be applied to a subclass of Application.
When published in a Servlet container, the value of the application path may be overridden using a servlet-mapping element in the web.xml.
BUT.
The library is planned to be used only in combination with embadded Servlet container.
So, always exists servlet-mapping. And as result ApplicationPath should always be ignored.
Fact that exists RoutingConfig.applicationPath() method is conceptual bug.
FYI: https://www.logicbig.com/tutorials/java-ee-tutorial/jax-rs/context-resolver.html
e.g.
@GET
public String create(@Context Providers providers) {
ContextResolver<MyContext> cr = providers.getContextResolver(MyContext.class, MediaType.WILDCARD_TYPE);
...
}
TODO
ContextResolver
implementation may be annotated with @Produces
to restrict the media types for which it will be considered suitable. Default: MediaType.WILDCARD_TYPE
@javax.annotation.Priority
, like other providers. Why not?SUBJ.
Also the implementation of javax.ws.rs.ext.Providers
should be used internally in the RoutingConfig (instead of collections with providers)
FYI: https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/Providers.html
SUBJ.
Change the integration of LICENCE file in the JARs
same way with : Gmugra/net.cactusthorn.config#176
Specification:
An implementation MUST include pre-packaged
MessageBodyReader
andMessageBodyWriter
implementations for the following Java and media type combinations:
byte[]
- All media types ( */* ).
java.lang.String
- All media types ( */* ).
java.io.InputStream
- All media types ( */* ).
java.io.Reader
- All media types ( */* ).
java.io.File
- All media types ( */* ).
javax.activation.DataSource
- All media types ( */* ).
javax.xml.transform.Source
- XML types ( text/xml , application/xml and media types of the form application/*+xml).
javax.ws.rs.core.MultivaluedMap<String,String>
- Form content ( application/x-www-form-urlencoded ).
javax.ws.rs.core.StreamingOutput
- All media types ( */* ),
MessageBodyWriter
onlyjava.lang.Boolean
,java.lang.Character
,java.lang.Number
- Only for text/plain. Corresponding primitive types supported via boxing/unboxing conversion.
FYI:
ConvertersMessageBodyReader
/ObjectMessageBodyWriter
)At the moment, the messages simple hard-coded, which is not nice.
TODO: some simple-to-use solution based on ResourceBundle
& MessageFormat
should work e.g.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response processForm(@HeaderParam("X-type") String type, Form form) {
...
}
At the moment @CookieParam
support only javax.servlet.http.Cookie
which is primitive and wrong accorting to JAX-RS specification.
https://jakarta.ee/specifications/platform/8/apidocs/javax/ws/rs/cookieparam :
public
@interface
CookieParamBinds the value of a HTTP cookie to a resource method parameter, resource class field, or resource class bean property. A default value can be specified using the
@DefaultValue
annotation. The type T of the annotated parameter, field or property must either:
- Be a primitive type
- Be
javax.ws.rs.core.Cookie
- Have a constructor that accepts a single String argument
- Have a static method named valueOf or fromString that accepts a single String argument (see, for example, Integer.valueOf(String))
- Have a registered implementation of ParamConverterProvider JAX-RS extension SPI that returns a ParamConverter instance capable of a "from string" conversion for the type.
- Be List<T>, Set<T> or SortedSet<T>, where T satisfies 2, 3, 4 or 5 above. The resulting collection is read-only.
About Exceptions:
if the field or property is
annotated with @HeaderParam or @CookieParam then an implementation MUST generate an instance of
BadRequestException (400 status) that wraps the thrown exception and no entity.
By default, the JAX-RS runtime will automatically support the methods HEAD and OPTIONS if not explicitly implemented. For HEAD, the runtime will invoke the implemented GET method, if present, and ignore the response entity, if set. For OPTIONS, the Allow response header will be set to the set of HTTP methods supported by the resource.
Resource-methods with same http-method & path but different @Produces
are not mapped correctly.
e.g.
@Path("/customers")
public class CustomerResource {
@GET
@Path("{id}")
@Produces("application/xml")
public Customer getCustomerXml(@PathParam("id") int id) {...}
@GET
@Path("{id}")
@Produces("text/plain")
public String getCustomerText(@PathParam("id") int id) {...}
@GET
@Path("{id}")
@Produces("application/json")
public Customer getCustomerJson(@PathParam("id") int id) {...}
}
From JSR-339 specification:
Valid parameter types for each of the above annotations are listed in the corresponding Javadoc, however in
general (excluding@Context
) the following types are supported:
- Types for which a ParamConverter is available via a registered ParamConverterProvider. See
Javadoc for these classes for more information.- Primitive types.
- Types that have a constructor that accepts a single String argument.
- Types that have a static method named valueOf or fromString with a single String argument
that return an instance of the type. If both methods are present then valueOf MUST be used unless
the type is an enum in which case fromString MUST be used.- List<T>, Set<T>, or SortedSet<T>, where T satisfies 3 or 4 above. The resulting collection is read-only.
The DefaultValue annotation may be used to supply a default value for some of the above, see the Javadoc
for DefaultValue for usage details and rules for generating a value in the absence of this annotation and
the requested data. The Encoded annotation may be used to disable automatic URI decoding for@MatrixParam
,@QueryParam
, and@PathParam
annotated fields and properties.A WebApplicationException thrown during construction of field or property values using 3 or 4 above
is processed directly as described in Section 3.3.4. Other exceptions thrown during construction of field
or property values using 3 or 4 above are treated as client errors: if the field or property is annotated with
@MatrixParam
,@QueryParam
or@PathParam
then an implementation MUST generate an instance of
NotFoundException (404 status) that wraps the thrown exception and no entity; if the field or property is
annotated with@HeaderParam
or@CookieParam
then an implementation MUST generate an instance of
BadRequestException (400 status) that wraps the thrown exception and no entity. Exceptions MUST be
processed as described in Section 3.3.4
So:
@MatrixParam
, @QueryParam
or @PathParam
-> 404@HeaderParam
or @CookieParam
-> 400@FormParam
?In fact, all of this is a simplification compared to what is currently implemented...
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
@Context
should support javax.ws.rs.core.SecurityContext@Context
should NOT support java.security.PrincipalAt the moment the library only supports "pre-defined" HttpMethods:
@DELETE
, @GET
, @HEAD
, @OPTIONS
, @POST
, @PUT
, @PATCH
That's not quite right. It should support any "method" which is defined with meta-annotation @HttpMethod
.
e.g.
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("LOCK")
public @interface LOCK {
}
SUBJ.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
org.slf4j:jul-to-slf4j
, org.slf4j:slf4j-api
)com.google.dagger:dagger
, com.google.dagger:dagger-compiler
)org.apache.maven.plugins:maven-failsafe-plugin
, org.apache.maven.plugins:maven-surefire-plugin
)org.eclipse.jetty:jetty-servlet
, org.eclipse.jetty:jetty-server
)org.slf4j:jul-to-slf4j
, org.slf4j:slf4j-api
)These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
org.eclipse.jetty:jetty-servlet
, org.eclipse.jetty:jetty-server
)org.junit.jupiter:junit-jupiter-params
, org.junit.jupiter:junit-jupiter-engine
, org.junit.jupiter:junit-jupiter-api
)org.mockito:mockito-junit-jupiter
, org.mockito:mockito-core
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/maven.yml
actions/checkout v2
actions/setup-java v2
actions/cache v2
core/pom.xml
demo-jetty/pom.xml
json-gson/pom.xml
pom.xml
com.google.dagger:dagger-compiler 2.40.5
javax.servlet:javax.servlet-api 3.1.0
javax.ws.rs:javax.ws.rs-api 2.1.1
javax.annotation:javax.annotation-api 1.3.2
com.google.code.gson:gson 2.8.9
org.thymeleaf:thymeleaf 3.0.14.RELEASE
org.hibernate.validator:hibernate-validator 6.2.0.Final
org.glassfish:javax.el 3.0.1-b12
org.eclipse.jetty:jetty-server 9.4.43.v20210629
org.eclipse.jetty:jetty-servlet 9.4.43.v20210629
com.google.dagger:dagger 2.40.5
org.slf4j:slf4j-api 1.7.32
org.slf4j:jul-to-slf4j 1.7.32
ch.qos.logback:logback-classic 1.2.6
org.junit.jupiter:junit-jupiter-api 5.8.1
org.junit.jupiter:junit-jupiter-engine 5.8.1
org.junit.jupiter:junit-jupiter-params 5.8.1
org.mockito:mockito-core 3.12.4
org.mockito:mockito-junit-jupiter 3.12.4
org.apache.maven.plugins:maven-assembly-plugin 3.3.0
org.apache.maven.plugins:maven-dependency-plugin 3.2.0
org.apache.maven.plugins:maven-compiler-plugin 3.8.1
org.apache.maven.plugins:maven-resources-plugin 3.2.0
org.apache.maven.plugins:maven-surefire-plugin 3.0.0-M5
org.apache.maven.plugins:maven-failsafe-plugin 3.0.0-M5
org.apache.maven.plugins:maven-clean-plugin 3.1.0
org.apache.maven.plugins:maven-install-plugin 3.0.0-M1
org.apache.maven.plugins:maven-javadoc-plugin 3.3.1
org.apache.maven.plugins:maven-deploy-plugin 3.0.0-M1
org.apache.maven.plugins:maven-release-plugin 3.0.0-M4
org.codehaus.mojo:flatten-maven-plugin 1.2.7
org.apache.maven.plugins:maven-gpg-plugin 3.0.1
org.sonatype.plugins:nexus-staging-maven-plugin 1.6.8
org.apache.maven.plugins:maven-jar-plugin 3.2.0
org.jacoco:jacoco-maven-plugin 0.8.7
org.eluder.coveralls:coveralls-maven-plugin 4.3.0
org.glassfish.jaxb:jaxb-runtime 2.3.5
org.apache.maven.plugins:maven-source-plugin 3.2.1
com.github.spotbugs:spotbugs-maven-plugin 4.4.2.2
com.github.spotbugs:spotbugs 4.4.0
org.apache.maven.plugins:maven-pmd-plugin 3.14.0
org.apache.maven.plugins:maven-jxr-plugin 3.1.1
org.apache.maven.plugins:maven-site-plugin 3.9.1
org.apache.maven.plugins:maven-project-info-reports-plugin 3.1.2
org.apache.maven.plugins:maven-checkstyle-plugin 3.1.2
com.puppycrawl.tools:checkstyle 9.1
org.apache.maven.plugins:maven-enforcer-plugin 3.0.0
thymeleaf/pom.xml
validation-javax/pom.xml
When the generic type is required to select a suitable MessageBodyWriter
, this class may be used to wrap the entity and capture its generic type.
e.g.
List<String> list = new ArrayList<String>();
GenericEntity<List<String>> entity = new GenericEntity<List<String>>(list) {};
Response response = Response.ok(entity).build();
FYI: need to add support in RoutingServlet
Root resource classes are "plain old Java objects" (POJOs) that are either annotated with
@Path
or have at least one method annotated with@Path
or a request method designator, such as@GET
,@PUT
,@POST
, or@DELETE
.
The addResource methods must throw IllegalArgumentException
, when parameter is null or not fit requirements for Root resource classes.
FYI: methods annotated with @Path
, but with no HTTP method annotation is Subresource Locator. At the moment the library not support it, so such kind of declaration should be ignored.
Convert/check @DefaultValue
during the initialization phase:
ParamConverter.Lazy
concept is not part of this issueAlso be sure:
If the type of the annotated parameter is
List
,Set
orSortedSet
then the resulting collection will have a single entry mapped from the supplied default value.
If this annotation is not used and the corresponding meta-data is not present in the request, the value will be an empty collection for
List
,Set
orSortedSet
, null for other object types, and the Java-defined default for primitive types.
The literal part of the supplied value (those characters that are not part of a template parameter) is automatically percent encoded to conform to the path production of RFC 3986 section 3.3. Note that percent encoded values are allowed in the literal part of the value, an implementation will recognize such values and will not double encode the '%' character.
RFC 3986:
path = path-abempty ; begins with "/" or is empty / path-absolute ; begins with "/" but not "//" / path-noscheme ; begins with a non-colon segment / path-rootless ; begins with a segment / path-empty ; zero characters path-abempty = *( "/" segment ) path-absolute = "/" [ segment-nz *( "/" segment ) ] path-noscheme = segment-nz-nc *( "/" segment ) path-rootless = segment-nz *( "/" segment ) path-empty = 0<pchar> segment = *pchar segment-nz = 1*pchar segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) ; non-zero-length segment without any colon ":" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
HttpServletRequest#getPathInfo:
Returns:
a String, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or null if the URL does not have any extra path information
FYI: net.cactusthorn.routing.uri.UriComponentEncoder
At the moment, it's not about 100% full implementation.
Next methods not need to be implemented:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.