Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: JAX-RS Dispatcher #88

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions gemini-jax-rs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

<organization>
<name>TechEmpower, Inc.</name>
<url>https://www.techempower.com/</url>
</organization>

<licenses>
<license>
<name>Revised BSD License, 3-clause</name>
<distribution>repo</distribution>
</license>
</licenses>

<parent>
<artifactId>gemini-parent</artifactId>
<groupId>com.techempower</groupId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>gemini-jax-rs</artifactId>
<description>
An extension for Gemini that provides dispatching implemented as a subset of JAX-RS.
</description>

<dependencies>
<dependency>
<groupId>com.techempower</groupId>
<artifactId>gemini</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<!--
TODO: Remove this once performance testing is done, or can be done from the unit tests
where this can be a test dependency
-->
<groupId>com.caucho</groupId>
<artifactId>resin</artifactId>
<optional>false</optional>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.techempower.gemini.jaxrs.core;

public class CharSpan implements CharSequence
{
private final CharSequence charSequence;
private final int start;
private final int end;
private int hash = 1;
private String toString;

CharSpan(CharSequence charSequence, int start, int end)
{
this.charSequence = charSequence;
this.start = start;
this.end = end;
}

CharSpan(String string)
{
this(string, 0, string.length());
this.toString = string;
}

public int getStart()
{
return start;
}

public int getEnd()
{
return end;
}

@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
CharSpan charSpan = (CharSpan) o;
int length = length();
if (length != charSpan.length())
{
return false;
}
for (int i = 0; i < length; i++)
{
if (charAt(i) != charSpan.charAt(i))
{
return false;
}
}
return true;
}

@Override
public int hashCode()
{
if (hash == 1 && length() > 0)
{
int h = 1;
for (int i = end - 1; i >= start; i--)
{
h = 31 * h + charAt(i - start);
}
hash = h;
}
return hash;
}

@Override
public int length()
{
return end - start;
}

@Override
public char charAt(int index)
{
return charSequence.charAt(start + index);
}

@Override
public CharSequence subSequence(int start, int end)
{
if (start == 0 && end == length())
{
return this;
}
return charSequence.subSequence(this.start + start, this.start + end);
}

@Override
public String toString()
{
if (toString == null)
{
toString = charSequence.subSequence(start, end).toString();
}
return toString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.techempower.gemini.jaxrs.core;

import java.util.List;
import java.util.Map;

public interface Endpoint
{
// TODO: Will likely want to change this to something more meaningful, like
// UriPathInfo or whatever it's called
Object invoke(String httpMethod,
String uri,
List<Map.Entry<String, String>> headers,
Map<String, String> pathParams,
Map<String, String> queryParams,
String body);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.techempower.gemini.jaxrs.core;

import java.util.Set;

public class EndpointMetadata
{
private final String path;
private final Set<String> httpMethods;
private final QMediaTypeGroup mediaTypeConsumes;
private final QMediaTypeGroup mediaTypeProduces;

public EndpointMetadata(String path,
Set<String> httpMethods,
QMediaTypeGroup mediaTypeConsumes,
QMediaTypeGroup mediaTypeProduces)
{
this.path = path;
this.httpMethods = httpMethods;
this.mediaTypeConsumes = mediaTypeConsumes;
this.mediaTypeProduces = mediaTypeProduces;
}

public String getPath()
{
return path;
}

public Set<String> getHttpMethods()
{
return httpMethods;
}

public QMediaTypeGroup getMediaTypeConsumes()
{
return mediaTypeConsumes;
}

public QMediaTypeGroup getMediaTypeProduces()
{
return mediaTypeProduces;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.techempower.gemini.jaxrs.core;

import java.util.List;
import java.util.Map;

public interface EndpointRegistry
{
Endpoint getEndpointFor(String httpMethod,
String uri,
// TODO: Eventually this will all be in a lazy-loaded UriInfo
List<Map.Entry<String, String>> headers);

void register(EndpointMetadata metadata, Endpoint endpoint);
}
Loading