├── .gitignore ├── FAQ.md ├── README.md ├── acteur-annotation-processors ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── annotation │ └── processors │ ├── GuiceModuleAnnotationProcessor.java │ └── HttpCallAnnotationProcessor.java ├── acteur-annotations ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ ├── acteur │ └── annotations │ │ ├── GeneratedFrom.java │ │ ├── GuiceModule.java │ │ └── HttpCall.java │ └── parameters │ └── gen │ └── Origin.java ├── acteur-base ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteurbase │ │ ├── AbstractActeur.java │ │ ├── ActeurBaseModule.java │ │ ├── ActeurResponseFactory.java │ │ ├── ActeurState.java │ │ ├── ArrayChain.java │ │ ├── Chain.java │ │ ├── ChainCallback.java │ │ ├── ChainRunner.java │ │ ├── ChainsRunner.java │ │ ├── Deferral.java │ │ ├── InstantiatingIterators.java │ │ └── package.html │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteurbase │ ├── ChainRunnerTest.java │ ├── TestCallback.java │ └── impl │ ├── A2.java │ ├── Response.java │ └── ResponseImpl.java ├── acteur-cookie-auth ├── index-reflection.marker ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── cookie │ └── auth │ ├── AuthCookieWriter.java │ ├── CookieActeur.java │ ├── CookieAuthModule.java │ ├── CookieAuthenticator.java │ ├── CookieAuthenticatorImpl.java │ ├── LoginActeur.java │ ├── LoginInfo.java │ ├── LogoutActeur.java │ ├── SessionTimeout.java │ ├── UserFinder.java │ └── package.html ├── acteur-header-entities ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── header │ └── entities │ ├── BasicCredentials.java │ ├── CacheControl.java │ ├── CacheControlTypes.java │ ├── Connection.java │ ├── ConnectionHeaderData.java │ ├── FrameOptions.java │ ├── StrictTransportSecurity.java │ └── UnknownConnectionHeaderData.java ├── acteur-headers-jodatime ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── headers │ └── jodatime │ ├── JodaCacheControl.java │ ├── JodaCacheControlHeader.java │ ├── JodaCacheControlTypes.java │ ├── JodaDateTimeHeader.java │ ├── JodaDurationHeader.java │ ├── JodaHeaders.java │ └── JodaKeepAliveHeader.java ├── acteur-headers ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ ├── headers │ │ ├── AbstractHeader.java │ │ ├── AccelBufferingHeader.java │ │ ├── AllowHeader.java │ │ ├── ArrayHeaderValueType.java │ │ ├── AuthHeader.java │ │ ├── BasicCredentialsHeader.java │ │ ├── BooleanHeader.java │ │ ├── BoundedRange.java │ │ ├── BoundedRangeNetty.java │ │ ├── ByteRangeHeader.java │ │ ├── ByteRanges.java │ │ ├── CacheControlHeader.java │ │ ├── CharSequenceHeader.java │ │ ├── CharsetHeader.java │ │ ├── ConnectionHeader.java │ │ ├── ContentRangeHeader.java │ │ ├── CookieHeader.java │ │ ├── CookieHeaderNetty428.java │ │ ├── DateTimeHeader.java │ │ ├── DurationHeader.java │ │ ├── ETagHeader.java │ │ ├── FrameOptionsHeader.java │ │ ├── HeaderNamesHeader.java │ │ ├── HeaderValueType.java │ │ ├── Headers.java │ │ ├── InstantHeader.java │ │ ├── IntHeader.java │ │ ├── KeepAliveHeader.java │ │ ├── LocaleHeader.java │ │ ├── LongHeader.java │ │ ├── Method.java │ │ ├── MimeTypeHeader.java │ │ ├── NumberHeader.java │ │ ├── PragmaHeader.java │ │ ├── Range.java │ │ ├── SetCookieHeader.java │ │ ├── SetCookieHeaderNetty428.java │ │ ├── StrictTransportSecurityHeader.java │ │ ├── StringArrayHeader.java │ │ ├── StringHeader.java │ │ ├── TimestampHeader.java │ │ ├── UriHeader.java │ │ ├── VaryHeader.java │ │ ├── WebSocketLocationHeader.java │ │ └── WebSocketProtocolsHeader.java │ │ └── request │ │ └── HttpProtocolRequest.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── headers │ ├── AbstractHeaderTest.java │ ├── ByteRangesTest.java │ ├── CookieHeaderNetty428Test.java │ ├── DateHeaderTest.java │ ├── ETagHeaderTest.java │ ├── FrameOptionsHeaderTest.java │ ├── PragmaHeaderTest.java │ ├── StrictTransportSecurityHeaderTest.java │ └── TimestampHeaderTest.java ├── acteur-jdbc ├── index-reflection.marker ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── jdbc │ ├── ResultSetWriter.java │ ├── ResultSetWriterActeur.java │ └── ResultSetWriterFactory.java ├── acteur-mongo-async ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── mongo │ │ └── async │ │ ├── ActeurMongoModule.java │ │ ├── ByteBufCodec.java │ │ ├── CacheHeaderInfo.java │ │ ├── ConstantBuffers.java │ │ ├── CursorControl.java │ │ ├── CursorWriter.java │ │ ├── CursorWriterFactory.java │ │ ├── JacksonCodec.java │ │ ├── JacksonCodecs.java │ │ ├── MongoUpdater.java │ │ ├── ObjectIdJacksonConfigurer.java │ │ ├── ObjectIdToJSONConfigurer.java │ │ ├── PlainJsonWriter.java │ │ ├── QueryActeur.java │ │ ├── QueryWithCacheHeadersActeur.java │ │ └── WriteCursorContentsAsJSON.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── mongo │ └── async │ ├── ActeurAsyncTest.java │ ├── ByteBufCodecTest.java │ ├── DynamicCodecsTest.java │ ├── Java8TimeSerializationTest.java │ ├── LocaleSerializationTest.java │ ├── SRC.java │ └── TestBsonArrays.java ├── acteur-mongo-reactive ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── mongo │ │ └── reactive │ │ ├── ActeurMongoModule.java │ │ ├── ByteBufCodec.java │ │ ├── CacheHeaderInfo.java │ │ ├── ConstantBuffers.java │ │ ├── CursorControl.java │ │ ├── CursorWriter.java │ │ ├── CursorWriterFactory.java │ │ ├── ETagResult.java │ │ ├── EtagEvaluator.java │ │ ├── JacksonCodec.java │ │ ├── JacksonCodecs.java │ │ ├── MongoUpdater.java │ │ ├── ObjectIdJacksonConfigurer.java │ │ ├── ObjectIdToJSONConfigurer.java │ │ ├── PlainJsonWriter.java │ │ ├── QueryActeur.java │ │ ├── QueryWithCacheHeadersActeur.java │ │ ├── SubscriberWriter.java │ │ └── WriteCursorContentsAsJSON.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── mongo │ └── reactive │ ├── ActeurAsyncTest.java │ ├── ByteBufCodecTest.java │ ├── DynamicCodecsTest.java │ ├── Java8TimeSerializationTest.java │ ├── LocaleSerializationTest.java │ ├── SRC.java │ ├── SubscriberContextImplTest.java │ └── TestBsonArrays.java ├── acteur-mongo ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── mongo │ │ ├── CursorWriter.java │ │ ├── CursorWriterActeur.java │ │ ├── MongoModule.java │ │ └── util │ │ ├── EventToQuery.java │ │ └── EventToQueryConfig.java │ └── test │ ├── java │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── mongo │ │ ├── MongoDaemonVersion.java │ │ ├── MongoHarness.java │ │ └── MongoModuleTest.java │ └── resources │ └── com │ └── mastfrog │ └── acteur │ └── mongo │ └── MongoModuleTest.properties ├── acteur-resources ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── resources │ │ ├── ClasspathResourceInfo.java │ │ ├── ClasspathResources.java │ │ ├── DefaultExpiresPolicy.java │ │ ├── DefaultStaticResources.java │ │ ├── DynamicFileResources.java │ │ ├── ExpiresPolicy.java │ │ ├── FileResources.java │ │ ├── MergedResources.java │ │ ├── MimeTypes.java │ │ ├── Resource.java │ │ ├── ResourcesPage.java │ │ ├── StaticResources.java │ │ └── markup │ │ ├── MarkupFiles.java │ │ ├── MarkupFilesModule.java │ │ └── package.html │ └── test │ ├── java │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── resources │ │ ├── ResourcesApp.java │ │ └── StaticResourcesTest.java │ └── resources │ └── com │ └── mastfrog │ └── acteur │ └── resources │ ├── StaticResourcesTest.properties │ ├── another.txt │ └── hello.txt ├── acteur-server-sent-events ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── sse │ │ ├── ActeurServerSentEventsModule.java │ │ ├── DefaultMessageRenderer.java │ │ ├── EventChannelName.java │ │ ├── EventSink.java │ │ ├── MessageRenderer.java │ │ └── SseActeur.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── sse │ ├── SilentRequestLogger.java │ ├── SseApp.java │ └── SseTest.java ├── acteur-util ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── util │ │ ├── ErrorHandler.java │ │ ├── ErrorHandlers.java │ │ ├── ErrorInterceptor.java │ │ ├── HttpMethod.java │ │ ├── PasswordHasher.java │ │ ├── Realm.java │ │ ├── RequestID.java │ │ ├── RotatingRealmProvider.java │ │ ├── Server.java │ │ └── ServerControl.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── util │ ├── ErrorHandlerTest.java │ ├── FrameOptionsTest.java │ ├── PasswordHasherTest.java │ ├── RotatingRealmProviderTest.java │ └── StrictTransportSecurityTest.java ├── acteur ├── .attach_pid31540 ├── index-reflection.marker ├── nbactions.xml ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── mastfrog │ │ │ └── acteur │ │ │ ├── Acteur.java │ │ │ ├── ActeurFactory.java │ │ │ ├── Application.java │ │ │ ├── BuiltInPageAnnotationHandler.java │ │ │ ├── CORSResource.java │ │ │ ├── CORSResponseDecorator.java │ │ │ ├── CORSResponseDecoratorImpl.java │ │ │ ├── CheckIfModifiedSinceHeader.java │ │ │ ├── CheckIfNoneMatchHeader.java │ │ │ ├── CheckIfUnmodifiedSinceHeader.java │ │ │ ├── ChunkHandler.java │ │ │ ├── Closables.java │ │ │ ├── ContentConverter.java │ │ │ ├── DefaultRequestLogger.java │ │ │ ├── DeferredComputationResult.java │ │ │ ├── DeferredComputationResultActeur.java │ │ │ ├── ErrorActeur.java │ │ │ ├── Event.java │ │ │ ├── FailureResponseFactory.java │ │ │ ├── Help.java │ │ │ ├── HelpGenerator.java │ │ │ ├── HelpPage.java │ │ │ ├── HttpCallOrOrderedComparator.java │ │ │ ├── HttpEvent.java │ │ │ ├── ImplicitBindings.java │ │ │ ├── OnBeforeEvent.java │ │ │ ├── Page.java │ │ │ ├── PagePathAndMethodFilter.java │ │ │ ├── PagesImpl2.java │ │ │ ├── PathFilters.java │ │ │ ├── PathPatterns.java │ │ │ ├── RequestLogger.java │ │ │ ├── Response.java │ │ │ ├── ResponseDecorator.java │ │ │ ├── ResponseImpl.java │ │ │ ├── ResponseSender.java │ │ │ ├── ResponseWriter.java │ │ │ ├── State.java │ │ │ ├── annotations │ │ │ ├── Concluders.java │ │ │ ├── Early.java │ │ │ ├── GenericApplication.java │ │ │ ├── GenericApplicationModule.java │ │ │ ├── HttpCallRegistryLoader.java │ │ │ ├── InstallChunkHandler.java │ │ │ └── Precursors.java │ │ │ ├── auth │ │ │ ├── AsyncAuthenticationActeur.java │ │ │ ├── AsyncAuthenticationModule.java │ │ │ ├── AsyncAuthenticator.java │ │ │ ├── AuthenticateBasicActeur.java │ │ │ ├── AuthenticationActeur.java │ │ │ ├── AuthenticationResult.java │ │ │ ├── Authenticator.java │ │ │ ├── MockAuthenticator.java │ │ │ ├── SimpleUser.java │ │ │ ├── Tarpit.java │ │ │ ├── TarpitCacheKeyFactory.java │ │ │ └── TarpitImpl.java │ │ │ ├── debug │ │ │ ├── DefaultProbe.java │ │ │ ├── HttpProbe.java │ │ │ └── Probe.java │ │ │ ├── errors │ │ │ ├── Err.java │ │ │ ├── ErrorRenderer.java │ │ │ ├── ErrorResponse.java │ │ │ ├── ExceptionEvaluator.java │ │ │ ├── ExceptionEvaluatorRegistry.java │ │ │ └── ResponseException.java │ │ │ ├── package.html │ │ │ ├── preconditions │ │ │ ├── Authenticated.java │ │ │ ├── AuthenticatedIf.java │ │ │ ├── BannedUrlParameters.java │ │ │ ├── BasicAuth.java │ │ │ ├── CORS.java │ │ │ ├── Description.java │ │ │ ├── Example.java │ │ │ ├── Examples.java │ │ │ ├── InjectRequestBodyAs.java │ │ │ ├── InjectUrlParametersAs.java │ │ │ ├── MaximumPathLength.java │ │ │ ├── MaximumRequestBodyLength.java │ │ │ ├── Methods.java │ │ │ ├── MinimumRequestBodyLength.java │ │ │ ├── PageAnnotationHandler.java │ │ │ ├── ParametersMustBeNumbersIfPresent.java │ │ │ ├── Path.java │ │ │ ├── PathRegex.java │ │ │ ├── RequireAtLeastOneUrlParameterFrom.java │ │ │ ├── RequireParametersIfMethodMatches.java │ │ │ ├── RequiredUrlParameters.java │ │ │ ├── UrlParametersMayNotBeCombined.java │ │ │ └── UrlParametersMayNotBeCombinedSets.java │ │ │ ├── server │ │ │ ├── ActeurSslConfig.java │ │ │ ├── DefaultPathFactory.java │ │ │ ├── DefaultPipelineDecorator.java │ │ │ ├── EarlyPagesPipelineDecorator.java │ │ │ ├── EventImpl.java │ │ │ ├── EventLoopFactory.java │ │ │ ├── NioServerChannelFactory.java │ │ │ ├── PathFactory.java │ │ │ ├── PipelineDecorator.java │ │ │ ├── PipelineFactoryImpl.java │ │ │ ├── SelfSignedSslConfig.java │ │ │ ├── ServerBootstrapConfigurer.java │ │ │ ├── ServerBuilder.java │ │ │ ├── ServerImpl.java │ │ │ ├── ServerLifecycleHook.java │ │ │ ├── ServerModule.java │ │ │ ├── UnknownNetworkEventHandler.java │ │ │ ├── UpstreamHandlerImpl.java │ │ │ └── WebSocketEvent.java │ │ │ ├── spi │ │ │ └── ApplicationControl.java │ │ │ └── websocket │ │ │ ├── DefaultOnWebsocketConnect.java │ │ │ ├── OnWebsocketConnect.java │ │ │ └── WebSocketUpgradeActeur.java │ └── test │ │ ├── java │ │ └── com │ │ │ └── mastfrog │ │ │ └── acteur │ │ │ ├── AppTest.java │ │ │ ├── AsyncActeursTest.java │ │ │ ├── BasePathTest.java │ │ │ ├── CompApp.java │ │ │ ├── ComprehensiveTest.java │ │ │ ├── ConnectionReuseTest.java │ │ │ ├── CookieTest.java │ │ │ ├── DecoratorWithOnBeforeEventTest.java │ │ │ ├── EarlyInterceptionTest.java │ │ │ ├── ErrTest.java │ │ │ ├── InternalsTest.java │ │ │ ├── PagePathAndMethodFilterTest.java │ │ │ ├── PathFactoryTest.java │ │ │ ├── PatternAndGlobCacheTest.java │ │ │ ├── PutTest.java │ │ │ ├── ResponseDecoratorTest.java │ │ │ ├── SilentRequestLogger.java │ │ │ ├── SslTest.java │ │ │ ├── TarpitTest.java │ │ │ ├── TestAnnotations.java │ │ │ ├── TestMultiplePages.java │ │ │ ├── VerifyDateTimeBehavior.java │ │ │ ├── WebSocketTest.java │ │ │ ├── annotations │ │ │ ├── AnotherPage.java │ │ │ ├── FakePage.java │ │ │ ├── GenericApplicationTest.java │ │ │ ├── X.java │ │ │ └── ZZZPage.java │ │ │ ├── auth │ │ │ └── AsyncAuthenticationModuleTest.java │ │ │ └── server │ │ │ ├── DebugApp.java │ │ │ ├── DefaultPathFactoryTest.java │ │ │ ├── EventImplFactory.java │ │ │ └── EventImplTest.java │ │ └── resources │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ ├── ComprehensiveTest.properties │ │ ├── InternalsTest.properties │ │ ├── PathFactoryTest.properties │ │ ├── PutTest.properties │ │ ├── TestAnnotations.properties │ │ ├── annotations │ │ └── GenericApplicationTest │ │ └── sse │ │ └── SseTest.properties └── theugly.txt ├── deprecated ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── acteur │ ├── ClasspathResourcePage.java │ └── io │ └── FileWriter.java ├── marshaller-registry ├── index-reflection.marker ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── marshallers │ │ ├── ContentMarshallers.java │ │ ├── Marshaller.java │ │ └── netty │ │ ├── ByteArrayInterpreter.java │ │ ├── ByteBufMarshaller.java │ │ ├── ByteBufferMarshaller.java │ │ ├── CharSequenceInterperter.java │ │ ├── ImageStreamInterpreter.java │ │ ├── InputStreamInterpreter.java │ │ ├── JsonListMarshaller.java │ │ ├── JsonMapMarshaller.java │ │ ├── JsonObjectMarshaller.java │ │ ├── NettyContentMarshallers.java │ │ └── StringMarshaller.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── marshallers │ └── netty │ └── NettyContentMarshallersTest.java ├── mime ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── mime │ │ ├── MimeType.java │ │ ├── MimeTypeComponent.java │ │ ├── MimeTypeParser.java │ │ ├── ParsedMimeType.java │ │ ├── SimpleMimeTypeWithCharset.java │ │ └── SimpleMimeTypeWithParams.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── mime │ └── MimeTypeParserTest.java ├── netty-websocket-pubsub ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mastfrog │ │ └── acteur │ │ └── pubsub │ │ ├── Bus.java │ │ ├── BusListener.java │ │ ├── ChannelId.java │ │ ├── ChannelRegistry.java │ │ └── PubSubBus.java │ └── test │ └── java │ └── com │ └── mastfrog │ └── acteur │ └── pubsub │ └── BusTest.java ├── pom.xml ├── simple-webserver ├── nbactions.xml ├── pom.xml ├── serve └── src │ └── main │ └── java │ └── com │ └── mastfrog │ └── simple │ └── webserver │ └── FileServer.java └── url ├── description.properties ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── mastfrog │ │ ├── url │ │ ├── Anchor.java │ │ ├── GenericUrlComponent.java │ │ ├── Host.java │ │ ├── HostAndPort.java │ │ ├── Label.java │ │ ├── Parameters.java │ │ ├── ParametersDelimiter.java │ │ ├── ParametersElement.java │ │ ├── ParsedParameters.java │ │ ├── Path.java │ │ ├── PathElement.java │ │ ├── Port.java │ │ ├── Protocol.java │ │ ├── Protocols.java │ │ ├── URL.java │ │ ├── URLBuilder.java │ │ ├── URLComponent.java │ │ ├── URLParser.java │ │ └── package.html │ │ └── util │ │ └── builder │ │ ├── AbstractBuilder.java │ │ └── Builder.java └── resources │ └── com │ └── mastfrog │ └── url │ └── Bundle.properties └── test └── java └── com └── mastfrog └── url ├── HostIpV6Test.java ├── MoreTest.java ├── ParsedParametersTest.java ├── PathElementTest.java ├── PathTest.java ├── PortTest.java ├── URLTest.java └── UnderscoreTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | *.orig 8 | *.iml 9 | .idea/ 10 | target/ 11 | nb-configuration.xml 12 | 13 | /acteur-mongo-async/nbproject/ 14 | /interpreter-registry/nbproject/ 15 | /marshaller-registry/nbproject/ 16 | /acteur-util/nbproject/ 17 | /acteur-websocket-pubsub/nbproject/ 18 | /netty-websocket-pubsub/nbproject/ 19 | /acteur/nbproject/ 20 | /url/nbproject/ 21 | /acteur-headers/nbproject/ 22 | /acteur-server-sent-events/nbproject/ 23 | /mime/nbproject/ 24 | -------------------------------------------------------------------------------- /acteur-annotation-processors/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-annotation-processors 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | https://github.com/timboudreau/acteur.git 23 | scm:git:https://github.com/timboudreau/acteur.git 24 | git@github.com/timboudreau/acteur.git 25 | 26 | 27 | Github 28 | https://github.com/timboudreau/acteur/issues 29 | 30 | 31 | 32 | 33 | MIT 34 | https://opensource.org/licenses/MIT 35 | repo 36 | 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | 44 | 45 | 46 | ${project.groupId} 47 | annotation-processors 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /acteur-annotations/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-annotations 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | https://github.com/timboudreau/acteur.git 23 | scm:git:https://github.com/timboudreau/acteur.git 24 | git@github.com/timboudreau/acteur.git 25 | 26 | 27 | Github 28 | https://github.com/timboudreau/acteur/issues 29 | 30 | 31 | 32 | 33 | MIT 34 | https://opensource.org/licenses/MIT 35 | repo 36 | 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /acteur-annotations/src/main/java/com/mastfrog/acteur/annotations/GeneratedFrom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.annotations; 26 | 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * DO NOT USE in code. Generated into __GenPage Page subclasses by the annotation 34 | * processor for HttpCall, so the framework can identify stateless page classes. 35 | * 36 | * @author Tim Boudreau 37 | */ 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target(ElementType.TYPE) 40 | public @interface GeneratedFrom { 41 | Class value(); 42 | } 43 | -------------------------------------------------------------------------------- /acteur-annotations/src/main/java/com/mastfrog/acteur/annotations/GuiceModule.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Annotate Guice modules with this and GenericApplictionModule will install 10 | * them if they are on the classpath. This module will automatically look up 11 | * any modules registered with @GuiceModule and install them (unless their 12 | * exact type is in the exclusion list passed to GenericApplictionModule's 13 | * constructor). 14 | *

15 | * Such modules must have a no-arg constructor or a 1-arg constructor 16 | * where the argument type is Settings, or a 2-arg constructor in which one 17 | * argument is Settings and the other is ReentrantScope (since some applications 18 | * need to do special binding of things within Acteur's request scope). 19 | * 20 | * @author Tim Boudreau 21 | */ 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target(ElementType.TYPE) 24 | public @interface GuiceModule { 25 | public static final String META_INF_PATH = "META-INF/http/modules.list"; 26 | } 27 | -------------------------------------------------------------------------------- /acteur-base/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-base/src/main/java/com/mastfrog/acteurbase/ActeurBaseModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteurbase; 25 | 26 | import com.google.inject.AbstractModule; 27 | import com.mastfrog.giulius.scope.ReentrantScope; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | public class ActeurBaseModule extends AbstractModule { 34 | 35 | private final ReentrantScope scope; 36 | 37 | public ActeurBaseModule(ReentrantScope scope) { 38 | this.scope = scope; 39 | 40 | } 41 | 42 | @Override 43 | protected void configure() { 44 | scope.bindTypes(binder(), Chain.class, Deferral.class); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /acteur-base/src/test/java/com/mastfrog/acteurbase/impl/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteurbase.impl; 25 | 26 | import com.mastfrog.acteur.headers.HeaderValueType; 27 | import io.netty.channel.ChannelFutureListener; 28 | import io.netty.handler.codec.http.HttpResponseStatus; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public interface Response { 35 | 36 | public Response add(HeaderValueType header, T value); 37 | 38 | public void setResponseBodyWriter(ChannelFutureListener l); 39 | 40 | public void setStatus(HttpResponseStatus status); 41 | 42 | public void setMessage(Object message); 43 | } 44 | -------------------------------------------------------------------------------- /acteur-cookie-auth/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-cookie-auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-cookie-auth 18 | 19 | https://github.com/timboudreau/acteur 20 | Acteur Cookie Authentication 21 | 22 | 23 | 24 | ${project.groupId} 25 | acteur 26 | 27 | 28 | 29 | Github 30 | https://github.com/timboudreau/acteur/issues 31 | 32 | 33 | 34 | https://github.com/timboudreau/acteur.git 35 | scm:git:https://github.com/timboudreau/acteur.git 36 | git@github.com/timboudreau/acteur.git 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | 44 | 45 | 46 | MIT 47 | https://opensource.org/licenses/MIT 48 | repo 49 | 50 | 51 | 52 | 53 | 54 | Tim Boudreau 55 | tim@timboudreau.com 56 | https://timboudreau.com 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/CookieActeur.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.google.inject.Inject; 4 | import com.mastfrog.acteur.HttpEvent; 5 | import com.mastfrog.acteur.auth.AuthenticationActeur; 6 | import io.netty.handler.codec.http.HttpResponseStatus; 7 | 8 | /** 9 | * Implementation of AuthenticationActeur which uses cookies instead of 10 | * basic auth credentials. 11 | * 12 | * @author Tim Boudreau 13 | */ 14 | final class CookieActeur extends AuthenticationActeur { 15 | 16 | @Inject 17 | CookieActeur(HttpEvent evt, CookieAuthenticator auth) throws Exception { 18 | Object[] o = auth.authenticateRequest(evt); 19 | if (o != null && o.length > 0) { 20 | setState(new ConsumedLockedState(o[0])); 21 | } else { 22 | setState(new RespondWith(HttpResponseStatus.UNAUTHORIZED, "Not authorized")); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/CookieAuthModule.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.TypeLiteral; 5 | import com.mastfrog.acteur.auth.AuthenticationActeur; 6 | import com.mastfrog.giulius.scope.ReentrantScope; 7 | 8 | /** 9 | * Module which sets up bindings for Cookie authentication, if provided an 10 | * implementation of {@link UserFinder}. 11 | * 12 | * @author Tim Boudreau 13 | */ 14 | public final class CookieAuthModule extends AbstractModule { 15 | 16 | private final ReentrantScope scope; 17 | private final UserTypeAndFinderType types; 18 | 19 | /** 20 | * Create a module 21 | * 22 | * @param scope This must be the scope which the ServerModule or 23 | * GenericApplicationModule will use as its request scope. This can be done 24 | * by subclassing either of those, or by passing the same instance of 25 | * ReentrantScope to both the constructor of your ServerBuilder 26 | * @param userType The class that represents a User object in this 27 | * application, which the UserFinder will return if authentication succeeds. 28 | * @param finderType The type of UserFinder to bind. 29 | */ 30 | public CookieAuthModule(ReentrantScope scope, Class userType, Class> finderType) { 31 | this.scope = scope; 32 | types = new UserTypeAndFinderType<>(userType, finderType); 33 | } 34 | 35 | @Override 36 | protected void configure() { 37 | bind(new TL()).to(types.finderType); 38 | scope.bindTypes(binder(), types.userType); 39 | bind(AuthenticationActeur.class).to(CookieActeur.class); 40 | } 41 | 42 | private static final class TL extends TypeLiteral> { 43 | } 44 | 45 | static class UserTypeAndFinderType { 46 | 47 | final Class userType; 48 | final Class> finderType; 49 | 50 | UserTypeAndFinderType(Class userType, Class> finderType) { 51 | this.userType = userType; 52 | this.finderType = finderType; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/LoginActeur.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.google.inject.Inject; 4 | import com.mastfrog.acteur.Acteur; 5 | import com.mastfrog.acteur.HttpEvent; 6 | import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED; 7 | 8 | /** 9 | * Acteur which can be used in the {@link Precursors} annotation of HTTP 10 | * endpoints that log in a user, passing a LoginInfo as the HTTP 11 | * request body. 12 | * 13 | * @author Tim Boudreau 14 | */ 15 | public final class LoginActeur extends Acteur { 16 | 17 | @Inject 18 | LoginActeur(HttpEvent evt, CookieAuthenticator auth) throws Exception { 19 | LoginInfo info = evt.jsonContent(LoginInfo.class); 20 | Object[] inject = auth.login(evt, info, response()); 21 | if (inject == null || inject.length == 0) { 22 | auth.logout(evt, response()); 23 | setState(new RespondWith(UNAUTHORIZED, "Unknown user name or password")); 24 | } else { 25 | setState(new ConsumedLockedState(inject[0])); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/LoginInfo.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.mastfrog.util.preconditions.Checks; 7 | import java.util.concurrent.ThreadLocalRandom; 8 | import org.netbeans.validation.api.InvalidInputException; 9 | import org.netbeans.validation.api.Problems; 10 | 11 | /** 12 | * User credentials sent in an HTTP request body to log in. Note: The password 13 | * returning method can be called exactly once - it overwrites the 14 | * original value with garbage upon being called.. Two properties must be 15 | * present in the JSON: 16 | *

20 | * Other properties may be present but will be ignored. 21 | * 22 | * @author Tim Boudreau 23 | */ 24 | @JsonIgnoreProperties(ignoreUnknown = true) 25 | public class LoginInfo { 26 | 27 | private final String user; 28 | private final char[] password; 29 | 30 | @JsonCreator 31 | public LoginInfo(@JsonProperty("user") String user, @JsonProperty("password") char[] password) { 32 | Checks.notNull("user", user); 33 | Checks.notNull("password", password); 34 | if (password.length == 0) { 35 | throw new InvalidInputException(new Problems().append("Zero length password")); 36 | } 37 | this.user = user; 38 | this.password = password; 39 | } 40 | 41 | String user() { 42 | return user; 43 | } 44 | 45 | synchronized char[] getPassword() { 46 | char[] result = new char[password.length]; 47 | System.arraycopy(password, 0, result, 0, result.length); 48 | for (int i = 0; i < password.length; i++) { 49 | password[i] = (char) ThreadLocalRandom.current().nextInt(); 50 | } 51 | return result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/LogoutActeur.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.google.inject.Inject; 4 | import com.mastfrog.acteur.Acteur; 5 | import com.mastfrog.acteur.HttpEvent; 6 | import com.mastfrog.acteur.annotations.Precursors; 7 | import java.net.URISyntaxException; 8 | 9 | /** 10 | * Acteur which can be used in the {@link Precursors} annotation of an 11 | * endpoint which should log the user out. 12 | * 13 | * @author Tim Boudreau 14 | */ 15 | public class LogoutActeur extends Acteur { 16 | 17 | @Inject 18 | LogoutActeur(CookieAuthenticator auth, HttpEvent evt) throws URISyntaxException { 19 | auth.logout(evt, response()); 20 | setState(new ConsumedLockedState()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/SessionTimeout.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.cookie.auth; 2 | 3 | import com.google.inject.Inject; 4 | import com.mastfrog.giulius.DeploymentMode; 5 | import com.mastfrog.settings.Settings; 6 | import com.mastfrog.util.preconditions.ConfigurationError; 7 | import java.time.Duration; 8 | import javax.inject.Singleton; 9 | 10 | /** 11 | * Represents the duration of a login session before a user will be required to 12 | * re-log-in. Used for cookie expiration times, cache expiration times, etc. Set 13 | * the "session.expiry.hours" settings key to a number of hours 14 | * that sessions should last without requiring login again. By default it is set 15 | * to 2 minutes in development mode and 2 days in production mode. 16 | * 17 | * @author Tim Boudreau 18 | */ 19 | @Singleton 20 | public final class SessionTimeout { 21 | 22 | /** 23 | * Settings key which determines session duration in hours. If unspecified, 24 | * session duration is 2 minutes for testing purposes, so this should 25 | * always be set in production. 26 | */ 27 | public static final String SETTINGS_KEY_SESSION_EXPIRY_HOURS = "session.expiry.hours"; 28 | private final Duration expiry; 29 | 30 | @Inject 31 | SessionTimeout(Settings settings, DeploymentMode mode) { 32 | Integer expiry = settings.getInt(SETTINGS_KEY_SESSION_EXPIRY_HOURS); 33 | if (expiry != null) { 34 | this.expiry = Duration.ofHours(expiry); 35 | } else if (mode.isProduction()) { 36 | // throw new ConfigurationError("Will not use the default session " 37 | // + "expiration time of 2 minutes in production. Set" 38 | // + SETTINGS_KEY_SESSION_EXPIRY_HOURS + " to something resonable."); 39 | this.expiry = Duration.ofDays(2); 40 | } else { 41 | this.expiry = Duration.ofMinutes(2); 42 | } 43 | } 44 | 45 | public Duration get() { 46 | return expiry; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /acteur-cookie-auth/src/main/java/com/mastfrog/acteur/cookie/auth/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Acteur Cookie Auth API 5 | 6 | 7 |

8 | This is an API which makes it trivial to add cookie-based authentication 9 | to acteur-based web applications, as opposed to using HTTP basic 10 | authentication. Code that was using the @Authenticated 11 | (or deprecated @BasicAuth) annotation need not be 12 | modified - the new authentication scheme can be used transparently. 13 |

14 |

15 | To use cookie authentication, the following changes are needed in an 16 | application that formerly used HTTP Basic Authentication and the 17 | @Authenticated annotation: 18 |

19 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /acteur-header-entities/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.mastfrog 7 | acteur-parent 8 | 2.9.7 9 | 10 | 11 | acteur-header-entities 12 | 13 | https://github.com/timboudreau/acteur 14 | Acteur Header Entities 15 | 16 | Simple types, parsers and builders for common HTTP header 17 | values such as cache-control, basic auth credentials, frame options, 18 | strict transport security and connection that are easy to work with 19 | programmatically, parse out of inbound headers and generate correctly into 20 | outbound headers. 21 | 22 | 23 | 24 | ${project.groupId} 25 | util-strings 26 | 27 | 28 | 29 | https://github.com/timboudreau/acteur.git 30 | scm:git:https://github.com/timboudreau/acteur.git 31 | git@github.com/timboudreau/acteur.git 32 | 33 | 34 | 35 | Mastfrog Technologies 36 | https://mastfrog.com 37 | 38 | 39 | 40 | 41 | MIT 42 | https://opensource.org/licenses/MIT 43 | repo 44 | 45 | 46 | 47 | 48 | 49 | Tim Boudreau 50 | tim@timboudreau.com 51 | https://timboudreau.com 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /acteur-header-entities/src/main/java/com/mastfrog/acteur/header/entities/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.header.entities; 25 | 26 | /** 27 | * Enum of standard values for the HTTP Connection header. 28 | * 29 | * @author Tim Boudreau 30 | */ 31 | public enum Connection implements ConnectionHeaderData { 32 | close, keep_alive, upgrade; 33 | 34 | @Override 35 | public boolean isKnownConnectionValue() { 36 | return true; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | switch (this) { 42 | case close: 43 | return name(); 44 | case keep_alive: 45 | return "keep-alive"; 46 | case upgrade: 47 | return "Upgrade"; 48 | default: 49 | throw new AssertionError(this); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /acteur-header-entities/src/main/java/com/mastfrog/acteur/header/entities/ConnectionHeaderData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2021 Mastfrog Technologies. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.header.entities; 25 | 26 | import com.mastfrog.util.strings.Strings; 27 | 28 | /** 29 | * 30 | * @author Tim Boudreau 31 | */ 32 | public interface ConnectionHeaderData { 33 | 34 | default boolean isKnownConnectionValue() { 35 | return false; 36 | } 37 | 38 | static ConnectionHeaderData fromString(CharSequence seq) { 39 | if (Strings.charSequencesEqual(seq, "keep-alive", true)) { 40 | return Connection.keep_alive; 41 | } else if (Strings.charSequencesEqual(seq, "close", true)) { 42 | return Connection.close; 43 | } else if (Strings.charSequencesEqual(seq, "upgrade", true)) { 44 | return Connection.upgrade; 45 | } else { 46 | return new UnknownConnectionHeaderData(seq); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /acteur-headers-jodatime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-headers-jodatime 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | https://github.com/timboudreau/acteur.git 23 | scm:git:https://github.com/timboudreau/acteur.git 24 | git@github.com/timboudreau/acteur.git 25 | 26 | 27 | Github 28 | https://github.com/timboudreau/acteur/issues 29 | 30 | 31 | 32 | 33 | MIT 34 | https://opensource.org/licenses/MIT 35 | repo 36 | 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | 44 | 45 | 46 | ${project.groupId} 47 | acteur-headers 48 | 49 | 50 | joda-time 51 | joda-time 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /acteur-headers-jodatime/src/main/java/com/mastfrog/acteur/headers/jodatime/JodaCacheControlHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers.jodatime; 25 | 26 | import com.mastfrog.acteur.headers.AbstractHeader; 27 | import com.mastfrog.acteur.header.entities.CacheControl; 28 | import io.netty.handler.codec.http.HttpHeaderNames; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class JodaCacheControlHeader extends AbstractHeader { 35 | 36 | JodaCacheControlHeader() { 37 | super(CacheControl.class, HttpHeaderNames.CACHE_CONTROL); 38 | } 39 | 40 | @Override 41 | public String toString(CacheControl value) { 42 | return value.toString(); 43 | } 44 | 45 | @Override 46 | public CacheControl toValue(CharSequence value) { 47 | return CacheControl.fromString(value); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/AccelBufferingHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import static com.mastfrog.util.strings.Strings.charSequencesEqual; 27 | import io.netty.util.AsciiString; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | final class AccelBufferingHeader extends AbstractHeader { 34 | 35 | private static final AsciiString OFF = new AsciiString("off"); 36 | private static final AsciiString ON = new AsciiString("on"); 37 | 38 | public AccelBufferingHeader() { 39 | super(Boolean.TYPE, new AsciiString("X-Accel-Buffering")); 40 | } 41 | 42 | @Override 43 | public CharSequence toCharSequence(Boolean value) { 44 | return value ? ON : OFF; 45 | } 46 | 47 | @Override 48 | public Boolean toValue(CharSequence value) { 49 | return charSequencesEqual(ON, value); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/AuthHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.acteur.util.Realm; 27 | import com.mastfrog.util.preconditions.Checks; 28 | import io.netty.handler.codec.http.HttpHeaderNames; 29 | import io.netty.util.AsciiString; 30 | 31 | /** 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | final class AuthHeader extends AbstractHeader { 36 | 37 | AuthHeader() { 38 | super(Realm.class, HttpHeaderNames.WWW_AUTHENTICATE); 39 | } 40 | 41 | @Override 42 | public CharSequence toCharSequence(Realm value) { 43 | Checks.notNull("value", value); 44 | return AsciiString.of("Basic realm=\"" + value.toString() + "\""); 45 | } 46 | 47 | @Override 48 | public Realm toValue(CharSequence value) { 49 | Checks.notNull("value", value); 50 | return Realm.createSimple(value); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/BasicCredentialsHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.acteur.header.entities.BasicCredentials; 27 | import com.mastfrog.util.preconditions.Checks; 28 | import io.netty.handler.codec.http.HttpHeaderNames; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | class BasicCredentialsHeader extends AbstractHeader { 35 | 36 | BasicCredentialsHeader() { 37 | super(BasicCredentials.class, HttpHeaderNames.AUTHORIZATION); 38 | } 39 | 40 | @Override 41 | @SuppressWarnings("deprecation") 42 | public String toString(BasicCredentials value) { 43 | Checks.notNull("value", value); 44 | return value.toString(); 45 | } 46 | 47 | @Override 48 | public BasicCredentials toValue(CharSequence value) { 49 | Checks.notNull("value", value); 50 | return BasicCredentials.parse(value); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/BooleanHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.headers; 26 | 27 | import com.mastfrog.util.preconditions.Checks; 28 | import com.mastfrog.util.strings.Strings; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class BooleanHeader extends AbstractHeader { 35 | 36 | BooleanHeader(CharSequence name) { 37 | super(Boolean.TYPE, name); 38 | } 39 | 40 | @Override 41 | @SuppressWarnings("deprecation") 42 | public String toString(Boolean value) { 43 | Checks.notNull("value", value); 44 | return value.toString(); 45 | } 46 | 47 | @Override 48 | public Boolean toValue(CharSequence value) { 49 | Checks.notNull("value", value); 50 | return Strings.charSequencesEqual("true", value, true) 51 | || Strings.charSequencesEqual("1", value, false); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/ByteRangeHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.preconditions.Checks; 27 | 28 | /** 29 | * Header that uses a byte range value 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | final class ByteRangeHeader extends AbstractHeader { 34 | 35 | ByteRangeHeader(CharSequence name) { 36 | super(ByteRanges.class, name); 37 | } 38 | 39 | @Override 40 | @SuppressWarnings("deprecation") 41 | public String toString(ByteRanges value) { 42 | Checks.notNull("value", value); 43 | return value.toString(); 44 | } 45 | 46 | @Override 47 | public CharSequence toCharSequence(ByteRanges value) { 48 | return value.toCharSequence(); 49 | } 50 | 51 | @Override 52 | public ByteRanges toValue(CharSequence value) { 53 | Checks.notNull("value", value); 54 | return new ByteRanges(value); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/CharSequenceHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.headers; 26 | 27 | import com.mastfrog.util.preconditions.Checks; 28 | import io.netty.util.AsciiString; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class CharSequenceHeader extends AbstractHeader { 35 | 36 | CharSequenceHeader(CharSequence name) { 37 | super(CharSequence.class, AsciiString.of(name)); 38 | } 39 | 40 | @Override 41 | public CharSequence toValue(CharSequence value) { 42 | Checks.notNull("value", value); 43 | return AsciiString.of(value); 44 | } 45 | 46 | @Override 47 | public CharSequence toCharSequence(CharSequence value) { 48 | Checks.notNull("value", value); 49 | return value; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/ContentRangeHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.headers; 26 | 27 | import com.mastfrog.util.preconditions.Checks; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | final class ContentRangeHeader extends AbstractHeader { 34 | 35 | ContentRangeHeader(CharSequence name) { 36 | super(BoundedRangeNetty.class, name); 37 | } 38 | 39 | @Override 40 | public CharSequence toCharSequence(BoundedRangeNetty value) { 41 | Checks.notNull("value", value); 42 | return value.toCharSequence(); 43 | } 44 | 45 | @Override 46 | public BoundedRangeNetty toValue(CharSequence value) { 47 | return new BoundedRangeNetty(value); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/IntHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.preconditions.Checks; 27 | import com.mastfrog.util.strings.Strings; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | class IntHeader extends AbstractHeader { 34 | 35 | IntHeader(CharSequence name) { 36 | super(Integer.TYPE, name); 37 | } 38 | 39 | @Override 40 | public CharSequence toCharSequence(Integer value) { 41 | Checks.notNull("value", value); 42 | return value.toString(); 43 | } 44 | 45 | @Override 46 | public Integer toValue(CharSequence value) { 47 | Checks.notNull("value", value); 48 | return Strings.parseInt(value); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/LocaleHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.preconditions.Checks; 27 | import java.util.Locale; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | class LocaleHeader extends AbstractHeader { 34 | 35 | LocaleHeader(CharSequence name) { 36 | super(Locale.class, name); 37 | } 38 | 39 | @Override 40 | @SuppressWarnings("deprecation") 41 | public String toString(Locale value) { 42 | Checks.notNull("value", value); 43 | return value.toLanguageTag(); 44 | } 45 | 46 | @Override 47 | public Locale toValue(CharSequence value) { 48 | Checks.notNull("value", value); 49 | return Locale.forLanguageTag(value.toString()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/LongHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.strings.Strings; 27 | 28 | /** 29 | * 30 | * @author Tim Boudreau 31 | */ 32 | class LongHeader extends AbstractHeader { 33 | 34 | LongHeader(CharSequence name) { 35 | super(Long.TYPE, name); 36 | } 37 | 38 | @Override 39 | @SuppressWarnings("deprecation") 40 | public String toString(Long value) { 41 | return value.toString(); 42 | } 43 | 44 | @Override 45 | public Long toValue(CharSequence value) { 46 | return Strings.parseLong(value); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/MimeTypeHeader.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.headers; 2 | 3 | import com.mastfrog.mime.MimeType; 4 | import io.netty.handler.codec.http.HttpHeaderNames; 5 | import java.util.Map; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | 8 | /** 9 | * 10 | * @author Tim Boudreau 11 | */ 12 | final class MimeTypeHeader extends AbstractHeader { 13 | 14 | private static final Map CACHE = new ConcurrentHashMap<>(); 15 | 16 | public MimeTypeHeader() { 17 | super(MimeType.class, HttpHeaderNames.CONTENT_TYPE); 18 | } 19 | 20 | public CharSequence toCharSequence(MimeType value) { 21 | return value.toCharSequence(); 22 | } 23 | 24 | public MimeType toValue(CharSequence value) { 25 | return CACHE.computeIfAbsent(value, MimeType::parse); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/NumberHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.strings.Strings; 27 | 28 | /** 29 | * Header which is a number (so casting to long is unneeded for literals). 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | class NumberHeader extends AbstractHeader { 34 | 35 | NumberHeader(CharSequence name) { 36 | super(Number.class, name); 37 | } 38 | 39 | @Override 40 | @SuppressWarnings("deprecation") 41 | public String toString(Number value) { 42 | return Long.toString(value.longValue()); 43 | } 44 | 45 | @Override 46 | public Number toValue(CharSequence value) { 47 | return Strings.parseLong(value); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/PragmaHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2022 Mastfrog Technologies. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.acteur.header.entities.CacheControl; 27 | import com.mastfrog.acteur.header.entities.CacheControlTypes; 28 | import io.netty.util.AsciiString; 29 | 30 | /** 31 | * Handles the HTTP 1.0 Pragma: no-cache header style. 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | final class PragmaHeader extends AbstractHeader { 36 | 37 | static final AsciiString PRAGMA = AsciiString.cached("pragma"); 38 | private static final AsciiString NO_CACHE = AsciiString.cached("no-cache"); 39 | private static final CacheControl RESP = CacheControl.$(CacheControlTypes.no_cache); 40 | 41 | PragmaHeader() { 42 | super(CacheControl.class, PRAGMA); 43 | } 44 | 45 | @Override 46 | public CacheControl toValue(CharSequence value) { 47 | if (NO_CACHE.contentEqualsIgnoreCase(value)) { 48 | return RESP; 49 | } 50 | return null; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/StrictTransportSecurityHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2018 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.headers; 26 | 27 | import com.mastfrog.acteur.header.entities.StrictTransportSecurity; 28 | import io.netty.util.AsciiString; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class StrictTransportSecurityHeader extends AbstractHeader { 35 | 36 | private static final AsciiString STRICT_TRANSPORT_SECURITY = AsciiString.of("strict-transport-securty"); 37 | 38 | StrictTransportSecurityHeader() { 39 | super(StrictTransportSecurity.class, STRICT_TRANSPORT_SECURITY); 40 | } 41 | 42 | @Override 43 | public StrictTransportSecurity toValue(CharSequence value) { 44 | return StrictTransportSecurity.parse(value); 45 | } 46 | 47 | @Override 48 | public CharSequence toCharSequence(StrictTransportSecurity value) { 49 | return AsciiString.of(value.toString()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/StringHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | /** 27 | * 28 | * @author Tim Boudreau 29 | */ 30 | class StringHeader extends AbstractHeader { 31 | 32 | StringHeader(CharSequence name) { 33 | super(String.class, name); 34 | } 35 | 36 | @Override 37 | @SuppressWarnings("deprecation") 38 | public String toString(String value) { 39 | return value; 40 | } 41 | 42 | @Override 43 | public String toValue(CharSequence value) { 44 | return value.toString(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/TimestampHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2022 Mastfrog Technologies. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import java.time.Instant; 27 | import java.time.temporal.Temporal; 28 | 29 | /** 30 | * Subtype of HeaderValueType instances which are convertible into an Instant. 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public interface TimestampHeader extends HeaderValueType { 35 | 36 | /** 37 | * Convert this header into one which accepts and returns Instant. 38 | * 39 | * @return An instant 40 | */ 41 | TimestampHeader toInstantHeader(); 42 | } 43 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/UriHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import static com.mastfrog.util.preconditions.Checks.notNull; 27 | import java.net.URI; 28 | import java.net.URISyntaxException; 29 | import java.util.logging.Level; 30 | import java.util.logging.Logger; 31 | 32 | /** 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | final class UriHeader extends AbstractHeader { 37 | 38 | UriHeader(CharSequence name) { 39 | super(URI.class, name); 40 | } 41 | 42 | @Override 43 | @SuppressWarnings("deprecation") 44 | public String toString(URI value) { 45 | return notNull("value", value).toString(); 46 | } 47 | 48 | @Override 49 | public URI toValue(CharSequence value) { 50 | try { 51 | return new URI(notNull("value", value).toString()); 52 | } catch (URISyntaxException ex) { 53 | Logger.getLogger(Headers.class.getName()).log(Level.WARNING, "Bad URI in " 54 | + name() + " - " + value, ex); 55 | return null; 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/WebSocketLocationHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.preconditions.Exceptions; 27 | import io.netty.handler.codec.http.HttpHeaderNames; 28 | import java.net.MalformedURLException; 29 | import java.net.URL; 30 | 31 | /** 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | final class WebSocketLocationHeader extends AbstractHeader { 36 | 37 | WebSocketLocationHeader() { 38 | super(URL.class, HttpHeaderNames.WEBSOCKET_LOCATION); 39 | } 40 | 41 | @Override 42 | @SuppressWarnings("deprecation") 43 | public String toString(URL value) { 44 | return value.toExternalForm(); 45 | } 46 | 47 | @Override 48 | public URL toValue(CharSequence value) { 49 | try { 50 | return new URL(value.toString()); 51 | } catch (MalformedURLException ex) { 52 | return Exceptions.chuck(ex); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /acteur-headers/src/main/java/com/mastfrog/acteur/headers/WebSocketProtocolsHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.util.strings.Strings; 27 | import io.netty.handler.codec.http.HttpHeaderNames; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | final class WebSocketProtocolsHeader extends AbstractHeader { 34 | 35 | private static final CharSequence comma = Strings.singleChar(','); 36 | 37 | WebSocketProtocolsHeader() { 38 | super(CharSequence[].class, HttpHeaderNames.WEBSOCKET_PROTOCOL); 39 | } 40 | 41 | @Override 42 | public CharSequence toCharSequence(CharSequence[] value) { 43 | return Strings.join(',', value); 44 | } 45 | 46 | @Override 47 | public CharSequence[] toValue(CharSequence value) { 48 | CharSequence[] result = Strings.split(',', value); 49 | for (int i = 0; i < result.length; i++) { 50 | result[i] = Strings.trim(result[i]); 51 | } 52 | return result; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /acteur-headers/src/test/java/com/mastfrog/acteur/headers/AbstractHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.headers; 26 | 27 | import io.netty.handler.codec.http.HttpHeaderNames; 28 | import static org.junit.Assert.assertEquals; 29 | import static org.junit.Assert.assertTrue; 30 | import org.junit.Test; 31 | 32 | /** 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | public class AbstractHeaderTest { 37 | 38 | 39 | @Test 40 | @SuppressWarnings("deprecation") 41 | public void testNames() { 42 | assertTrue(Headers.SET_COOKIE_B.is(HttpHeaderNames.SET_COOKIE)); 43 | assertTrue(Headers.SET_COOKIE_B.is("Set-Cookie")); 44 | assertTrue(Headers.SET_COOKIE_B.is("set-cookie")); 45 | assertTrue(Headers.SET_COOKIE_B.is("sEt-cOoKiE")); 46 | assertEquals(Headers.SET_COOKIE, Headers.SET_COOKIE_B); 47 | assertEquals(Headers.SET_COOKIE, Headers.stringHeader(HttpHeaderNames.SET_COOKIE)); 48 | assertEquals(Headers.SET_COOKIE, Headers.stringHeader("Set-Cookie")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /acteur-headers/src/test/java/com/mastfrog/acteur/headers/StrictTransportSecurityHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2018 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import com.mastfrog.acteur.header.entities.StrictTransportSecurity; 27 | import static org.junit.Assert.assertEquals; 28 | import org.junit.Test; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public class StrictTransportSecurityHeaderTest { 35 | 36 | @Test 37 | public void testStrictTransportHeader() { 38 | HeaderValueType h = new StrictTransportSecurityHeader(); 39 | assertEquals(StrictTransportSecurity.FIVE_YEARS_INCLUDE_SUBDOMAINS_PRELOAD, 40 | h.toValue(StrictTransportSecurity.FIVE_YEARS_INCLUDE_SUBDOMAINS_PRELOAD.toString())); 41 | 42 | assertEquals(StrictTransportSecurity.ONE_YEAR, 43 | h.toValue(StrictTransportSecurity.ONE_YEAR.toString())); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /acteur-headers/src/test/java/com/mastfrog/acteur/headers/TimestampHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2022 Mastfrog Technologies. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.headers; 25 | 26 | import java.time.Instant; 27 | import java.time.ZonedDateTime; 28 | import java.time.temporal.ChronoField; 29 | import static org.junit.Assert.*; 30 | import org.junit.Test; 31 | 32 | /** 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | public class TimestampHeaderTest { 37 | 38 | @Test 39 | public void testInstantConversion() { 40 | ZonedDateTime when = ZonedDateTime.now().with(ChronoField.NANO_OF_SECOND, 0).with(ChronoField.MILLI_OF_SECOND, 0); 41 | TimestampHeader raw = Headers.LAST_MODIFIED; 42 | String origFmt = raw.toCharSequence(when).toString(); 43 | TimestampHeader inst = raw.toInstantHeader(); 44 | String fromInstant = inst.toCharSequence(when.toInstant()).toString(); 45 | assertEquals(origFmt, fromInstant); 46 | Instant in = inst.convert(origFmt); 47 | assertEquals(when.toInstant(), in); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /acteur-jdbc/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-jdbc 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | 23 | ${project.groupId} 24 | acteur 25 | 26 | 27 | 28 | Github 29 | https://github.com/timboudreau/acteur/issues 30 | 31 | 32 | 33 | https://github.com/timboudreau/acteur.git 34 | scm:git:https://github.com/timboudreau/acteur.git 35 | git@github.com/timboudreau/acteur.git 36 | 37 | 38 | 39 | Mastfrog Technologies 40 | https://mastfrog.com 41 | 42 | 43 | 44 | 45 | MIT 46 | https://opensource.org/licenses/MIT 47 | repo 48 | 49 | 50 | 51 | 52 | 53 | Tim Boudreau 54 | tim@timboudreau.com 55 | https://timboudreau.com 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /acteur-jdbc/src/main/java/com/mastfrog/acteur/jdbc/ResultSetWriterActeur.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.jdbc; 25 | 26 | import com.mastfrog.acteur.Acteur; 27 | import java.sql.ResultSet; 28 | 29 | /** 30 | * If you use @ImplicitBindings(ResultSet.class) on your 31 | * application and complete your request with this, it will write out your 32 | * result set as JSON. 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | public class ResultSetWriterActeur extends Acteur { 37 | 38 | ResultSetWriterActeur(ResultSet rs, ResultSetWriterFactory fact) { 39 | ok(); 40 | setResponseBodyWriter(fact.create(rs)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /acteur-mongo-async/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-mongo-reactive/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-mongo/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-mongo/src/main/java/com/mastfrog/acteur/mongo/CursorWriterActeur.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.mongo; 25 | 26 | import com.google.inject.Inject; 27 | import com.mastfrog.acteur.Acteur; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | public final class CursorWriterActeur extends Acteur { 34 | 35 | @Inject 36 | CursorWriterActeur(CursorWriter writer) { 37 | setChunked(true); 38 | ok(); 39 | setResponseWriter(writer); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /acteur-mongo/src/test/resources/com/mastfrog/acteur/mongo/MongoModuleTest.properties: -------------------------------------------------------------------------------- 1 | # To change this license header, choose License Headers in Project Properties. 2 | # To change this template file, choose Tools | Templates 3 | # and open the template in the editor. 4 | 5 | #mongoPort=29005 6 | #mongoHost=localhost 7 | -------------------------------------------------------------------------------- /acteur-resources/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-resources/src/main/java/com/mastfrog/acteur/resources/ClasspathResourceInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.resources; 25 | 26 | /** 27 | * 28 | * @author Tim Boudreau 29 | */ 30 | public final class ClasspathResourceInfo { 31 | 32 | private final Class relativeTo; 33 | private final String[] names; 34 | 35 | public ClasspathResourceInfo(Class relativeTo, String... names) { 36 | this.relativeTo = relativeTo; 37 | this.names = new String[names.length]; 38 | System.arraycopy(names, 0, this.names, 0, names.length); 39 | } 40 | 41 | String[] names() { 42 | return names; 43 | } 44 | 45 | Class relativeTo() { 46 | return relativeTo; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /acteur-resources/src/main/java/com/mastfrog/acteur/resources/ExpiresPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.resources; 25 | 26 | import com.google.inject.ImplementedBy; 27 | import com.mastfrog.mime.MimeType; 28 | import com.mastfrog.url.Path; 29 | import java.time.ZonedDateTime; 30 | 31 | /** 32 | * Determines the value of the Expires header for various files 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | @ImplementedBy(DefaultExpiresPolicy.class) 37 | public interface ExpiresPolicy { 38 | /** 39 | * Determine the latest date when markup should be cached for 40 | * the passed path - used in constructing cache control and 41 | * expires headers. 42 | * 43 | * @param mimeType The mime type being used 44 | * @param path The url path 45 | * @return A DateTime, or null if none should be used 46 | */ 47 | public ZonedDateTime get(MimeType mimeType, Path path); 48 | } 49 | -------------------------------------------------------------------------------- /acteur-resources/src/main/java/com/mastfrog/acteur/resources/Resource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.resources; 25 | 26 | import com.mastfrog.acteur.HttpEvent; 27 | import com.mastfrog.acteur.Page; 28 | import com.mastfrog.acteur.Response; 29 | import com.mastfrog.mime.MimeType; 30 | 31 | /** 32 | * A single resource such as a file to be served. 33 | */ 34 | public interface Resource { 35 | 36 | /** 37 | * Decorate the response, adding headers, setting response code, etc. 38 | * 39 | * @param page The page 40 | * @param evt The event 41 | * @param path The file path 42 | * @param response The response 43 | * @param chunked Whether or not the server plans to use HTTP chunked encoding 44 | * @throws Exception If something goes wrong 45 | */ 46 | void decorateResponse(HttpEvent evt, String path, Response response, boolean chunked) throws Exception; 47 | 48 | void attachBytes(HttpEvent evt, Response response, boolean chunked) throws Exception; 49 | 50 | MimeType getContentType(); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /acteur-resources/src/main/java/com/mastfrog/acteur/resources/StaticResources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.resources; 25 | 26 | import com.google.inject.ImplementedBy; 27 | 28 | /** 29 | * Source of static resources / files to be served. 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | @ImplementedBy(DefaultStaticResources.class) 34 | public interface StaticResources { 35 | 36 | public static final String RESOURCE_CLASSES_KEY = "static.resource.classes"; 37 | public static final String RESOURCE_NAMES_PREFIX = "static.resource.names"; 38 | public static final String RESOURCE_FOLDERS_KEY = "static.resource.folders"; 39 | 40 | /** 41 | * Get a resource that should be served. 42 | * 43 | * @param path The path from the base dir to the file 44 | * @return A resource or null 45 | */ 46 | Resource get(String path); 47 | 48 | String[] getPatterns(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /acteur-resources/src/test/resources/com/mastfrog/acteur/resources/StaticResourcesTest.properties: -------------------------------------------------------------------------------- 1 | static.base.url.path=static/(.*) 2 | production.mode=true 3 | acteur.debug=false 4 | neverKeepAlive=false 5 | dyn.resources.use.hash.etag=true 6 | cors.enabled=false 7 | -------------------------------------------------------------------------------- /acteur-resources/src/test/resources/com/mastfrog/acteur/resources/another.txt: -------------------------------------------------------------------------------- 1 | This is another file. It has some data in it. 2 | -------------------------------------------------------------------------------- /acteur-resources/src/test/resources/com/mastfrog/acteur/resources/hello.txt: -------------------------------------------------------------------------------- 1 | Test test test 2 | This is a test 3 | It is like a test too 4 | -------------------------------------------------------------------------------- /acteur-server-sent-events/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-server-sent-events/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | acteur-server-sent-events 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | https://github.com/timboudreau/acteur.git 23 | scm:git:https://github.com/timboudreau/acteur.git 24 | git@github.com/timboudreau/acteur.git 25 | 26 | 27 | Github 28 | https://github.com/timboudreau/acteur/issues 29 | 30 | 31 | 32 | 33 | MIT 34 | https://opensource.org/licenses/MIT 35 | repo 36 | 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | 44 | 45 | 46 | ${project.groupId} 47 | acteur 48 | 49 | 50 | ${project.groupId} 51 | giulius-tests 52 | test 53 | 54 | 55 | ${project.groupId} 56 | netty-http-test-harness 57 | test 58 | 59 | 60 | junit 61 | junit 62 | test 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /acteur-server-sent-events/src/main/java/com/mastfrog/acteur/sse/ActeurServerSentEventsModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2018 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.sse; 25 | 26 | import com.google.inject.Module; 27 | import com.google.inject.Binder; 28 | import com.mastfrog.giulius.scope.ReentrantScope; 29 | 30 | /** 31 | * Module that installs support for server sent events, and channel-specific 32 | * event sinks for sending messages to clients. You will need to use 33 | * SseActeur as in the @Concluders for at least one http endpoint, 34 | * and pass an EventChannelName in the context for the name of the channel 35 | * that connection will become subscribed to. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | public class ActeurServerSentEventsModule implements Module { 40 | 41 | private final ReentrantScope scope; 42 | 43 | public ActeurServerSentEventsModule(ReentrantScope scope) { 44 | this.scope = scope; 45 | } 46 | 47 | @Override 48 | public void configure(Binder binder) { 49 | scope.bindTypesAllowingNulls(binder, EventChannelName.class); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /acteur-server-sent-events/src/main/java/com/mastfrog/acteur/sse/EventChannelName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.sse; 25 | 26 | import java.util.concurrent.atomic.AtomicLong; 27 | 28 | /** 29 | * 30 | * @author Tim Boudreau 31 | */ 32 | public final class EventChannelName { 33 | 34 | public final String name; 35 | private final AtomicLong count = new AtomicLong(); 36 | 37 | public EventChannelName(String name) { 38 | this.name = name; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return name; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | return o == this ? true : o instanceof EventChannelName && ((EventChannelName) o).name.equals(name); 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return name.hashCode() * 47; 54 | } 55 | 56 | public long nextId() { 57 | return count.getAndIncrement(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /acteur-server-sent-events/src/main/java/com/mastfrog/acteur/sse/MessageRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.sse; 26 | 27 | import com.google.inject.ImplementedBy; 28 | 29 | /** 30 | * Renders a message into a server-sent event. The default implementation 31 | * renders strings as plain text and other types as JSON. Implement and bind 32 | * this type if you want some other sort of behavior. 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | @ImplementedBy(DefaultMessageRenderer.class) 37 | public interface MessageRenderer { 38 | 39 | /** 40 | * Converts a message object to a string 41 | * 42 | * @param msg The message 43 | * @return A string representation 44 | */ 45 | String toString(Object msg); 46 | } 47 | -------------------------------------------------------------------------------- /acteur-server-sent-events/src/test/java/com/mastfrog/acteur/sse/SilentRequestLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.sse; 26 | 27 | import com.google.inject.Binder; 28 | import com.google.inject.Module; 29 | import com.mastfrog.acteur.Event; 30 | import com.mastfrog.acteur.RequestLogger; 31 | import com.mastfrog.acteur.util.RequestID; 32 | import io.netty.handler.codec.http.HttpResponseStatus; 33 | 34 | /** 35 | * Quiets down the logger for tests. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | public class SilentRequestLogger implements RequestLogger, Module { 40 | 41 | @Override 42 | public void onBeforeEvent(RequestID rid, Event event) { 43 | // do nothing 44 | } 45 | 46 | @Override 47 | public void onRespond(RequestID rid, Event event, HttpResponseStatus status) { 48 | // do nothing 49 | } 50 | 51 | @Override 52 | public void configure(Binder binder) { 53 | binder.bind(RequestLogger.class).toInstance(this); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /acteur-util/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur-util/src/main/java/com/mastfrog/acteur/util/ErrorInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.util; 2 | 3 | /** 4 | * Injectable interceptor for exceptions thrown. Used in tests which want 5 | * to fail if server-side exceptions occur. 6 | * 7 | * @author Tim Boudreau 8 | */ 9 | public interface ErrorInterceptor { 10 | public void onError(Throwable err); 11 | } 12 | -------------------------------------------------------------------------------- /acteur-util/src/main/java/com/mastfrog/acteur/util/HttpMethod.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.util; 2 | 3 | import com.mastfrog.util.strings.Strings; 4 | 5 | /** 6 | * 7 | * @author Tim Boudreau 8 | */ 9 | public interface HttpMethod { 10 | 11 | String name(); 12 | 13 | CharSequence toCharSequence(); 14 | 15 | /** 16 | * Checks equivalency with other libraries or string's classes that 17 | * represent HTTP methods, using the string value (name if an enum, 18 | * otherwise toString()); can also be used passing a String or 19 | * CharSequence. 20 | * 21 | * @param o Some object that might represent this HTTP method 22 | * @return True if it appears to 23 | */ 24 | default boolean is(Object o) { 25 | if (o == this) { 26 | return true; 27 | } else if (o == null) { 28 | return false; 29 | } else if (o instanceof HttpMethod) { 30 | CharSequence a = toCharSequence(); 31 | CharSequence b = ((HttpMethod) o).toCharSequence(); 32 | return Strings.charSequencesEqual(a, b, true); 33 | } else if (o instanceof Enum) { 34 | Enum e = (Enum) o; 35 | return name().equals(e.name()); 36 | } else if (o instanceof String) { 37 | return ((String) o).equalsIgnoreCase(name()); 38 | } else if (o instanceof CharSequence) { 39 | return Strings.charSequencesEqual(toCharSequence(), (CharSequence) o, true); 40 | } else { 41 | return o.toString().equalsIgnoreCase(name()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /acteur-util/src/main/java/com/mastfrog/acteur/util/RotatingRealmProvider.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.util; 2 | 3 | import com.mastfrog.settings.Settings; 4 | import com.mastfrog.util.strings.Strings; 5 | import com.mastfrog.util.strings.RandomStrings; 6 | import java.time.Duration; 7 | import java.time.temporal.ChronoUnit; 8 | import javax.inject.Inject; 9 | import javax.inject.Provider; 10 | import javax.inject.Singleton; 11 | 12 | /** 13 | * Provides an authentication realm which changes every hour or whatever 14 | * interval is specified 15 | * 16 | * @author Tim Boudreau 17 | */ 18 | @Singleton 19 | public final class RotatingRealmProvider implements Provider { 20 | 21 | public static final String SETTINGS_KEY_ROTATE_INTERVAL_MINUTES = "realm.rotate.interval.minutes"; 22 | public static final int DEFAULT_ROTATE_INTERVAL = 60; 23 | private static final RandomStrings rs = new RandomStrings(); 24 | private final Duration interval; 25 | private final String salt; 26 | 27 | @Inject 28 | RotatingRealmProvider(Settings s) { 29 | interval = Duration.of(s.getInt(SETTINGS_KEY_ROTATE_INTERVAL_MINUTES, DEFAULT_ROTATE_INTERVAL), ChronoUnit.MINUTES); 30 | salt = rs.get(4); 31 | } 32 | 33 | @Override 34 | public Realm get() { 35 | Duration since1970 = Duration.ofMillis(System.currentTimeMillis()); 36 | long minutesSince1970 = since1970.toMinutes(); 37 | long intervals = minutesSince1970 / interval.toMinutes(); 38 | return new Realm(Strings.interleave(Long.toString(intervals, 36), salt)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /acteur-util/src/main/java/com/mastfrog/acteur/util/ServerControl.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.util; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.Condition; 5 | 6 | /** 7 | * Handle with which a server can be interrogated about its state or shut down; 8 | * implements Condition for backward compatibility with early versions of this 9 | * library. The signal() and signalAll() methods initiate a graceful shutdown 10 | * where running requests are concluded; shutdown with an argument of true 11 | * for immediately will interrupt threads and trigger immediate shutdown. 12 | * 13 | * @author Tim Boudreau 14 | */ 15 | public interface ServerControl extends Condition { 16 | /** 17 | * Shut down, waiting for thread pools to terminate and connections to 18 | * be closed (unlike getCondition().signal()). 19 | * @param immediately If thread pools should be shut down without 20 | * processing any pending work 21 | * @param timeout How long to wait for shutdown (may nonetheless wait 22 | * longer since closing the channel does not afford a timeout) 23 | * @param unit A time unit 24 | * @throws InterruptedException 25 | */ 26 | void shutdown(boolean immediately, long timeout, TimeUnit unit) throws InterruptedException; 27 | /** 28 | * Shut down and wait for termination 29 | * @param immediately If thread pools should be shut down without 30 | * processing pending work 31 | * @throws InterruptedException If something interrupts shutdown 32 | */ 33 | void shutdown(boolean immediately) throws InterruptedException; 34 | 35 | int getPort(); 36 | } 37 | -------------------------------------------------------------------------------- /acteur-util/src/test/java/com/mastfrog/acteur/util/PasswordHasherTest.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.util; 2 | 3 | import com.mastfrog.settings.SettingsBuilder; 4 | import java.io.IOException; 5 | import java.nio.charset.Charset; 6 | import java.security.NoSuchAlgorithmException; 7 | import static org.junit.Assert.assertFalse; 8 | import static org.junit.Assert.assertNotEquals; 9 | import static org.junit.Assert.assertNotNull; 10 | import static org.junit.Assert.assertTrue; 11 | import org.junit.Test; 12 | 13 | /** 14 | * 15 | * @author Tim Boudreau 16 | */ 17 | public class PasswordHasherTest { 18 | 19 | @Test 20 | public void testCheckPassword() throws IOException, NoSuchAlgorithmException { 21 | assertTrue(true); 22 | PasswordHasher h = new PasswordHasher(new SettingsBuilder().build(), Charset.forName("UTF-8")); 23 | 24 | String pw = "password"; 25 | String enc = h.encryptPassword(pw); 26 | assertNotNull(enc); 27 | 28 | String pw2 = "somethingElse"; 29 | String enc2 = h.encryptPassword(pw2); 30 | assertNotNull(enc2); 31 | 32 | assertNotEquals(enc, enc2); 33 | 34 | boolean matches = h.checkPassword(pw2, enc2); 35 | assertTrue(matches); 36 | 37 | matches = h.checkPassword(pw, enc); 38 | assertTrue(matches); 39 | 40 | matches = h.checkPassword(pw2, enc); 41 | assertFalse(matches); 42 | 43 | matches = h.checkPassword(pw, enc2); 44 | assertFalse(matches); 45 | 46 | String old = "a:Du4EC8d82VujiPSlommA2XHrQLtUvytrowONoiG5q0yjG3Ed:4jhJV/hZ4Ab0liMsX0HDG/qJCIvgPCqyAeVB69n+ZdOWNWTXOCypD+WlzJELpKQ1/8tHL6jI709ogWTiJt0/9Q=="; 47 | assertTrue("Something has broken password compatibility", h.checkPassword("somethingElse", old)); 48 | old = "a:3wWOjtsJci7mL3wknhhtCsZnNmywjXI9w39Y2SiUVIfOaA2s:XZ6i/sDDGW0tEGYW3Bbcg1BitWugNm8DNQnx1p7CowRj9b0tkUQXRwqez60rSmRnBqOSRDw/4FUcg43fdliCZw=="; 49 | assertTrue("Something has broken password compatibility", h.checkPassword("password", old)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /acteur-util/src/test/java/com/mastfrog/acteur/util/RotatingRealmProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.util; 25 | 26 | import com.mastfrog.settings.Settings; 27 | import org.junit.Test; 28 | import static org.junit.Assert.*; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public class RotatingRealmProviderTest { 35 | 36 | @Test 37 | public void testDurationConversionWorks() { 38 | RotatingRealmProvider prov = new RotatingRealmProvider(Settings.EMPTY); 39 | Realm realm = prov.get(); 40 | assertEquals(realm, prov.get()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /acteur/.attach_pid31540: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timboudreau/acteur/1b273e55ab5ae7e387fc7452b0a956f41122709f/acteur/.attach_pid31540 -------------------------------------------------------------------------------- /acteur/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/CORSResponseDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur; 25 | 26 | import com.google.inject.ImplementedBy; 27 | import io.netty.handler.codec.http.HttpResponse; 28 | 29 | /** 30 | * Decorates cors responses. 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | @ImplementedBy(CORSResponseDecoratorImpl.class) 35 | public interface CORSResponseDecorator { 36 | 37 | /** 38 | * Adds headers to an acteur response. 39 | * 40 | * @param evt The event 41 | * @param resp The response headers should be added to. 42 | */ 43 | void decorateCorsPreflight(HttpEvent evt, Response resp, Page page); 44 | 45 | /** 46 | * Adds headers to application-level responses such as Not Found and errors 47 | * 48 | * @param response 49 | */ 50 | default void decorateApplicationResponse(HttpResponse response) { 51 | // do nothing 52 | } 53 | 54 | default void decorateApplicationResponse(HttpResponse response, Page page) { 55 | decorateApplicationResponse(response); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/FailureResponseFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur; 25 | 26 | import io.netty.handler.codec.http.HttpResponse; 27 | 28 | /** 29 | * Bind in guice to customize 404 not found responses, and failures that cannot 30 | * be handled by ErrorRenderer (i.e. something threw an exception in it) - i.e. 31 | * last-ditch handling for exceptions other than closing the connection. 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | public interface FailureResponseFactory { 36 | 37 | HttpResponse createNotFoundResponse(Event evt); 38 | 39 | HttpResponse createFallbackResponse(Throwable thrown); 40 | } 41 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/Help.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur; 2 | 3 | import com.mastfrog.giulius.annotations.Setting; 4 | import static com.mastfrog.giulius.annotations.Setting.Tier.TERTIARY; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * If this annotation appears on an Application, it automatically makes a Help 12 | * page available. 13 | * 14 | * @author Tim Boudreau 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.TYPE) 18 | public @interface Help { 19 | 20 | @Setting(value = "Defines a regular expression used for the URL path for JSON help", 21 | defaultValue = "^help$", tier = TERTIARY) 22 | public static final String HELP_URL_PATTERN_SETTINGS_KEY = "helpUrlPattern"; 23 | 24 | @Setting(value = "Defines a regular expression used to match the URL path for HTML help", 25 | defaultValue = "\"^help\\\\.html$\"", tier = TERTIARY) 26 | public static final String HELP_HTML_URL_PATTERN_SETTINGS_KEY = "helpHtmlUrlPattern"; 27 | 28 | String value() default ""; 29 | } 30 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/RequestLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur; 25 | 26 | import com.google.inject.ImplementedBy; 27 | import com.mastfrog.acteur.util.RequestID; 28 | import io.netty.handler.codec.http.HttpResponseStatus; 29 | 30 | /** 31 | * Logger which can be injected, which takes care of actually logging each 32 | * request and response. 33 | * 34 | * @author Tim Boudreau 35 | */ 36 | @ImplementedBy(DefaultRequestLogger.class) 37 | public interface RequestLogger { 38 | 39 | public static RequestLogger SILENT = (rid, evt, status) -> { 40 | }; 41 | 42 | default void onBeforeEvent(RequestID rid, Event event) { 43 | // do nothing 44 | } 45 | 46 | void onRespond(RequestID rid, Event event, HttpResponseStatus status); 47 | } 48 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/ResponseDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2018 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur; 25 | 26 | import io.netty.handler.codec.http.HttpResponseStatus; 27 | 28 | /** 29 | * 30 | * @author Tim Boudreau 31 | */ 32 | public interface ResponseDecorator { 33 | 34 | void onBeforeSendResponse(Application application, HttpResponseStatus status, 35 | Event event, Response response, Acteur acteur, Page page); 36 | } 37 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/ResponseSender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur; 25 | 26 | /** 27 | * Actually sends the response to a request 28 | * 29 | * @author Tim Boudreau 30 | */ 31 | interface ResponseSender extends Thread.UncaughtExceptionHandler { 32 | void receive(Acteur action, com.mastfrog.acteur.State state, ResponseImpl response); 33 | } 34 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/annotations/Concluders.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.mastfrog.acteur.Acteur; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * Annotation which is only useful on Acteurs with the HttpCall annotation to 11 | * trigger page source generation, which specifies some more Acteurs to run 12 | * after the annotated one. 13 | * 14 | * @author Tim Boudreau 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.TYPE) 18 | public @interface Concluders { 19 | 20 | Class[] value(); 21 | } 22 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/annotations/Precursors.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.mastfrog.acteur.Acteur; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * Annotation which is only useful on Acteurs with the HttpCall annotation 11 | * to trigger page source generation, which specifies some more Acteurs 12 | * to run before the annotated one. 13 | * 14 | * @author Tim Boudreau 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target(ElementType.TYPE) 18 | public @interface Precursors { 19 | Class[] value(); 20 | } 21 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/auth/AuthenticationActeur.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.auth; 2 | 3 | import com.google.inject.ImplementedBy; 4 | import com.mastfrog.acteur.Acteur; 5 | 6 | /** 7 | * 8 | * @author Tim Boudreau 9 | */ 10 | @SuppressWarnings("deprecation") 11 | @ImplementedBy(AuthenticateBasicActeur.class) 12 | public class AuthenticationActeur extends Acteur { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.auth; 25 | 26 | import com.google.inject.ImplementedBy; 27 | import com.mastfrog.acteur.header.entities.BasicCredentials; 28 | import java.io.IOException; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | @ImplementedBy(MockAuthenticator.class) 35 | public interface Authenticator { 36 | /** 37 | * Handles authentication, saying yea or nay. 38 | * 39 | * @param realm The Realm object used in authentication 40 | * @param credentials The credentials 41 | * @return An array of objects to inject into later acteurs if successful, 42 | * null on failure 43 | * @throws IOException if something goes wrong 44 | */ 45 | Object[] authenticate(String realm, BasicCredentials credentials) throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/auth/Tarpit.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.auth; 2 | 3 | import com.google.inject.ImplementedBy; 4 | import com.mastfrog.acteur.HttpEvent; 5 | import com.mastfrog.giulius.annotations.Setting; 6 | 7 | /** 8 | * Used by AuthenticateBasicActeur. Too many failed password attempts and you go 9 | * in the tar pit - first responses are delayed, then blocked altogether. 10 | *

11 | * Callers are identified by default by their IP address, but you can inject a 12 | * TarpitCacheKeyFactory to look at cookies or whatever you want. 13 | * 14 | * @author Tim Boudreau 15 | */ 16 | @ImplementedBy(TarpitImpl.class) 17 | public interface Tarpit { 18 | 19 | @Setting(value = "BasicAuth: Number of minutes a host should be banned", type = Setting.ValueType.INTEGER, defaultValue = "5") 20 | public static final String SETTINGS_KEY_TARPIT_EXPIRATION_TIME_MINUTES 21 | = "tarpit.default.expiration.minutes"; 22 | public static final int DEFAULT_TARPIT_EXPIRATION_TIME_MINUTES = 5; 23 | 24 | /** 25 | * Add an entry to the tarpit for failing to authenticate, incrementing the 26 | * count if necessary. 27 | * 28 | * @param evt The http request 29 | * @return The updated number of bad requests 30 | */ 31 | public int add(HttpEvent evt); 32 | 33 | /** 34 | * Get the number of bad requests 35 | * 36 | * @param evt An http request 37 | * @return The 38 | */ 39 | public int count(HttpEvent evt); 40 | 41 | public void remove(HttpEvent evt); 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/auth/TarpitCacheKeyFactory.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.auth; 2 | 3 | import com.mastfrog.acteur.HttpEvent; 4 | import java.net.InetSocketAddress; 5 | import java.net.SocketAddress; 6 | 7 | /** 8 | * 9 | * @author tim 10 | */ 11 | public class TarpitCacheKeyFactory { 12 | 13 | /** 14 | * Construct a cache key 15 | * @param evt An http request 16 | * @return The key or null if none can be computed 17 | */ 18 | public String createKey(HttpEvent evt) { 19 | SocketAddress addr = evt.remoteAddress(); 20 | if (!(addr instanceof InetSocketAddress)) { 21 | return null; 22 | } 23 | String remoteAddress = ((InetSocketAddress) addr).getHostString(); 24 | return remoteAddress; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/debug/DefaultProbe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.debug; 25 | 26 | import com.google.inject.Singleton; 27 | import javax.inject.Inject; 28 | 29 | /** 30 | * Default implementation of Probe. 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | @Singleton 35 | class DefaultProbe implements Probe { 36 | // all methods have default bodies, do nothing here 37 | 38 | @Inject 39 | DefaultProbe() { 40 | // constructor for Graal's native-image code to detect 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/AuthenticatedIf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.Annotation; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * Marks an endpoint as authenticated if the named setting is set to true. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | public @interface AuthenticatedIf { 40 | String setting(); 41 | String value() default "default"; 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/BannedUrlParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * 33 | * @author tim 34 | */ 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target(ElementType.TYPE) 37 | @Description("URL parameters which are not allowed") 38 | public @interface BannedUrlParameters { 39 | String[] value(); 40 | } 41 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/BasicAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Indicates that a page requires authentication. The name is a misnomer, since 33 | * it can indicate any authentication scheme. 34 | * 35 | * @deprecated Use @Authenticated instead 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Requires authentication") 42 | @Deprecated 43 | public @interface BasicAuth { 44 | 45 | } 46 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/Description.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Provide a description for a page or acteur which will be used by 33 | * Application.getHelpPageType() to provide an API-level help call. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | public @interface Description { 40 | String value(); 41 | 42 | String category() default "Web-API"; 43 | } 44 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/InjectRequestBodyAs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Make the request body available as the passed type. Note that this type must 33 | * also be in the application's @ImplicitBindings annotation, or in the 34 | * @HttpCall annotation's scopeTypes parameter of at least one 35 | * Acteur to be available to Guice. Annotation which can appear on an Acteur 36 | * with the @HttpCall annotation or on a Page with that annotation. 37 | * 38 | * @author Tim Boudreau 39 | */ 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Target(ElementType.TYPE) 42 | @Description("Inject the request body as a specific type") 43 | public @interface InjectRequestBodyAs { 44 | 45 | Class value(); 46 | } 47 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/MaximumPathLength.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Specifies a maximum number of / separated elements in the URL path, 33 | * for use Acteurs which use the tail of the URL path as an open-ended list 34 | * of something. 35 | * Annotation which can appear on an Acteur with the @HttpCall annotation 36 | * or on a Page with that annotation. 37 | * 38 | * @author Tim Boudreau */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Maximum number of path elements in URL path") 42 | public @interface MaximumPathLength { 43 | int value(); 44 | } 45 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/MaximumRequestBodyLength.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * 33 | * Annotation which can appear on an Acteur with the @HttpCall annotation 34 | * or on a Page with that annotation. Specifies a maximum length for the 35 | * request body, which is computed without necessarily parsing that body. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Maximum length of the request body") 42 | public @interface MaximumRequestBodyLength { 43 | 44 | int value(); 45 | } 46 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/Methods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import com.mastfrog.acteur.headers.Method; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * Annotation which can be set on Page classes to determine what methods are 34 | * respond to. Equivalent of using ActeurFactory.matchMethods in the 35 | * constructor. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Match HTTP methods") 42 | public @interface Methods { 43 | 44 | Method[] value() default Method.GET; 45 | } 46 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/MinimumRequestBodyLength.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which can appear on an Acteur with the @HttpCall annotation 33 | * or on a Page with that annotation. If the request body - the body of a 34 | * POST or PUT operation - is less than the specified number of characters, 35 | * the request will be rejected with BAD REQUEST. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Minimum length of the request body") 42 | public @interface MinimumRequestBodyLength { 43 | 44 | int value(); 45 | } 46 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/ParametersMustBeNumbersIfPresent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which can appear on an Acteur with the @HttpCall annotation 33 | * or on a Page with that annotation. Specifies that the passed url parameters 34 | * must be numbers (with the expressed constraints) if present or the 35 | * request should be rejected with BAD REQUEST. 36 | * 37 | * @author Tim Boudreau 38 | */ 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Target(ElementType.TYPE) 41 | @Description("Parameters must be numbers if present") 42 | public @interface ParametersMustBeNumbersIfPresent { 43 | String[] value(); 44 | boolean allowDecimal() default false; 45 | boolean allowNegative() default true; 46 | } 47 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/Path.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Specifieds a glob-style URL path, such as /mything/* - a * can represent 33 | * anything but a / character. Used for simpler matching than full-blown 34 | * regular expression evaluation (which it is translated to at runtime). 35 | * 36 | * Annotation which can appear on an Acteur with the @HttpCall annotation 37 | * or on a Page with that annotation. 38 | * 39 | * @author Tim Boudreau 40 | */ 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target(ElementType.TYPE) 43 | @Description("Glob-style URL Path, e.g. /api/*/foo") 44 | public @interface Path { 45 | String[] value(); 46 | 47 | boolean decode() default false; 48 | } 49 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/PathRegex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which determines regular expressions used to determine whether a 33 | * page responds to a given request. 34 | * 35 | * Annotation which can appear on an Acteur with the @HttpCall annotation 36 | * or on a Page with that annotation. 37 | * 38 | * @author Tim Boudreau 39 | */ 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Target(ElementType.TYPE) 42 | @Description("Regular expression URL path") 43 | public @interface PathRegex { 44 | 45 | String[] value(); 46 | 47 | boolean decode() default false; 48 | } 49 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/RequireAtLeastOneUrlParameterFrom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which can appear on an Acteur with the @HttpCall annotation 33 | * or on a Page with that annotation. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | @Description("Require at least one of these URL parameters") 40 | public @interface RequireAtLeastOneUrlParameterFrom { 41 | String[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/RequireParametersIfMethodMatches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import com.mastfrog.acteur.headers.Method; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * Annotation which can appear on an Acteur with the @HttpCall annotation 34 | * or on a Page with that annotation. 35 | * 36 | * @author Tim Boudreau 37 | */ 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target(ElementType.TYPE) 40 | @Description("If a particular HTTP method matches, require some set of parameters") 41 | public @interface RequireParametersIfMethodMatches { 42 | public String[] value(); 43 | public Method method(); 44 | } 45 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/RequiredUrlParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which causes a Page to return 400 Bad Request if the 33 | * url parameters do not match what the annotation describes. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | @Description("Required URL parameters") 40 | public @interface RequiredUrlParameters { 41 | 42 | String[] value(); 43 | 44 | Combination combination() default Combination.ALL; 45 | 46 | public enum Combination { 47 | 48 | ALL, 49 | AT_LEAST_ONE 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/UrlParametersMayNotBeCombined.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which can appear on an Acteur with the @HttpCall annotation 33 | * or on a Page with that annotation. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | @Description("Specifies a combination of URL parameters which may not appear together") 40 | public @interface UrlParametersMayNotBeCombined { 41 | String[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/preconditions/UrlParametersMayNotBeCombinedSets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 tim. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.preconditions; 25 | 26 | import java.lang.annotation.ElementType; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | import java.lang.annotation.Target; 30 | 31 | /** 32 | * Annotation which can appear on an Acteur with the @HttpCall annotation 33 | * or on a Page with that annotation. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target(ElementType.TYPE) 39 | @Description("Groups of URL parameters which may not appear in combination") 40 | public @interface UrlParametersMayNotBeCombinedSets { 41 | UrlParametersMayNotBeCombined[] value(); 42 | } 43 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/server/DefaultPipelineDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Tim Boudreau 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.server; 25 | 26 | import io.netty.channel.ChannelPipeline; 27 | import javax.inject.Inject; 28 | 29 | /** 30 | * Default impl 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | class DefaultPipelineDecorator implements PipelineDecorator { 35 | 36 | @Inject 37 | public DefaultPipelineDecorator() { 38 | // constructor for Graal's native-image code to detect 39 | } 40 | 41 | @Override 42 | public void onCreatePipeline(ChannelPipeline pipeline) { 43 | //do nothing 44 | } 45 | 46 | @Override 47 | public void onPipelineInitialized(ChannelPipeline pipeline) { 48 | //do nothing 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/server/ServerBootstrapConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2018 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.server; 25 | 26 | import com.google.inject.ImplementedBy; 27 | import com.mastfrog.settings.Settings; 28 | import io.netty.bootstrap.ServerBootstrap; 29 | 30 | /** 31 | * Bind this if you want to customize Netty's server bootstrap on server initialization 32 | * (used to install a logging channel factory for logging surprise channel closures and 33 | * similar). 34 | */ 35 | @ImplementedBy(value = ServerModule.NoOpServerBootstrapConfigurer.class) 36 | public interface ServerBootstrapConfigurer { 37 | 38 | ServerBootstrap configureServerBootstrap(ServerBootstrap bootstrap, Settings settings); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/server/UnknownNetworkEventHandler.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.server; 2 | 3 | import com.google.inject.ImplementedBy; 4 | import com.mastfrog.acteur.server.UnknownNetworkEventHandler.UNEH; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * Handler which can receive Netty events which the framework cannot directly 10 | * handle. 11 | * 12 | * @author Tim Boudreau 13 | */ 14 | @ImplementedBy(UNEH.class) 15 | public abstract class UnknownNetworkEventHandler { 16 | 17 | protected abstract void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception; 18 | 19 | static final class UNEH extends UnknownNetworkEventHandler { 20 | 21 | @Inject 22 | UNEH() { 23 | // constructor for Graal's native-image code to detect 24 | } 25 | 26 | @Override 27 | protected void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 28 | System.out.println("Don't know how to process " + msg + " " + msg.getClass().getName()); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/server/WebSocketEvent.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.server; 2 | 3 | import com.mastfrog.acteur.Event; 4 | import com.mastfrog.util.codec.Codec; 5 | import io.netty.buffer.ByteBuf; 6 | import io.netty.buffer.ByteBufInputStream; 7 | import io.netty.channel.Channel; 8 | import io.netty.channel.ChannelHandlerContext; 9 | import io.netty.handler.codec.http.websocketx.WebSocketFrame; 10 | import java.io.IOException; 11 | import java.net.SocketAddress; 12 | 13 | /** 14 | * 15 | * @author Tim Boudreau 16 | */ 17 | public final class WebSocketEvent implements Event { 18 | 19 | private final WebSocketFrame frame; 20 | private final ChannelHandlerContext channel; 21 | private final SocketAddress addr; 22 | private final Codec mapper; 23 | 24 | public WebSocketEvent(WebSocketFrame frame, ChannelHandlerContext channel, SocketAddress addr, Codec mapper) { 25 | this.frame = frame; 26 | this.channel = channel; 27 | this.addr = addr; 28 | this.mapper = mapper; 29 | } 30 | 31 | @Override 32 | public Channel channel() { 33 | return channel.channel(); 34 | } 35 | 36 | @Override 37 | public ChannelHandlerContext ctx() { 38 | return channel; 39 | } 40 | 41 | @Override 42 | public WebSocketFrame request() { 43 | return frame; 44 | } 45 | 46 | @Override 47 | public SocketAddress remoteAddress() { 48 | return addr; 49 | } 50 | 51 | @Override 52 | public T jsonContent(Class type) throws IOException { 53 | return mapper.readValue(new ByteBufInputStream(frame.content()), type); 54 | } 55 | 56 | @Override 57 | public ByteBuf content() throws IOException { 58 | return frame.content(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /acteur/src/main/java/com/mastfrog/acteur/websocket/DefaultOnWebsocketConnect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur.websocket; 26 | 27 | import com.mastfrog.acteur.HttpEvent; 28 | import io.netty.channel.Channel; 29 | 30 | /** 31 | * Default noop implementation. 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | final class DefaultOnWebsocketConnect implements OnWebsocketConnect { 36 | 37 | @Override 38 | public Object connected(HttpEvent evt, Channel channel) { 39 | // do nothing 40 | return null; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/SilentRequestLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.acteur; 26 | 27 | import com.google.inject.Binder; 28 | import com.google.inject.Module; 29 | import com.mastfrog.acteur.util.RequestID; 30 | import io.netty.handler.codec.http.HttpResponseStatus; 31 | 32 | /** 33 | * Quiets down the logger for tests. 34 | * 35 | * @author Tim Boudreau 36 | */ 37 | public class SilentRequestLogger implements RequestLogger, Module { 38 | 39 | @Override 40 | public void onBeforeEvent(RequestID rid, Event event) { 41 | // do nothing 42 | } 43 | 44 | @Override 45 | public void onRespond(RequestID rid, Event event, HttpResponseStatus status) { 46 | // do nothing 47 | } 48 | 49 | @Override 50 | public void configure(Binder binder) { 51 | binder.bind(RequestLogger.class).toInstance(this); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/annotations/AnotherPage.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.mastfrog.acteur.annotations.HttpCall; 4 | import com.mastfrog.acteur.Page; 5 | 6 | /** 7 | * 8 | * @author Tim Boudreau 9 | */ 10 | @HttpCall(order=2000) 11 | public class AnotherPage extends Page { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/annotations/FakePage.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.mastfrog.acteur.annotations.HttpCall; 4 | import com.mastfrog.acteur.Page; 5 | import com.mastfrog.acteur.annotations.FakePage.Foo.Bar; 6 | import com.mastfrog.util.strings.RandomStrings; 7 | 8 | /** 9 | * 10 | * @author Tim Boudreau 11 | */ 12 | @HttpCall(order=1000, scopeTypes = {String.class, Integer.class, RandomStrings.class, Bar.class}) 13 | public class FakePage extends Page { 14 | 15 | 16 | public static class Foo { 17 | public static class Bar { 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/annotations/X.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.mastfrog.acteur.Acteur; 4 | import com.mastfrog.acteur.annotations.FakePage.Foo; 5 | import com.mastfrog.acteur.annotations.FakePage.Foo.Bar; 6 | import com.mastfrog.acteur.annotations.X.Barble; 7 | import com.mastfrog.acteur.annotations.X.Fooble; 8 | import com.mastfrog.acteur.headers.Method; 9 | import static com.mastfrog.acteur.headers.Method.GET; 10 | import com.mastfrog.acteur.preconditions.Methods; 11 | import com.mastfrog.acteur.preconditions.PathRegex; 12 | 13 | /** 14 | * 15 | * @author Tim Boudreau 16 | */ 17 | @HttpCall(order = 30000, scopeTypes = {Foo.class, Bar.class}) 18 | @PathRegex("^foo\\/bar$") 19 | @Methods({GET, Method.DELETE}) 20 | @Precursors({Fooble.class, Barble.class}) 21 | public class X extends Acteur { 22 | 23 | static class Fooble extends Acteur { 24 | 25 | Fooble() { 26 | next(new Foo()); 27 | } 28 | } 29 | 30 | static class Barble extends Acteur { 31 | 32 | } 33 | 34 | public static class Foo { 35 | 36 | } 37 | public static class Bar { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/annotations/ZZZPage.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.annotations; 2 | 3 | import com.google.inject.Inject; 4 | import com.mastfrog.acteur.ActeurFactory; 5 | import com.mastfrog.acteur.annotations.HttpCall; 6 | import com.mastfrog.acteur.Page; 7 | import io.netty.handler.codec.http.HttpResponseStatus; 8 | 9 | /** 10 | * 11 | * @author Tim Boudreau 12 | */ 13 | @HttpCall(order=-1) 14 | public class ZZZPage extends Page { 15 | 16 | @Inject 17 | ZZZPage(ActeurFactory af) { 18 | add(af.respondWith(HttpResponseStatus.CREATED, "Foo.")); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /acteur/src/test/java/com/mastfrog/acteur/server/EventImplFactory.java: -------------------------------------------------------------------------------- 1 | package com.mastfrog.acteur.server; 2 | 3 | import com.mastfrog.acteur.Event; 4 | import io.netty.handler.codec.http.HttpRequest; 5 | 6 | /** 7 | * 8 | * @author Tim Boudreau 9 | */ 10 | public class EventImplFactory { 11 | public static Event newEvent(HttpRequest req, PathFactory paths) { 12 | return new EventImpl(req, paths); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/ComprehensiveTest.properties: -------------------------------------------------------------------------------- 1 | neverKeepAlive=true 2 | #port=4231 3 | bindAddress=127.0.0.1 4 | #aggregateChunks=false 5 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/InternalsTest.properties: -------------------------------------------------------------------------------- 1 | cors.enabled=true 2 | neverKeepAlive=true 3 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/PathFactoryTest.properties: -------------------------------------------------------------------------------- 1 | basepath=foo/bar 2 | port=8080 3 | hostname=example.com 4 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/PutTest.properties: -------------------------------------------------------------------------------- 1 | httpCompression=false 2 | neverKeepAlive=true 3 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/TestAnnotations.properties: -------------------------------------------------------------------------------- 1 | #neverKeepAlive=true 2 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/annotations/GenericApplicationTest: -------------------------------------------------------------------------------- 1 | port=12304 2 | -------------------------------------------------------------------------------- /acteur/src/test/resources/com/mastfrog/acteur/sse/SseTest.properties: -------------------------------------------------------------------------------- 1 | port=12735 2 | -------------------------------------------------------------------------------- /acteur/theugly.txt: -------------------------------------------------------------------------------- 1 | 2 | Bits of history that could be discarded: 3 | 4 | - Odd that decororateResponse, create404response take a Netty HttpResponse, 5 | rather than an acteur Response - just an artifact of the early days 6 | 7 | - Etag and LastModified checking annotations only work if you set the 8 | header on the page - should create a communication path for the partially 9 | built responses before they are coalesced - right now each acteur only 10 | sees its own empty response 11 | 12 | - Page.getResponseHeaders() is duplicative and violates the DRY principle, 13 | but needed until the above is fixed 14 | 15 | - Can no longer inject an HttpEvent into a page constructor because it is 16 | not in-scope during page instantiation. Easy fix in acteur-base, but would 17 | prefer to make Page less necessary rather than encourage subclassing it 18 | 19 | - HackHttpHeaders is problematic - Netty 3 allowed for sending raw ByteBufs 20 | down the pipe; Netty 4 requires chunked encoding for incremental responses. 21 | Hacking this support back in meant some fussing with Netty's HTTP codec. 22 | This means we go to war with Netty's HTTP codec which wants to set incorrect 23 | values for transfer-encoding; and sending ByteBufs wreaks havoc with the 24 | HttpContentCompressor, and forces us to have a fork of HttpObjectAggregator. 25 | Supposedly this will improve in a threatened rewrite of Netty's HTTP codec, 26 | so support is still there - but that hasn't happened yet. 27 | -------------------------------------------------------------------------------- /marshaller-registry/index-reflection.marker: -------------------------------------------------------------------------------- 1 | This file's presence activates the reflection-indexing profile in mastfrog-parent, 2 | which will cause META-INF/injection/reflective.json to be generated, which can be used 3 | by SubstrateVM for generating a native, ahead-of-time-compiled binary of a Java application. 4 | 5 | The index will include all methods, fields and constructors which must be available via 6 | reflection for instantiation by Guice, Jackson or similar. 7 | -------------------------------------------------------------------------------- /marshaller-registry/src/main/java/com/mastfrog/marshallers/Marshaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.marshallers; 25 | 26 | /** 27 | * Reads and writes objects into stream-like data stores. 28 | * 29 | * @author Tim Boudreau 30 | */ 31 | public interface Marshaller { 32 | 33 | /** 34 | * Read an object from the passed data store. 35 | * 36 | * @param data The data, such as a ByteBuffer 37 | * @param hints Type-specific hints, such as a Charset to use for string 38 | * conversion to bytes. 39 | * @return An object 40 | * @throws Exception If something goes wrong 41 | */ 42 | T read(R data, Object[] hints) throws Exception; 43 | 44 | /** 45 | * Write an objecct into the passed data store. 46 | * 47 | * @param obj The object to write 48 | * @param into The store to write it into 49 | * @param hints Type-specific hints, such as a Charset to use for string 50 | * conversion to bytes. 51 | * @throws Exception If something goes wrong 52 | */ 53 | void write(T obj, R into, Object[] hints) throws Exception; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /marshaller-registry/src/main/java/com/mastfrog/marshallers/netty/ByteArrayInterpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.marshallers.netty; 26 | 27 | import io.netty.buffer.ByteBuf; 28 | import com.mastfrog.marshallers.Marshaller; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class ByteArrayInterpreter implements Marshaller { 35 | 36 | @Override 37 | public byte[] read(ByteBuf data, Object[] hints) throws Exception { 38 | byte[] bytes = new byte[data.readableBytes()]; 39 | data.getBytes(0, bytes); 40 | return bytes; 41 | } 42 | 43 | @Override 44 | public void write(byte[] obj, ByteBuf into, Object[] hints) throws Exception { 45 | into.writeBytes(obj); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /marshaller-registry/src/main/java/com/mastfrog/marshallers/netty/ByteBufMarshaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.marshallers.netty; 25 | 26 | import io.netty.buffer.ByteBuf; 27 | import com.mastfrog.marshallers.Marshaller; 28 | 29 | /** 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | final class ByteBufMarshaller implements Marshaller { 34 | 35 | @Override 36 | public ByteBuf read(ByteBuf data, Object[] hints) throws Exception { 37 | return data; 38 | } 39 | 40 | @Override 41 | public void write(ByteBuf obj, ByteBuf into, Object[] hints) throws Exception { 42 | if (into == obj) { 43 | return; 44 | } 45 | into.writeBytes(obj); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /marshaller-registry/src/main/java/com/mastfrog/marshallers/netty/ByteBufferMarshaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.marshallers.netty; 25 | 26 | import io.netty.buffer.ByteBuf; 27 | import java.nio.ByteBuffer; 28 | import com.mastfrog.marshallers.Marshaller; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | final class ByteBufferMarshaller implements Marshaller { 35 | 36 | @Override 37 | public ByteBuffer read(ByteBuf data, Object[] hints) throws Exception { 38 | if (data.isDirect()) { 39 | return data.internalNioBuffer(0, data.readableBytes()); 40 | } else { 41 | ByteBuffer buffer = ByteBuffer.allocateDirect(data.readableBytes()); 42 | data.readBytes(buffer); 43 | return (ByteBuffer) buffer.flip(); 44 | } 45 | } 46 | 47 | @Override 48 | public void write(ByteBuffer obj, ByteBuf into, Object[] hints) throws Exception { 49 | into.writeBytes(obj); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /marshaller-registry/src/main/java/com/mastfrog/marshallers/netty/CharSequenceInterperter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.mastfrog.marshallers.netty; 26 | 27 | import io.netty.buffer.ByteBuf; 28 | import java.nio.charset.Charset; 29 | import com.mastfrog.marshallers.Marshaller; 30 | 31 | /** 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | final class CharSequenceInterperter implements Marshaller { 36 | 37 | @Override 38 | public CharSequence read(ByteBuf data, Object[] hints) throws Exception { 39 | Charset charset = NettyContentMarshallers.findCharset(hints); 40 | return data.getCharSequence(0, data.readableBytes(), charset); 41 | } 42 | 43 | @Override 44 | public void write(CharSequence obj, ByteBuf into, Object[] hints) throws Exception { 45 | Charset charset = NettyContentMarshallers.findCharset(hints); 46 | into.writeCharSequence(obj, charset); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /mime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.mastfrog 6 | mastfrog-parent 7 | 2.9.7 8 | 9 | mime 10 | 11 | Mime 12 | 13 | 14 | A standalone MIME-type parser, with API that is a near-drop-in 15 | replacement for Guava's MediaType, minus the bulk. No runtime dependencies. 16 | 17 | 18 | 19 | 20 | org.junit.jupiter 21 | junit-jupiter-api 22 | test 23 | 24 | 25 | org.junit.jupiter 26 | junit-jupiter-params 27 | test 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-engine 32 | test 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /netty-websocket-pubsub/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 4.0.0 9 | 10 | 11 | com.mastfrog 12 | mastfrog-parent 13 | 2.9.7 14 | 15 | 16 | 17 | netty-websocket-pubsub 18 | 19 | https://github.com/timboudreau/acteur 20 | 21 | 22 | https://github.com/timboudreau/acteur.git 23 | scm:git:https://github.com/timboudreau/acteur.git 24 | git@github.com/timboudreau/acteur.git 25 | 26 | 27 | Github 28 | https://github.com/timboudreau/acteur/issues 29 | 30 | 31 | 32 | 33 | MIT 34 | https://opensource.org/licenses/MIT 35 | repo 36 | 37 | 38 | 39 | 40 | Mastfrog Technologies 41 | https://mastfrog.com 42 | 43 | Netty Websocket Pubsub 44 | 45 | 46 | 47 | ${project.groupId} 48 | giulius 49 | 50 | 51 | ${project.groupId} 52 | marshaller-registry 53 | 54 | 55 | io.netty 56 | netty-codec-http 57 | 58 | 59 | junit 60 | junit 61 | test 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /netty-websocket-pubsub/src/main/java/com/mastfrog/acteur/pubsub/ChannelId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.acteur.pubsub; 25 | 26 | /** 27 | * An ad-hoc name for a pub-sub channel, which multiple netty channels 28 | * may be subscribed to. The channels subscribed must have a handler that 29 | * knows what to do with a WebSocketFrame. 30 | * 31 | * @author Tim Boudreau 32 | */ 33 | public final class ChannelId { 34 | 35 | private final String name; 36 | 37 | public ChannelId(String name) { 38 | this.name = name; 39 | } 40 | 41 | public boolean equals(Object o) { 42 | return o instanceof ChannelId && ((ChannelId) o).name.equals(name); 43 | } 44 | 45 | public int hashCode() { 46 | return name.hashCode() * 71; 47 | } 48 | 49 | public String toString() { 50 | return name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /simple-webserver/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | run 5 | 6 | jar 7 | 8 | 9 | process-classes 10 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 11 | 12 | 13 | -classpath %classpath com.mastfrog.simple.webserver.Server 14 | java 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /simple-webserver/serve: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 3 | java -jar $DIR/server.jar $1 $2 4 | 5 | -------------------------------------------------------------------------------- /url/description.properties: -------------------------------------------------------------------------------- 1 | name=URL API 2 | description=URL classes which are collection-safe, perform some normalization \ 3 | and are composed of well-typed component objects. 4 | -------------------------------------------------------------------------------- /url/src/main/java/com/mastfrog/url/ParametersDelimiter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.url; 25 | 26 | /** 27 | * A query delimiter in a URL. 28 | * 29 | * @author Tim Boudreau 30 | */ 31 | public enum ParametersDelimiter { 32 | SEMICOLON(';'), 33 | AMPERSAND('&'), 34 | ; 35 | private char delimiter; 36 | ParametersDelimiter(char delimiter) { 37 | this.delimiter = delimiter; 38 | } 39 | 40 | public char charValue() { 41 | return delimiter; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /url/src/main/java/com/mastfrog/url/URLComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2013 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.url; 25 | 26 | import java.io.Serializable; 27 | 28 | /** 29 | * One element of a URL, such as a Host, Port, Password, Path, PathElement, 30 | * Parameters or ParametersElement. 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public interface URLComponent extends Serializable { 35 | /** 36 | * Determine if this component is in compliance with the RFCs governing 37 | * URLs and DNS. 38 | * @return True if this component is valid. 39 | */ 40 | public boolean isValid(); 41 | /** 42 | * Get a human-readable, localized name for this part of the URL. 43 | * Useful if an error message needs to be shown. 44 | * @return The component name 45 | */ 46 | public String getComponentName(); 47 | /** 48 | * Append this component to a StringBuilder. 49 | * @param sb A StringBuilder 50 | */ 51 | public void appendTo (StringBuilder sb); 52 | } 53 | -------------------------------------------------------------------------------- /url/src/main/java/com/mastfrog/url/package.html: -------------------------------------------------------------------------------- 1 | 2 |

URL API

3 | 4 | This is a small library for parsing URLs, which provides an actual object model 5 | of the elements of URLs and their component objects. 6 | 7 | Unlike java.net.url, URLs and all of their components can be invalid and provide human-friendly 8 | localized messages as to what's wrong with them - no MalformedURLExceptions and nothing 9 | that will unexpectedly make a network connection if you use it as a HashMap key. 10 | 11 | URLs also do minimal self-normalizing when parsed (handling .. in paths, replacing 12 | "localhost" with 127.0.0.1 or ::1, lower-casing host labels - very minimal, but sufficient to de-duplicate equivalent 13 | URLs, and all standards-compliant. A lot of work went into reading RFCs to get things right here, and it has 14 | an exhaustive test-suite. URLs can be parsed or built with builders. 15 | 16 | java.net.URL was developed for HotJava in the 90s, and was probably 17 | great for that use case - and that use case only. This is a library for doing 18 | modern Java coding with URLs. 19 | 20 |

Usage

21 | 22 | In the simplest form: 23 | 24 |
25 |     URL url = URL.parse("http://joe:password@foo.com:8080/foo/bar?baz=quux#hey");
26 |     assert "hey".equals(url.getAnchor());
27 |     assert "joe".equals(url.getUsername();
28 |     assert "password".equals(url.getPassword();
29 |     assert "bar".equals(url.getPath().getLastElement().toString());
30 |     assert Host.parse("foo.com").equals(url.getHost());
31 |     assert 8080 == url.getPort().intValue();
32 |     assert url.isValid();
33 | 
34 | 35 | 36 | -------------------------------------------------------------------------------- /url/src/main/resources/com/mastfrog/url/Bundle.properties: -------------------------------------------------------------------------------- 1 | port=Port 2 | host=Host 3 | label=Address Label 4 | parameters=Parameters 5 | parameters_element=Parameter Pair 6 | path=Path 7 | path_element=Path Element 8 | protocol=Protocol 9 | url=URL 10 | user_name=User Name 11 | password=Password 12 | anchor=Anchor 13 | BAD_URL_COMPONENT={0} is invalid 14 | RELATIVE_PATH_HAS_TO_MANY_BACKWARD_STEPS=Invalid relative path {0} 15 | PATH_CONTAINS_ILLEGAL_CHARACTERS=Path contains characters which cannot be represented in a URL: {0} 16 | PORT_IS_NOT_A_NUMBER=Port is not a number: {0} 17 | PORT_OUT_OF_RANGE=Port is not between 1 and 65535: {0} 18 | TopLevelDomainMissing=Top level domain missing from host 19 | DomainMissing=Domain missing from host 20 | HostTooLong=Host part is > 255 characters 21 | WrongNumberOfElementsForIpAddress=An IP address must have 4 or 6 label elements 22 | HostMixesNumericAndNonNumeric=A host name may not mix numbers and names 23 | -------------------------------------------------------------------------------- /url/src/test/java/com/mastfrog/url/MoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2019 Mastfrog Technologies. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.url; 25 | 26 | import static org.junit.Assert.assertNotNull; 27 | import static org.junit.Assert.assertNull; 28 | import static org.junit.Assert.assertTrue; 29 | import org.junit.Test; 30 | 31 | /** 32 | * 33 | * @author Tim Boudreau 34 | */ 35 | public class MoreTest { 36 | 37 | private static final String U = "http://foo.cloud.engineering.mycompany.com"; 38 | 39 | @Test 40 | public void testManyLabels() { 41 | URL url = URL.parse(U); 42 | assertNotNull(url); 43 | assertNull(url.getProblems()); 44 | assertTrue(url.isValid()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /url/src/test/java/com/mastfrog/url/ParsedParametersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Tim Boudreau. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package com.mastfrog.url; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.junit.Assert.assertNotNull; 28 | import org.junit.Test; 29 | 30 | /** 31 | * 32 | * @author Tim Boudreau 33 | */ 34 | public class ParsedParametersTest { 35 | 36 | @Test 37 | public void testSomeMethod() { 38 | URL u = URL.parse("http://media.localhost:5722/image?utk=upew7gMAAACcjwCr3jsDyIOxM9DWID1zanIcQ2iAAgAAACdZ"); 39 | ParsedParameters pp = u.getParameters().toParsedParameters(); 40 | assertEquals(pp.size(), 1); 41 | ParametersElement el = pp.iterator().next(); 42 | assertNotNull(el); 43 | assertEquals("utk", el.getKey()); 44 | assertEquals("upew7gMAAACcjwCr3jsDyIOxM9DWID1zanIcQ2iAAgAAACdZ", el.getValue()); 45 | } 46 | } 47 | --------------------------------------------------------------------------------