Skip to content

Commit

Permalink
Added protocol package and custom HttpHeaders implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jun 16, 2020
1 parent cf6d3c9 commit b131119
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Proteus Changelog.
## Unreleased
### No issue

**Break out XmlModule**


[cf6d3c9b4a93457](https://github.com/noboomu/proteus/commit/cf6d3c9b4a93457) Joshua Bauer *2020-05-15 00:05:32*

**Incorrect File.sep() use - broken on Windows.**

* On Windows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public ProteusApplication addDefaultRoutes(RoutingHandler router)
this.registeredEndpoints.add(EndpointInfo.builder().withConsumes("*/*").withProduces("text/plain").withPathTemplate(statusPath).withControllerName("Internal").withMethod(Methods.GET).build());

} catch (Exception e) {
log.error("Error adding health status route.", e.getMessage());
log.error("Error adding health status route.", e);
}
}

Expand Down Expand Up @@ -426,12 +426,12 @@ public ProteusApplication addDefaultRoutes(RoutingHandler router)

router.add(Methods.GET, "favicon.ico", (final HttpServerExchange exchange) ->
{
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, io.sinistral.proteus.server.MediaType.IMAGE_X_ICON.toString());
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, io.sinistral.proteus.protocol.MediaType.IMAGE_X_ICON.toString());
exchange.getResponseSender().send(faviconImageBuffer);
});

} catch (Exception e) {
log.error("Error adding favicon route.", e.getMessage());
log.error("Error adding favicon route.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package io.sinistral.proteus.protocol;

/**
* Base copied from org.apache.http.HttpHeaaders
*/

public final class HttpHeaders {
public static final String ACCEPT = "Accept";
public static final String ACCEPT_CH = "Accept-CH";
public static final String ACCEPT_CHARSET = "Accept-Charset";
public static final String ACCEPT_CH_LIFETIME = "Accept-CH-Lifetime";
public static final String ACCEPT_ENCODING = "Accept-Encoding";
public static final String ACCEPT_LANGUAGE = "Accept-Language";
public static final String ACCEPT_PUSH_POLICY = "Accept-Push-Policy";
public static final String ACCEPT_RANGES = "Accept-Ranges";
public static final String ACCEPT_SIGNATURE = "Accept-Signature";
public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
public static final String ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static final String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
public static final String ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
public static final String ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
public static final String ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
public static final String AGE = "Age";
public static final String ALLOW = "Allow";
public static final String ALT_SVC = "Alt-Svc";
public static final String AUDIO = "audio";
public static final String AUDIOWORKLET = "audioworklet";
public static final String AUTHORIZATION = "Authorization";
public static final String Access_Control_Allow_Headers = "Access-Control-Allow-Headers";
public static final String CACHE_CONTROL = "Cache-Control";
public static final String CLEAR_SITE_DATA = "Clear-Site-Data";
public static final String CONNECTION = "Connection";
public static final String CONTENT_DISPOSITION = "Content-Disposition";
public static final String CONTENT_DPR = "Content-DPR";
public static final String CONTENT_ENCODING = "Content-Encoding";
public static final String CONTENT_LANGUAGE = "Content-Language";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_LOCATION = "Content-Location";
public static final String CONTENT_MD5 = "Content-MD5";
public static final String CONTENT_RANGE = "Content-Range";
public static final String CONTENT_SECURITY_POLICY = "Content-Security-Policy";
public static final String CONTENT_SECURITY_POLICY_REPORT_ONLY = "Content-Security-Policy-Report-Only";
public static final String CONTENT_TYPE = "Content-Type";
public static final String COOKIE = "Cookie";
public static final String COOKIE2 = "Cookie2";
public static final String CORS = "cors";
public static final String CROSSDOMAIN_XML = "crossdomain.xml";
public static final String CROSS_ORIGIN_EMBEDDER_POLICY = "Cross-Origin-Embedder-Policy";
public static final String CROSS_ORIGIN_OPENER_POLICY = "Cross-Origin-Opener-Policy";
public static final String CROSS_ORIGIN_RESOURCE_POLICY = "Cross-Origin-Resource-Policy";
public static final String CROSS_SITE = "cross-site";
public static final String DATE = "Date";
public static final String DAV = "Dav";
public static final String DEPTH = "Depth";
public static final String DESTINATION = "Destination";
public static final String DEVICE_MEMORY = "Device-Memory";
public static final String DNT = "DNT";
public static final String DOCUMENT = "document";
public static final String DPR = "DPR";
public static final String EARLY_DATA = "Early-Data";
public static final String EMBED = "<embed>";
public static final String EMPTY = "empty";
public static final String ETAG = "ETag";
public static final String EXPECT = "Expect";
public static final String EXPECT_CT = "Expect-CT";
public static final String EXPIRES = "Expires";
public static final String FEATURE_POLICY = "Feature-Policy";
public static final String FONT = "font";
public static final String FORWARDED = "Forwarded";
public static final String FRAME = "<frame>";
public static final String FROM = "From";
public static final String HOST = "Host";
public static final String HTTP_EQUIV = "http-equiv";
public static final String IF = "If";
public static final String IFRAME = "<iframe>";
public static final String IF_MATCH = "If-Match";
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
public static final String IF_NONE_MATCH = "If-None-Match";
public static final String IF_RANGE = "If-Range";
public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
public static final String IMAGE = "image";
public static final String KEEP_ALIVE = "Keep-Alive";
public static final String LARGE_ALLOCATION = "Large-Allocation";
public static final String LAST_EVENT_ID = "Last-Event-ID";
public static final String LAST_MODIFIED = "Last-Modified";
public static final String LINK = "Link";
public static final String LOCATION = "Location";
public static final String LOCK_TOKEN = "Lock-Token";
public static final String MANIFEST = "manifest";
public static final String MAX_FORWARDS = "Max-Forwards";
public static final String META = "<meta>";
public static final String NAVIGATE = "navigate";
public static final String NEL = "NEL";
public static final String NESTED_DOCUMENT = "nested-document";
public static final String NESTED_NAVIGATE = "nested-navigate";
public static final String NONE = "none";
public static final String NO_CORS = "no-cors";
public static final String OBJECT = "<object>";
public static final String ORIGIN = "Origin";
public static final String OVERWRITE = "Overwrite";
public static final String PAINTWORKLET = "paintworklet";
public static final String PING_FROM = "Ping-From";
public static final String PING_TO = "Ping-To";
public static final String POST = "POST";
public static final String PRAGMA = "Pragma";
public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";
public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
public static final String PUBLIC_KEY_PINS = "Public-Key-Pins";
public static final String PUBLIC_KEY_PINS_REPORT_ONLY = "Public-Key-Pins-Report-Only";
public static final String PUSH_POLICY = "Push-Policy";
public static final String RANGE = "Range";
public static final String REFERER = "Referer";
public static final String REFERRER_POLICY = "Referrer-Policy";
public static final String REPORT = "report";
public static final String REPORT_TO = "Report-To";
public static final String RETRY_AFTER = "Retry-After";
public static final String SAME_ORIGIN = "same-origin";
public static final String SAME_SITE = "same-site";
public static final String SAVE_DATA = "Save-Data";
public static final String SCRIPT = "script";
public static final String SEC_FETCH_DEST = "Sec-Fetch-Dest";
public static final String SEC_FETCH_MODE = "Sec-Fetch-Mode";
public static final String SEC_FETCH_SITE = "Sec-Fetch-Site";
public static final String SEC_FETCH_USER = "Sec-Fetch-User";
public static final String SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept";
public static final String SEC_WEBSOCKET_EXTENSIONS = "Sec-WebSocket-Extensions";
public static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key";
public static final String SEC_WEBSOCKET_PROTOCOL = "Sec-WebSocket-Protocol";
public static final String SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
public static final String SERVER = "Server";
public static final String SERVER_TIMING = "Server-Timing";
public static final String SERVICEWORKER = "serviceworker";
public static final String SERVICE_WORKER_ALLOWED = "Service-Worker-Allowed";
public static final String SET_COOKIE = "Set-Cookie";
public static final String SET_COOKIE2 = "Set-Cookie2";
public static final String SHAREDWORKER = "sharedworker";
public static final String SIGNATURE = "Signature";
public static final String SIGNED_HEADERS = "Signed-Headers";
public static final String SOURCEMAP = "SourceMap";
public static final String STATUS_URI = "Status-URI";
public static final String STRICT_TRANSPORT_SECURITY = "Strict-Transport-Security";
public static final String STYLE = "style";
public static final String TE = "TE";
public static final String TIMEOUT = "Timeout";
public static final String TIMING_ALLOW_ORIGIN = "Timing-Allow-Origin";
public static final String TK = "Tk";
public static final String TRACK = "track";
public static final String TRAILER = "Trailer";
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
public static final String UPGRADE = "Upgrade";
public static final String UPGRADE_INSECURE_REQUESTS = "Upgrade-Insecure-Requests";
public static final String USER_AGENT = "User-Agent";
public static final String VARY = "Vary";
public static final String VIA = "Via";
public static final String VIDEO = "video";
public static final String VIEWPORT_WIDTH = "Viewport-Width";
public static final String WARNING = "Warning";
public static final String WEBSOCKET = "websocket";
public static final String WIDTH = "Width";
public static final String WORKER = "worker";
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
public static final String XSLT = "xslt";
public static final String X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options";
public static final String X_DNS_PREFETCH_CONTROL = "X-DNS-Prefetch-Control";
public static final String X_DOWNLOAD_OPTIONS = "X-Download-Options";
public static final String X_FIREFOX_SPDY = "X-Firefox-Spdy";
public static final String X_FORWARDED_FOR = "X-Forwarded-For";
public static final String X_FORWARDED_HOST = "X-Forwarded-Host";
public static final String X_FORWARDED_PROTO = "X-Forwarded-Proto";
public static final String X_FRAME_OPTIONS = "X-Frame-Options";
public static final String X_PERMITTED_CROSS_DOMAIN_POLICIES = "X-Permitted-Cross-Domain-Policies";
public static final String X_PINGBACK = "X-Pingback";
public static final String X_POWERED_BY = "X-Powered-By";
public static final String X_REQUESTED_WITH = "X-Requested-With";
public static final String X_ROBOTS_TAG = "X-Robots-Tag";
public static final String X_UA_COMPATIBLE = "X-UA-Compatible";
public static final String X_XSS_PROTECTION = "X-XSS-Protection";

private HttpHeaders() {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package io.sinistral.proteus.server;
package io.sinistral.proteus.protocol;

/**
* @author jbauer
Expand All @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MediaType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.inject.Inject;
import io.sinistral.proteus.protocol.MediaType;
import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.sinistral.proteus.wrappers.JsonViewWrapper;
import io.undertow.io.IoCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package io.sinistral.proteus.server.predicates;

import io.sinistral.proteus.server.MediaType;
import io.sinistral.proteus.protocol.MediaType;
import io.undertow.attribute.ExchangeAttributes;
import io.undertow.predicate.Predicate;
import io.undertow.predicate.Predicates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ protected void startUp() throws Exception
{
log.info("Starting " + this.getClass().getSimpleName());
}



}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,18 @@ private Operation parseMethod(
operation.setOperationId(getOperationId(method.getName()));
}

/*
if (StringUtils.isBlank(operation.getOperationId()))
{
String className = toLowerCase(method.getDeclaringClass().getSimpleName().charAt(0)) + method.getDeclaringClass().getSimpleName().substring(1);
String operationId = String.format("%s%s",className,toUpperCase(method.getName().charAt(0)) + method.getName().substring(1));
operation.setOperationId(operationId);
}
*/

// classResponses
if (classResponses != null && classResponses.length > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public RoutingHandler get()

router.add( HttpMethod.GET, pathTemplate, (HttpServerExchange exchange) ->
{
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, io.sinistral.proteus.server.MediaType.TEXT_YAML.contentType());
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, io.sinistral.proteus.protocol.MediaType.TEXT_YAML.contentType());

exchange.getResponseSender().send(spec);
});
Expand All @@ -335,7 +335,7 @@ public RoutingHandler get()
.withPathTemplate(pathTemplate)
.withControllerName(this.getClass().getSimpleName())
.withMethod(Methods.GET)
.withProduces(io.sinistral.proteus.server.MediaType.TEXT_YAML.contentType())
.withProduces(io.sinistral.proteus.protocol.MediaType.TEXT_YAML.contentType())
.build());


Expand Down Expand Up @@ -412,7 +412,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception

byte[] resourceBytes = IOUtils.toByteArray(resourceInputStream);

io.sinistral.proteus.server.MediaType mediaType = io.sinistral.proteus.server.MediaType.getByFileName(canonicalPath);
io.sinistral.proteus.protocol.MediaType mediaType = io.sinistral.proteus.protocol.MediaType.getByFileName(canonicalPath);

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, mediaType.toString());
exchange.getResponseSender().send(ByteBuffer.wrap(resourceBytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public RoutingHandler get()

router.add(HttpMethod.GET, pathTemplate, (HttpServerExchange exchange) ->
{
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, io.sinistral.proteus.server.MediaType.TEXT_YAML.contentType());
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, io.sinistral.proteus.protocol.MediaType.TEXT_YAML.contentType());

String spec = null;

Expand All @@ -481,7 +481,7 @@ public RoutingHandler get()

this.registeredEndpoints.add(
EndpointInfo.builder().withConsumes("*/*").withPathTemplate(pathTemplate).withControllerName(this.getClass().getSimpleName())
.withMethod(Methods.GET).withProduces(io.sinistral.proteus.server.MediaType.TEXT_YAML.contentType()).build());
.withMethod(Methods.GET).withProduces(io.sinistral.proteus.protocol.MediaType.TEXT_YAML.contentType()).build());

pathTemplate = this.basePath + "/" + this.redocPath;

Expand Down Expand Up @@ -544,7 +544,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception

byte[] resourceBytes = IOUtils.toByteArray(resourceInputStream);

io.sinistral.proteus.server.MediaType mediaType = io.sinistral.proteus.server.MediaType.getByFileName(canonicalPath);
io.sinistral.proteus.protocol.MediaType mediaType = io.sinistral.proteus.protocol.MediaType.getByFileName(canonicalPath);

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, mediaType.toString());

Expand Down

0 comments on commit b131119

Please sign in to comment.