├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── Dockerfile
├── Dockerfile.template
├── LICENSE
├── README-previous.md
├── README.md
├── docs
├── CNAME
├── howtos
│ ├── GDPR.md
│ ├── cricket.jmx
│ ├── environment-variables.txt
│ ├── eventHandling.md
│ ├── https.txt
│ ├── redirect.txt
│ ├── server-contexts.txt
│ └── service-name-and-uid.txt
├── index.html
├── local-css
│ └── main.css
└── local-resources
│ ├── become_a_patron_button@2x.png
│ ├── cricket-head1.svg
│ ├── cricket-logo.svg
│ ├── experiot-logo.svg
│ ├── favicon.ico
│ ├── readme.txt
│ └── signocom.png
├── examples
└── todo
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── mytodo
│ │ ├── Task.java
│ │ ├── TodoEventRouter.java
│ │ ├── TodoService.java
│ │ ├── event
│ │ └── task
│ │ │ ├── CreateTaskEvent.java
│ │ │ ├── DeleteTaskEvent.java
│ │ │ ├── ReadTaskEvent.java
│ │ │ └── UpdateTaskEvent.java
│ │ ├── in
│ │ └── TodoHttpApi.java
│ │ └── out
│ │ ├── TodoDao.java
│ │ └── TodoDaoIface.java
│ └── resources
│ └── settings.json
├── pom.xml
├── src
├── assembly
│ ├── distribution.xml
│ └── filter.properties
├── main
│ ├── java
│ │ └── org
│ │ │ └── cricketmsf
│ │ │ ├── Adapter.java
│ │ │ ├── ArgumentParser.java
│ │ │ ├── AuthorizationFilter.java
│ │ │ ├── AuthorizationFilterResult.java
│ │ │ ├── CricketHttpd.java
│ │ │ ├── CricketThreadFactory.java
│ │ │ ├── FileParameter.java
│ │ │ ├── HttpdIface.java
│ │ │ ├── Kernel.java
│ │ │ ├── MaintenanceFilter.java
│ │ │ ├── ParameterFilter.java
│ │ │ ├── RequestHeader.java
│ │ │ ├── RequestObject.java
│ │ │ ├── RequestParameter.java
│ │ │ ├── Runner.java
│ │ │ ├── WebsocketServer.java
│ │ │ ├── annotation
│ │ │ ├── EventHook.java
│ │ │ └── WebsocketAdapterHook.java
│ │ │ ├── api
│ │ │ ├── HttpResult.java
│ │ │ ├── ResponseCode.java
│ │ │ ├── Result.java
│ │ │ ├── ResultIface.java
│ │ │ └── StandardResult.java
│ │ │ ├── config
│ │ │ ├── AdapterConfiguration.java
│ │ │ ├── ConfigSet.java
│ │ │ ├── Configuration.java
│ │ │ └── HttpHeader.java
│ │ │ ├── event
│ │ │ ├── Delay.java
│ │ │ ├── Event.java
│ │ │ ├── EventDto.java
│ │ │ ├── EventMaster.java
│ │ │ ├── EventUtils.java
│ │ │ ├── GreeterEvent.java
│ │ │ ├── HttpEvent.java
│ │ │ ├── ProcedureCall.java
│ │ │ ├── Procedures.java
│ │ │ ├── ProceduresIface.java
│ │ │ ├── ShutdownRequested.java
│ │ │ └── StatusRequested.java
│ │ │ ├── exception
│ │ │ ├── AdapterException.java
│ │ │ ├── DispatcherException.java
│ │ │ ├── EventException.java
│ │ │ ├── InitException.java
│ │ │ ├── QueueException.java
│ │ │ └── WebsocketException.java
│ │ │ ├── in
│ │ │ ├── InboundAdapter.java
│ │ │ ├── InboundAdapterIface.java
│ │ │ ├── ResultNotUsed.java
│ │ │ ├── cli
│ │ │ │ ├── Cli.java
│ │ │ │ ├── CliEvent.java
│ │ │ │ └── CliIface.java
│ │ │ ├── event
│ │ │ │ ├── EventHandler.java
│ │ │ │ ├── EventListenerIface.java
│ │ │ │ └── SimpleQueueSubscriber.java
│ │ │ ├── file
│ │ │ │ ├── FileEvent.java
│ │ │ │ ├── FileReader.java
│ │ │ │ ├── FolderObserver.java
│ │ │ │ ├── NotDirectoryFilter.java
│ │ │ │ └── WatchdogIface.java
│ │ │ ├── http
│ │ │ │ ├── AdapterError.java
│ │ │ │ ├── CorsProcessor.java
│ │ │ │ ├── CsvFormatter.java
│ │ │ │ ├── FileResult.java
│ │ │ │ ├── GreeterAdapter.java
│ │ │ │ ├── HtmlGenAdapter.java
│ │ │ │ ├── HtmlGenAdapterIface.java
│ │ │ │ ├── HttpAdapterIface.java
│ │ │ │ ├── HttpPortedAdapter.java
│ │ │ │ ├── HttpRequestWorker.java
│ │ │ │ ├── JsonFormatter.java
│ │ │ │ ├── ParameterMapResult.java
│ │ │ │ ├── StatusAdapter.java
│ │ │ │ ├── Tester.java
│ │ │ │ ├── TxtFormatter.java
│ │ │ │ └── XmlFormatter.java
│ │ │ ├── messaging
│ │ │ │ └── MessageSubscriber.java
│ │ │ ├── mqtt
│ │ │ │ ├── Callback.java
│ │ │ │ ├── EventSubscriberCallback.java
│ │ │ │ ├── MqttEventSubscriber.java
│ │ │ │ ├── MqttSubscriber.java
│ │ │ │ └── MqttSubscriberCallback.java
│ │ │ ├── openapi
│ │ │ │ ├── BodyContent.java
│ │ │ │ ├── Content.java
│ │ │ │ ├── Element.java
│ │ │ │ ├── Info.java
│ │ │ │ ├── OpenApi.java
│ │ │ │ ├── OpenApiIface.java
│ │ │ │ ├── Operation.java
│ │ │ │ ├── Parameter.java
│ │ │ │ ├── ParameterLocation.java
│ │ │ │ ├── PathItem.java
│ │ │ │ ├── RequestBody.java
│ │ │ │ ├── Response.java
│ │ │ │ ├── Schema.java
│ │ │ │ ├── SchemaFormat.java
│ │ │ │ ├── SchemaProperty.java
│ │ │ │ ├── SchemaType.java
│ │ │ │ └── Server.java
│ │ │ ├── quartz
│ │ │ │ ├── QuartzJob.java
│ │ │ │ ├── QuartzScheduler.java
│ │ │ │ └── QuartzSchedulerIface.java
│ │ │ ├── scheduler
│ │ │ │ ├── Scheduler.java
│ │ │ │ └── SchedulerIface.java
│ │ │ └── websocket
│ │ │ │ ├── ClientList.java
│ │ │ │ └── WebsocketAdapter.java
│ │ │ ├── microsite
│ │ │ ├── SiteAdministrationModule.java
│ │ │ ├── auth
│ │ │ │ ├── AuthorizationFilter.java
│ │ │ │ ├── AuthorizationFilterResult.java
│ │ │ │ └── Exchange.java
│ │ │ ├── event
│ │ │ │ ├── auth
│ │ │ │ │ └── AuthEvent.java
│ │ │ │ ├── cms
│ │ │ │ │ └── CmsEvent.java
│ │ │ │ └── user
│ │ │ │ │ └── UserEvent.java
│ │ │ ├── in
│ │ │ │ ├── auth
│ │ │ │ │ └── AuthApi.java
│ │ │ │ ├── cms
│ │ │ │ │ ├── ContentManagerApiHttp.java
│ │ │ │ │ └── ContentServiceApiHttp.java
│ │ │ │ ├── siteadmin
│ │ │ │ │ └── SiteAdminApi.java
│ │ │ │ └── user
│ │ │ │ │ └── UserApi.java
│ │ │ └── out
│ │ │ │ ├── auth
│ │ │ │ ├── AuthCheckAdapter.java
│ │ │ │ ├── AuthEmbededAdapter.java
│ │ │ │ ├── AuthException.java
│ │ │ │ ├── Token.java
│ │ │ │ └── UserProxy.java
│ │ │ │ ├── cms
│ │ │ │ ├── CmsEmbededAdapter.java
│ │ │ │ ├── CmsException.java
│ │ │ │ ├── CmsIface.java
│ │ │ │ ├── Comment.java
│ │ │ │ ├── ContentRequestProcessor.java
│ │ │ │ ├── DeeplTranslator.java
│ │ │ │ ├── DefaultRuleEngine.java
│ │ │ │ ├── Document.java
│ │ │ │ ├── DocumentPathAndTagComparator.java
│ │ │ │ ├── RuleEngineIface.java
│ │ │ │ └── TranslatorIface.java
│ │ │ │ ├── db
│ │ │ │ ├── H2AuthDB.java
│ │ │ │ ├── H2CmsDB.java
│ │ │ │ ├── H2RemoteAuthDB.java
│ │ │ │ ├── H2RemoteCmsDB.java
│ │ │ │ ├── H2RemoteUserDB.java
│ │ │ │ └── H2UserDB.java
│ │ │ │ ├── notification
│ │ │ │ ├── EmailSenderIface.java
│ │ │ │ ├── SmtpSender.java
│ │ │ │ └── SmtpSender2.java
│ │ │ │ ├── siteadmin
│ │ │ │ ├── SiteAdministrationIface.java
│ │ │ │ └── SiteAdministrationModule.java
│ │ │ │ └── user
│ │ │ │ ├── HashMaker.java
│ │ │ │ ├── User.java
│ │ │ │ ├── UserAdapterIface.java
│ │ │ │ ├── UserEmbededAdapter.java
│ │ │ │ └── UserException.java
│ │ │ ├── out
│ │ │ ├── OutboundAdapter.java
│ │ │ ├── OutboundAdapterIface.java
│ │ │ ├── archiver
│ │ │ │ └── ZipArchiver.java
│ │ │ ├── auth
│ │ │ │ └── AuthAdapterIface.java
│ │ │ ├── autostart
│ │ │ │ ├── Autostart.java
│ │ │ │ └── AutostartIface.java
│ │ │ ├── db
│ │ │ │ ├── ComparatorIface.java
│ │ │ │ ├── DBException.java
│ │ │ │ ├── H2EmbededDB.java
│ │ │ │ ├── H2RemoteDB.java
│ │ │ │ ├── KeyValueCacheAdapterIface.java
│ │ │ │ ├── KeyValueDB.java
│ │ │ │ ├── KeyValueDBException.java
│ │ │ │ ├── KeyValueDBIface.java
│ │ │ │ ├── KeyValueStore.java
│ │ │ │ ├── KeyValueTable.java
│ │ │ │ ├── LimitedMap.java
│ │ │ │ ├── PostgreSqlDB.java
│ │ │ │ └── SqlDBIface.java
│ │ │ ├── dispatcher
│ │ │ │ ├── DispatcherIface.java
│ │ │ │ ├── MessageDispatcher.java
│ │ │ │ ├── MqttDispatcher.java
│ │ │ │ └── SimpleQueueClient.java
│ │ │ ├── event
│ │ │ │ └── EventDispatcherIface.java
│ │ │ ├── file
│ │ │ │ ├── CommandRunner.java
│ │ │ │ ├── CommandRunnerIface.java
│ │ │ │ ├── FileObject.java
│ │ │ │ ├── FileReaderAdapter.java
│ │ │ │ └── FileReaderAdapterIface.java
│ │ │ ├── log
│ │ │ │ ├── FileLogger.java
│ │ │ │ └── LoggerAdapterIface.java
│ │ │ ├── messaging
│ │ │ │ ├── MessageBroker.java
│ │ │ │ └── MessageBrokerClient.java
│ │ │ ├── mqtt
│ │ │ │ ├── MqttPublisher.java
│ │ │ │ ├── MqttPublisherAdapter.java
│ │ │ │ ├── MqttPublisherException.java
│ │ │ │ └── MqttPublisherIface.java
│ │ │ ├── queue
│ │ │ │ └── SimpleQueue.java
│ │ │ └── websocket
│ │ │ │ ├── WebsocketClient.java
│ │ │ │ └── WebsocketClientIface.java
│ │ │ ├── queue
│ │ │ ├── QueueCallbackIface.java
│ │ │ ├── QueueClientIface.java
│ │ │ ├── QueueIface.java
│ │ │ └── SubscriberIface.java
│ │ │ ├── services
│ │ │ ├── BasicEventRouter.java
│ │ │ ├── BasicService.java
│ │ │ ├── Microsite.java
│ │ │ ├── MicrositeEventRouter.java
│ │ │ └── MinimalService.java
│ │ │ └── util
│ │ │ ├── FileReader.java
│ │ │ ├── JsonReader.java
│ │ │ └── Stopwatch.java
│ └── resources
│ │ ├── BasicService-help.txt
│ │ ├── cricket.json
│ │ └── logback.xml
└── other
│ ├── build.xml
│ ├── index.html
│ ├── run.sh
│ └── run_8.sh
└── test
└── org
└── cricketmsf
└── test
└── microsite
├── CmsTests.java
├── GdprStandardUserTest.java
└── SystemTests.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | #
2 | # https://help.github.com/articles/dealing-with-line-endings/
3 | #
4 | # These are explicitly windows files and should use crlf
5 | *.bat text eol=crlf
6 |
7 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: gskorupa
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: https://paypal.me/gskorupa
13 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Cricket MSF microsite image
2 | FROM openjdk:10-jre-slim
3 |
4 | RUN mkdir /cricket
5 | RUN mkdir /cricket/data
6 | RUN mkdir /cricket/files
7 | RUN mkdir /cricket/backup
8 | COPY dist/cricket-1.4.4.jar /cricket
9 | COPY dist/config/cricket.json /cricket/config/
10 | COPY dist/www /cricket/www
11 | COPY dist/data/cricket_publickeystore.jks /cricket/data
12 | VOLUME /cricket
13 | volume /cricket/www
14 | WORKDIR /cricket
15 |
16 | CMD ["java", "--illegal-access=deny", "--add-modules", "java.xml.bind", "--add-modules", "java.activation", "-jar", "cricket-1.4.4.jar", "-r", "-c", "/cricket/config/cricket.json", "-s", "Microsite"]
--------------------------------------------------------------------------------
/Dockerfile.template:
--------------------------------------------------------------------------------
1 | # Cricket MSF microsite image
2 | FROM openjdk:10-jre-slim
3 |
4 | RUN mkdir /cricket
5 | RUN mkdir /cricket/data
6 | RUN mkdir /cricket/files
7 | RUN mkdir /cricket/backup
8 | COPY dist/cricket-{{version}}.jar /cricket
9 | COPY dist/config/cricket.json /cricket/config/
10 | COPY dist/www /cricket/www
11 | COPY dist/data/cricket_publickeystore.jks /cricket/data
12 | VOLUME /cricket
13 | volume /cricket/www
14 | WORKDIR /cricket
15 |
16 | CMD ["java", "--illegal-access=deny", "--add-modules", "java.xml.bind", "--add-modules", "java.activation", "-jar", "cricket-{{version}}.jar", "-r", "-c", "/cricket/config/cricket.json", "-s", "Microsite"]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Cricket Microservices Framework for Java.
2 |
3 |
4 | ## Building microservices
5 |
6 | Add dependency to your pom.xml
7 |
8 | ```xml
9 |
10 | org.cricketmsf
11 | cricket
12 | 2.0.0-rc36
13 |
14 | ```
15 |
16 | ## Headless CMS
17 |
18 | > NEED TO BE UPDATED
19 |
20 | Downlod `criket.jar` from Maven Central or build yourself (see below).
21 | ```shell
22 | ```
23 | Download admin web application
24 | ```shell
25 | ```
26 |
27 | ## Examples
28 |
29 | > NEED TO BE UPDATED
30 |
31 | ## Development
32 |
33 | Clone repository
34 | ```shell
35 | $ git clone https://github.com/gskorupa/cricket.git
36 | ```
37 |
38 | Build
39 | ```shell
40 | $ mvn package
41 | ```
42 |
43 | ## More information
44 |
45 | Go to https://cricketmsf.org to find more information about the platform.
46 |
47 | In case of problems or questions please create issue in the project Github repository.
48 |
49 |
--------------------------------------------------------------------------------
/docs/CNAME:
--------------------------------------------------------------------------------
1 | cricketmsf.org
--------------------------------------------------------------------------------
/docs/howtos/GDPR.md:
--------------------------------------------------------------------------------
1 | # GDPR compliance
2 |
3 | ## Encryption
4 |
5 | User database can be encrypted
6 |
7 | HTPPS
8 |
9 | ## Monitoring and logging
10 |
11 | Logging events related to user database access
12 |
13 | Info about requested account removal are send to admin email
14 |
15 | Anomymized log files
16 |
17 | ## Access control
18 |
19 | Restricted access to the data using both REST API and web GUI
20 |
21 |
22 | ## Data privacy
23 |
24 | ## Security by design
25 |
26 | ## Procedures
27 |
28 | TODO
29 |
30 | ### Complete removal of user's data
31 |
32 | From operational DB and backups
33 |
34 | ### Break into the system
35 |
36 | When potential data leak is detected ...
--------------------------------------------------------------------------------
/docs/howtos/environment-variables.txt:
--------------------------------------------------------------------------------
1 | Cricket service behavior can be tuned by two OS environment variables:
2 |
3 | 1. CMF_PARAM
4 | Acts same as -f command line option (overwrites -f option)
5 |
6 | 2. CRICKET_NAME
7 | Can be used to set the service name. Defaults to "CricketService"
8 |
9 | The name of this enironment variable can be configured in cricket.jason.
10 | Example:
11 | ...
12 | "@type": "org.cricketmsf.config.Configuration",
13 | "id": "echo",
14 | "service": "org.cricketmsf.services.BasicService",
15 | "properties": {
16 | "host": "0.0.0.0",
17 | "port": "8080",
18 | "threads": "0",
19 | "filter": "org.cricketmsf.SecurityFilter",
20 | "cors": "Access-Control-Allow-Origin:*",
21 | "time-zone": "GMT",
22 | "SRVC_NAME_ENV_VARIABLE": "CRICKET_NAME"
23 | }
24 | ...
--------------------------------------------------------------------------------
/docs/howtos/eventHandling.md:
--------------------------------------------------------------------------------
1 | # Event handling
2 |
3 | ## In handling method we can
4 |
5 | * process the event
6 | * suspend the event by setting new timepoint and run Kernel.dispatch()
7 | * change the event type (and optionally other parameters) and run Kernel.dispatch()
8 |
9 | **do not run Kernel.dispatch() without modifying the event -> endless loop!**
--------------------------------------------------------------------------------
/docs/howtos/https.txt:
--------------------------------------------------------------------------------
1 | How to run HTTPS server?
2 |
3 | 1. Configure SSL by setting "port" and "ssl" server properties in cricket.json as follows:
4 |
5 | "properties": {
6 | "host": "0.0.0.0",
7 | "port": "443",
8 | "ssl": "true",
9 | "keystore": "./data/cricket_publickeystore.jks",
10 | "keystore-password": "cricket15$#17",
11 | "threads": "0",
12 | "filter": "org.cricketmsf.SecurityFilter",
13 | "cors": "Access-Control-Allow-Origin:*",
14 | "time-zone": "GMT",
15 | "SRVC_NAME_ENV_VARIABLE": "CRICKET_NAME"
16 | }
17 |
18 | When you set "ssl":"false" the "keystore" and "keystore-password" will be ignored.
19 |
20 | The default keystore with the self signed certificate for "localhost" is generated
21 | during building Cricket distribution with
22 | "ant dist" command.
--------------------------------------------------------------------------------
/docs/howtos/redirect.txt:
--------------------------------------------------------------------------------
1 | How to send redirect from handler method?
2 |
3 |
4 | response.setCode(302);
5 | response.setMessage(newURL); //it will cerate "Location: newURL" response header
6 |
7 |
8 |
--------------------------------------------------------------------------------
/docs/howtos/server-contexts.txt:
--------------------------------------------------------------------------------
1 | Warning!
2 |
3 | When you have:
4 |
5 | a) HttpAdapter-A on context "/"
6 | b) HttpAdapter-B on context "/login"
7 |
8 | then
9 |
10 | request "/login.html" is handled by HttpAdapter-B instead of HttpAdapter-A.
11 |
12 | It looks like error (or undocumented feature) of sun.net.httpserver.HttpServer
13 |
14 |
--------------------------------------------------------------------------------
/docs/howtos/service-name-and-uid.txt:
--------------------------------------------------------------------------------
1 | 1. Service name:
2 |
3 | a) can be defined in the operting system environment variable
4 | b) environment variable name can be configured in cricket.json
5 | c) if nor configured, Cricket will look at CRICKET_SERVICE environment variable
6 | d) if environment variable is not set then service name will be set to "CricketService"
7 |
8 | Example a):
9 |
10 | export CRICKET_NAME="MyService1"; java -jar dist/cricketms-1.1.1.jar -r
11 | ...
12 | INFO:2017-03-11 20:32:08 +0000:
13 | INFO:2017-03-11 20:32:08 +0000: __| \ | __| Cricket
14 | INFO:2017-03-11 20:32:08 +0000: ( |\/ | _| Microservices Framework
15 | INFO:2017-03-11 20:32:08 +0000: \___|_| _|_| version 1.2.7
16 | INFO:2017-03-11 20:32:08 +0000:
17 | INFO:2017-03-11 20:32:08 +0000: # Service BasicService is running
18 | INFO:2017-03-11 20:32:08 +0000: # UUID: 5f3aee6c-7417-4231-8653-45b75af56c47
19 | INFO:2017-03-11 20:32:08 +0000: # NAME: asdfg
20 | INFO:2017-03-11 20:32:08 +0000: #
21 | INFO:2017-03-11 20:32:08 +0000: # HTTP listening on port 8080
22 | ...
23 |
24 | 2. UUID
25 | UUID is a random identifier generated on service start.
26 |
27 | 3. ID
28 | The service ID is configured in cricket.json
29 |
30 |
31 | 4. ID vs. UUID vs. Service name
32 |
33 | Every service started using the same configuration (cricket.json) have the same ID.
34 |
35 | The service will got different UUID on every restart.
36 |
37 | The service will got the same Service name regardles of the number of restarts
38 |
--------------------------------------------------------------------------------
/docs/local-css/main.css:
--------------------------------------------------------------------------------
1 | body{
2 | font-family: 'Lato', sans-serif;
3 | font-weight: 400;
4 | color: darkslategray;
5 | }
6 | h1 {
7 | font-family: 'Lato', sans-serif;
8 | font-weight: 900;
9 | }
10 | h2 {
11 | margin-bottom: 1rem;
12 | }
13 | h6 {
14 | margin-top: 2rem;
15 | margin-bottom: 1rem;
16 | }
17 | .row-centered {
18 | text-align:center;
19 | }
20 | .col-centered {
21 | display:inline-block;
22 | float:none;
23 | /* reset the text-align */
24 | text-align:left;
25 | /* inline-block space fix */
26 | margin-right:-4px;
27 | }
28 | .intro {
29 | color: darkslategray;
30 | padding-top: 20px;
31 | padding-bottom: 10px;
32 | }
33 | .feature{
34 | color: darkslategray;
35 | padding-top: 10px;
36 | padding-bottom: 10px;
37 | }
38 | .footer{
39 | color: darkslategray;
40 | margin-top: 2rem;
41 | border-top-style: solid;
42 | border-top-color: darkslategray;
43 | border-top-width: 1px;
44 | }
45 | .version{
46 | margin-top: 0px;
47 | margin-bottom: 0px;
48 | color: darkslategray;
49 | }
50 | p {
51 | margin-top: 10px;
52 | margin-bottom: 10px;
53 | text-align: left;
54 | }
55 |
56 | pre {
57 | background: #eeeeee;
58 | padding: 10px 10px 10px 10px;
59 | }
60 |
--------------------------------------------------------------------------------
/docs/local-resources/become_a_patron_button@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gskorupa/cricket/441d656fb03da4f2d109a0fbeaa83abce75c23ee/docs/local-resources/become_a_patron_button@2x.png
--------------------------------------------------------------------------------
/docs/local-resources/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gskorupa/cricket/441d656fb03da4f2d109a0fbeaa83abce75c23ee/docs/local-resources/favicon.ico
--------------------------------------------------------------------------------
/docs/local-resources/readme.txt:
--------------------------------------------------------------------------------
1 | resource files
2 |
--------------------------------------------------------------------------------
/docs/local-resources/signocom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gskorupa/cricket/441d656fb03da4f2d109a0fbeaa83abce75c23ee/docs/local-resources/signocom.png
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/Task.java:
--------------------------------------------------------------------------------
1 | package mytodo;
2 |
3 | public class Task {
4 | public Long id;
5 | public String title;
6 | }
7 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/TodoEventRouter.java:
--------------------------------------------------------------------------------
1 | package mytodo;
2 |
3 | import mytodo.event.task.CreateTaskEvent;
4 | import mytodo.event.task.DeleteTaskEvent;
5 | import mytodo.event.task.ReadTaskEvent;
6 | import mytodo.event.task.UpdateTaskEvent;
7 | import org.cricketmsf.annotation.EventHook;
8 | import org.cricketmsf.api.HttpResult;
9 | import org.cricketmsf.api.ResponseCode;
10 | import org.cricketmsf.api.Result;
11 | import org.cricketmsf.api.ResultIface;
12 | import org.slf4j.LoggerFactory;
13 |
14 | /**
15 | *
16 | * @author greg
17 | */
18 | public class TodoEventRouter {
19 |
20 | private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TodoEventRouter.class);
21 |
22 | private final TodoService service;
23 |
24 | public TodoEventRouter(TodoService service) {
25 | this.service = service;
26 | }
27 |
28 | @EventHook(className = "mytodo.event.task.CreateTaskEvent")
29 | public ResultIface createTodo(CreateTaskEvent event) {
30 | logger.debug(event.toString());
31 | Result result = new Result();
32 | boolean ok = service.todoDao.createTask(event);
33 | if (ok) {
34 | result.setData("created");
35 | } else {
36 | result.setCode(ResponseCode.BAD_REQUEST);
37 | result.setData("error");
38 | }
39 | return result;
40 | }
41 |
42 | @EventHook(className = "mytodo.event.task.UpdateTaskEvent")
43 | public ResultIface updateTodo(UpdateTaskEvent event) {
44 | logger.debug(event.toString());
45 | Result result = new Result();
46 | boolean ok = service.todoDao.updateTask(event);
47 | if (ok) {
48 | result.setData("updated");
49 | } else {
50 | result.setCode(ResponseCode.BAD_REQUEST);
51 | result.setData("error");
52 | }
53 | return result;
54 | }
55 |
56 | @EventHook(className = "mytodo.event.task.ReadTaskEvent")
57 | public ResultIface readTodo(ReadTaskEvent event) {
58 | logger.debug(event.toString());
59 | HttpResult result = new HttpResult();
60 | Long id = event.getData();
61 | Task task=service.todoDao.readTask(id);
62 | if(null!=task){
63 | result.setData(task);
64 | }else{
65 | result.setCode(ResponseCode.NOT_FOUND);
66 | }
67 | return result;
68 | }
69 |
70 | @EventHook(className = "mytodo.event.task.DeleteTaskEvent")
71 | public ResultIface deleteTodo(DeleteTaskEvent event) {
72 | logger.debug(event.toString());
73 | Result result = new Result();
74 | Long id = (Long) event.getData();
75 | boolean ok = service.todoDao.deleteTask(id);
76 | if (ok) {
77 | result.setData("deleted");
78 | } else {
79 | result.setCode(ResponseCode.BAD_REQUEST);
80 | result.setData("error");
81 | }
82 | return result;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/TodoService.java:
--------------------------------------------------------------------------------
1 | package mytodo;
2 |
3 | import mytodo.out.TodoDaoIface;
4 | import org.cricketmsf.services.MinimalService;
5 | import org.slf4j.LoggerFactory;
6 |
7 | public class TodoService extends MinimalService {
8 | private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TodoService.class);
9 |
10 | public TodoDaoIface todoDao=null;
11 |
12 | public TodoService() {
13 | super();
14 | setEventRouter(new TodoEventRouter(this));
15 | }
16 |
17 | @Override
18 | public void getAdapters() {
19 | super.getAdapters();
20 | // your code
21 | todoDao = (TodoDaoIface) getRegistered("TodoDao");
22 | }
23 |
24 | @Override
25 | public void runInitTasks() {
26 | //try {
27 | super.runInitTasks();
28 | //} catch (InitException ex) {
29 |
30 | //}
31 | // your code here
32 | setInitialized(true);
33 | }
34 |
35 | @Override
36 | public void shutdown() {
37 | // your code here
38 | super.shutdown();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/event/task/CreateTaskEvent.java:
--------------------------------------------------------------------------------
1 | package mytodo.event.task;
2 |
3 | import java.util.Date;
4 | import java.util.HashMap;
5 | import org.cricketmsf.event.Event;
6 |
7 | /**
8 | *
9 | * @author greg
10 | */
11 | public class CreateTaskEvent extends Event {
12 |
13 | private HashMap data;
14 |
15 | public CreateTaskEvent(){
16 | super();
17 | data=new HashMap<>();
18 | }
19 |
20 | public void setData(String title, Boolean done, Date deadline){
21 | data.put("title", title);
22 | data.put("done",done);
23 | data.put("deadline",deadline);
24 | }
25 |
26 | public HashMap getData(){
27 | return data;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/event/task/DeleteTaskEvent.java:
--------------------------------------------------------------------------------
1 | package mytodo.event.task;
2 |
3 | import java.util.Date;
4 | import java.util.HashMap;
5 | import org.cricketmsf.event.Event;
6 |
7 | /**
8 | *
9 | * @author greg
10 | */
11 | public class DeleteTaskEvent extends Event {
12 |
13 | private Long data;
14 |
15 | public DeleteTaskEvent(){
16 | super();
17 | data=null;
18 | }
19 |
20 | public void setData(Long id){
21 | data=id;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/event/task/ReadTaskEvent.java:
--------------------------------------------------------------------------------
1 | package mytodo.event.task;
2 |
3 | import org.cricketmsf.event.Event;
4 |
5 | public class ReadTaskEvent extends Event {
6 |
7 | private Long data;
8 |
9 | public ReadTaskEvent(){
10 | super();
11 | data=null;
12 | }
13 |
14 | public void setData(Long id){
15 | data=id;
16 | }
17 |
18 | @Override
19 | public Long getData(){
20 | return data;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/event/task/UpdateTaskEvent.java:
--------------------------------------------------------------------------------
1 | package mytodo.event.task;
2 |
3 | import java.util.Date;
4 | import java.util.HashMap;
5 | import org.cricketmsf.event.Event;
6 |
7 | /**
8 | *
9 | * @author greg
10 | */
11 | public class UpdateTaskEvent extends Event {
12 |
13 | private HashMap data;
14 |
15 | public UpdateTaskEvent(){
16 | super();
17 | data=new HashMap<>();
18 | }
19 |
20 | public void setData(Long id, String title, Boolean done, Date deadline){
21 | data.put("id",id);
22 | data.put("title", title);
23 | data.put("done",done);
24 | data.put("deadline",deadline);
25 | }
26 |
27 | public HashMap getData(){
28 | return data;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/in/TodoHttpApi.java:
--------------------------------------------------------------------------------
1 | package mytodo.in;
2 |
3 | import java.util.HashMap;
4 | import mytodo.event.task.CreateTaskEvent;
5 | import mytodo.event.task.ReadTaskEvent;
6 | import org.cricketmsf.Adapter;
7 | import org.cricketmsf.RequestObject;
8 | import org.cricketmsf.api.ResponseCode;
9 | import org.cricketmsf.event.ProcedureCall;
10 | import org.cricketmsf.in.http.HttpPortedAdapter;
11 | import org.slf4j.Logger;
12 | import org.slf4j.LoggerFactory;
13 |
14 | public class TodoHttpApi extends HttpPortedAdapter implements Adapter {
15 |
16 | private static final Logger logger = LoggerFactory.getLogger(TodoHttpApi.class);
17 |
18 | public TodoHttpApi() {
19 | super();
20 | }
21 |
22 | @Override
23 | public void loadProperties(HashMap properties, String adapterName) {
24 | super.loadProperties(properties, adapterName);
25 | setContext(properties.get("context"));
26 | }
27 |
28 | protected ProcedureCall preprocess(RequestObject request) {
29 | // validation and translation
30 | String method = request.method;
31 | if ("POST".equalsIgnoreCase(method)) {
32 | return preprocessPost(request);
33 | } else if ("GET".equalsIgnoreCase(method)) {
34 | return preprocessGet(request);
35 | } else if ("OPTIONS".equalsIgnoreCase(method)) {
36 | return ProcedureCall.toRespond(200, "OK");
37 | } else {
38 | return ProcedureCall.toRespond(ResponseCode.METHOD_NOT_ALLOWED, "error");
39 | }
40 | }
41 |
42 | private ProcedureCall preprocessPost(RequestObject request) {
43 | String errorMessage = "";
44 | ProcedureCall result;
45 |
46 | HashMap data = new HashMap<>();
47 | data.put("title", (String) request.parameters.getOrDefault("title", ""));
48 |
49 | if (errorMessage.isEmpty()) {
50 | CreateTaskEvent ev = new CreateTaskEvent();
51 | ev.setData(data);
52 | result = ProcedureCall.toForward(ev);
53 | } else {
54 | result = ProcedureCall.toRespond(400, errorMessage);
55 | }
56 | return result;
57 | }
58 |
59 | private ProcedureCall preprocessGet(RequestObject request) {
60 | String errorMessage = "";
61 | ProcedureCall result;
62 | Long id = null;
63 |
64 | try {
65 | id = Long.parseLong((String) request.parameters.get("id"));
66 | } catch (NullPointerException | NumberFormatException ex) {
67 | errorMessage = ex.getMessage();
68 | }
69 |
70 | if (errorMessage.isEmpty()) {
71 | ReadTaskEvent ev = new ReadTaskEvent();
72 | ev.setRootId(request.rootEventId);
73 | ev.setData(id);
74 | result = ProcedureCall.toForward(ev);
75 | } else {
76 | result = ProcedureCall.toRespond(400, errorMessage);
77 | }
78 | return result;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/out/TodoDao.java:
--------------------------------------------------------------------------------
1 | package mytodo.out;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.stream.Collectors;
6 | import mytodo.Task;
7 | import mytodo.event.task.CreateTaskEvent;
8 | import mytodo.event.task.UpdateTaskEvent;
9 | import org.cricketmsf.Adapter;
10 | import org.cricketmsf.out.OutboundAdapter;
11 |
12 | public class TodoDao extends OutboundAdapter implements Adapter,TodoDaoIface {
13 |
14 | HashMap tasks;
15 |
16 | public TodoDao() {
17 | super();
18 | tasks=new HashMap<>();
19 | }
20 |
21 | @Override
22 | public void loadProperties(HashMap properties, String adapterName) {
23 | super.loadProperties(properties, adapterName);
24 | }
25 |
26 | @Override
27 | public boolean createTask(CreateTaskEvent event) {
28 | Task t=new Task();
29 | t.id=System.currentTimeMillis();
30 | t.title=(String)event.getData().get("title");
31 | tasks.put(t.id, t);
32 | return true;
33 | }
34 |
35 | @Override
36 | public Task readTask(long id) {
37 | return tasks.get(id);
38 | }
39 |
40 | @Override
41 | public List readAll() {
42 | return tasks.values().stream().collect(Collectors.toList());
43 | }
44 |
45 | @Override
46 | public boolean updateTask(UpdateTaskEvent event) {
47 | Task t=new Task();
48 | t.id=(Long)event.getData().get("id");
49 | t.title=(String)event.getData().get("title");
50 | if(tasks.containsKey(t.id)){
51 | tasks.put(t.id,t);
52 | return true;
53 | }
54 | return false;
55 | }
56 |
57 | @Override
58 | public boolean deleteTask(long id) {
59 | tasks.remove(id);
60 | return true;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/examples/todo/src/main/java/mytodo/out/TodoDaoIface.java:
--------------------------------------------------------------------------------
1 | package mytodo.out;
2 |
3 | import java.util.List;
4 | import mytodo.Task;
5 | import mytodo.event.task.CreateTaskEvent;
6 | import mytodo.event.task.UpdateTaskEvent;
7 |
8 | /**
9 | *
10 | * @author greg
11 | */
12 | public interface TodoDaoIface {
13 |
14 | public boolean createTask(CreateTaskEvent event);
15 | public Task readTask(long id);
16 | public List readAll();
17 | public boolean updateTask(UpdateTaskEvent event);
18 | public boolean deleteTask(long id);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/examples/todo/src/main/resources/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "@type": "org.cricketmsf.config.ConfigSet",
3 | "description": "ToDo service",
4 | "services": [
5 | {
6 | "@type": "org.cricketmsf.config.Configuration",
7 | "id": "MyTodoService",
8 | "service": "mytodo.TodoService",
9 | "properties": {
10 | "port": "8080"
11 | },
12 | "ports": [
13 | {
14 | "name": "TaskAPI",
15 | "className": "mytodo.in.TodoHttpApi",
16 | "properties": {
17 | "context": "/api/task"
18 | }
19 | },
20 | {
21 | "name": "TodoDao",
22 | "interfaceName": "mytodo.out.TodoDaoIface",
23 | "className": "mytodo.out.TodoDao",
24 | "properties": {
25 | }
26 | }
27 | ]
28 | }
29 | ]
30 | }
31 |
--------------------------------------------------------------------------------
/src/assembly/distribution.xml:
--------------------------------------------------------------------------------
1 |
4 | distribution
5 | false
6 |
7 | zip
8 |
9 |
10 |
11 | ${basedir}/www
12 |
13 | */**
14 |
15 |
16 | README.txt
17 | NOTICE.txt
18 |
19 |
20 |
21 | ${basedir}/src/other
22 | config
23 |
24 | */**
25 |
26 |
27 | *.bak
28 |
29 |
30 |
31 |
32 |
33 | README.md
34 |
35 | true
36 |
37 |
38 | LICENSE
39 |
40 | true
41 |
42 |
43 | target/${artifactId}.jar
44 |
45 | false
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/assembly/filter.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 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/Adapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 | import org.cricketmsf.out.dispatcher.DispatcherIface;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public interface Adapter {
27 |
28 | /**
29 | * This method is executed while adapter is instantiated during the service start.
30 | * It's used to configure the adapter according to the configuration.
31 | *
32 | * @param properties map of properties readed from the configuration file
33 | * @param adapterName name of the adapter set in the configuration file (can be different
34 | * from the interface and class name.
35 | */
36 | public void loadProperties(HashMap properties, String adapterName);
37 |
38 | public Map getStatus(String name);
39 | public void updateStatusItem(String key, String value);
40 | public DispatcherIface getDispatcher();
41 | public String getName();
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/AuthorizationFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | import com.sun.net.httpserver.Filter;
19 | import com.sun.net.httpserver.HttpExchange;
20 | import java.io.IOException;
21 |
22 | /**
23 | * This is default filter used to check required request conditions.
24 | * It does nothing but could be used as a starting point to implement required filter.
25 | *
26 | * @author Grzegorz Skorupa
27 | */
28 | public class AuthorizationFilter extends Filter {
29 |
30 | private int errorCode = 200;
31 | private String errorMessage = "";
32 |
33 | @Override
34 | public String description() {
35 | return "Default security filter";
36 | }
37 |
38 | /**
39 | * Does request analysis
40 | *
41 | * @param exchange request object
42 | * @return true when authorized
43 | */
44 | public AuthorizationFilterResult checkRequest(HttpExchange exchange) {
45 | AuthorizationFilterResult result = new AuthorizationFilterResult();
46 | // below is simple example how to ovetwrite this method
47 | /*
48 | boolean problemDetected = false;
49 | // do some request checks etc.
50 | if (problemDetected) {
51 | result.code = 403; // FORBIDDEN
52 | result.message = "request blocket by security filter\r\n";
53 | } else {
54 | result.code = 200;
55 | result.message = "";
56 | }
57 | */
58 | return result;
59 | }
60 |
61 | @Override
62 | public void doFilter(HttpExchange exchange, Chain chain)
63 | throws IOException {
64 | // below is simple example how to ovetwrite this method
65 | /*
66 | SecurityFilterResult result = checkRequest(exchange);
67 | if (result.code != 200) {
68 | exchange.sendResponseHeaders(result.code, result.message.length());
69 | exchange.getResponseBody().write(result.message.getBytes());
70 | exchange.getResponseBody().close();
71 | exchange.close();
72 | } else {
73 | chain.doFilter(exchange);
74 | }
75 | */
76 | chain.doFilter(exchange);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/AuthorizationFilterResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class AuthorizationFilterResult {
23 | public int code = 0;
24 | public String message = "";
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/CricketThreadFactory.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf;
2 |
3 | import java.util.HashMap;
4 | import java.util.concurrent.ThreadFactory;
5 |
6 | /**
7 | *
8 | * @author greg
9 | */
10 | public class CricketThreadFactory implements ThreadFactory {
11 |
12 | private int counter;
13 | private String name;
14 | private ThreadGroup rootGroup;
15 | private HashMap groups = new HashMap<>();
16 |
17 | public CricketThreadFactory(String name) {
18 | counter = 1;
19 | this.name = name;
20 | rootGroup = new ThreadGroup(name);
21 | }
22 |
23 | @Override
24 | public Thread newThread(Runnable runnable) {
25 | Thread t = new Thread(runnable, "Scheduler");
26 | counter++;
27 | return t;
28 | }
29 |
30 | public Thread newThread(Runnable runnable, String name) {
31 | Thread t;
32 | if(this.name.equalsIgnoreCase(name)){
33 | t = new Thread(rootGroup, runnable, name + "-Thread_" + counter);
34 | }else if(groups.containsKey(name)){
35 | t = new Thread(groups.get(name), runnable, name + "-Thread_" + counter);
36 | }else{
37 | groups.put(name, new ThreadGroup(name));
38 | t = new Thread(groups.get(name), runnable, name + "-Thread_" + counter);
39 | }
40 | counter++;
41 | return t;
42 | }
43 |
44 | public void list(){
45 | rootGroup.list();
46 | for(ThreadGroup tg :groups.values()){
47 | tg.list();
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/FileParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | /**
19 | *
20 | * @author Grzegorz Skorupa
21 | */
22 | public class FileParameter {
23 | public String nextLine;
24 | public String fileLocation;
25 | public long fileSize;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/HttpdIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public interface HttpdIface {
8 | public void run();
9 | public void stop();
10 | public boolean isSsl();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/RequestHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | /**
19 | *
20 | * @author Grzegorz Skorupa
21 | */
22 | public class RequestHeader {
23 | public String name=null;
24 | public String value=null;
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/RequestObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | import com.sun.net.httpserver.Headers;
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public class RequestObject {
27 |
28 | public Long rootEventId = null;
29 | public String clientIp = null;
30 | public String method = null;
31 | public String uri = null;
32 | public String pathExt = null;
33 | public Headers headers = null;
34 | public Map parameters = new HashMap<>();
35 | public String acceptedResponseType = null;
36 | public String body = null;
37 |
38 | public RequestObject() {
39 | rootEventId=Kernel.getEventId();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/RequestParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf;
17 |
18 | /**
19 | *
20 | * @author Grzegorz Skorupa
21 | */
22 | public class RequestParameter {
23 | public String name=null;
24 | public String value=null;
25 | public RequestParameter(String name, String value){
26 | this.name=name;
27 | this.value=value;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/annotation/EventHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.annotation;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Repeatable;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 | import org.cricketmsf.event.Procedures;
25 |
26 | /**
27 | *
28 | * @author Grzegorz Skorupa
29 | */
30 | @Documented
31 | @Repeatable(EventHook.List.class)
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Target(ElementType.METHOD)
34 | public @interface EventHook {
35 | public String className();
36 | public int procedure() default Procedures.DEFAULT;
37 |
38 | @Documented
39 | @Retention(RetentionPolicy.RUNTIME)
40 | @Target(ElementType.METHOD)
41 | @interface List {
42 | EventHook[] value();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/annotation/WebsocketAdapterHook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.annotation;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | *
26 | * @author Grzegorz Skorupa
27 | */
28 | @Documented
29 | @Retention(RetentionPolicy.RUNTIME)
30 | @Target(ElementType.METHOD)
31 | public @interface WebsocketAdapterHook {
32 | public String adapterName();
33 | public String context();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/api/HttpResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Grzegorz Skorupa
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.api;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class HttpResult extends StandardResult {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/api/ResponseCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.api;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class ResponseCode {
23 | public final static int OK = 200;
24 | public final static int ACCEPTED = 202;
25 | public final static int CREATED = 201;
26 |
27 | public final static int MOVED_PERMANENTLY = 301;
28 | public final static int MOVED_TEMPORARY = 302;
29 | public final static int NOT_MODIFIED = 304;
30 |
31 | public final static int BAD_REQUEST = 400;
32 | public final static int UNAUTHORIZED = 401;
33 | public final static int SESSION_EXPIRED = 401;
34 | public final static int FORBIDDEN = 403;
35 | public final static int NOT_FOUND = 404;
36 | public final static int METHOD_NOT_ALLOWED = 405;
37 | public final static int CONFLICT = 409;
38 |
39 | public final static int INTERNAL_SERVER_ERROR = 500;
40 | public final static int NOT_IMPLEMENTED = 501;
41 | public final static int UNAVAILABLE = 503;
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/api/ResultIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.api;
17 |
18 | import com.sun.net.httpserver.Headers;
19 | import java.util.Date;
20 | import java.util.List;
21 |
22 | /**
23 | *
24 | * @author greg
25 | */
26 | public interface ResultIface {
27 |
28 | //public String getProcedureName();
29 | //public void setProcedureName(String procedureName);
30 | public int getProcedure();
31 | public void setProcedure(int procedure);
32 | public int getCode();
33 | public void setCode(int code);
34 | public String getMessage();
35 | public void setMessage(String message);
36 | public String getContentType();
37 | public void setContentType(String contentType);
38 | public Object getData();
39 | public void setData(Object data);
40 | public byte[] getPayload();
41 | public void setPayload(byte[] payload);
42 | public String getFileExtension();
43 | public void setFileExtension(String fileExt);
44 | public void setModificationDate(Date date);
45 | public Date getModificationDate();
46 | public String getModificationDateFormatted();
47 | public int getMaxAge();
48 | public void setMaxAge(int maxAge);
49 | public void setHeader(String name, String value);
50 | public void setHeader(String name, List values);
51 | public Headers getHeaders();
52 | public void setResponseTime(long time);
53 | public long getResponseTime();
54 | //public ResultIface procedureName(String procedureName);
55 | public ResultIface procedure(int procedure);
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/config/HttpHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.config;
17 |
18 | /**
19 | * Http header
20 | */
21 | public class HttpHeader {
22 | public String name;
23 | public String value;
24 |
25 | public HttpHeader(String name, String value){
26 | this.name=name;
27 | this.value=value;
28 | }
29 |
30 | /*
31 | public String getName() {
32 | return name;
33 | }
34 |
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 |
41 | public String getValue() {
42 | return value;
43 | }
44 |
45 |
46 | public void setValue(String value) {
47 | this.value = value;
48 | }
49 | */
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/Delay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | import java.util.concurrent.TimeUnit;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class Delay {
25 |
26 | private TimeUnit unit;
27 | private long delay;
28 | private long firstExecutionTime;
29 | private boolean cyclic = false;
30 | private boolean executionDateDefined;
31 |
32 | public Delay() {
33 | delay = -1;
34 | firstExecutionTime = -1;
35 | cyclic = false;
36 | unit = null;
37 | executionDateDefined = false;
38 | }
39 |
40 | /**
41 | * @return the unit
42 | */
43 | public TimeUnit getUnit() {
44 | return unit;
45 | }
46 |
47 | /**
48 | * @param unit the unit to set
49 | */
50 | public void setUnit(TimeUnit unit) {
51 | this.unit = unit;
52 | }
53 |
54 | /**
55 | * @return the delay
56 | */
57 | public long getDelay() {
58 | return delay;
59 | }
60 |
61 | /**
62 | * @param delay the delay to set
63 | */
64 | public void setDelay(long delay) {
65 | firstExecutionTime = System.currentTimeMillis() + delay;
66 | this.delay = delay;
67 | }
68 |
69 | public long getFirstExecutionTime() {
70 | return firstExecutionTime;
71 | }
72 |
73 | public void setFirstExecutionTime(long timepoint) {
74 | firstExecutionTime = timepoint;
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return "DELAY " + getDelay() + " " + getUnit();
80 | }
81 |
82 | /**
83 | * @return the cyclic
84 | */
85 | public boolean isCyclic() {
86 | return cyclic;
87 | }
88 |
89 | /**
90 | * @param cyclic the cyclic to set
91 | */
92 | public void setCyclic(boolean cyclic) {
93 | this.cyclic = cyclic;
94 | }
95 |
96 | /**
97 | * @return the fromDateDefinition
98 | */
99 | public boolean isExecutionDateDefined() {
100 | return executionDateDefined;
101 | }
102 |
103 | /**
104 | * @param executionDateDefined the fromDateDefinition to set
105 | */
106 | public void setExecutionDateDefined(boolean executionDateDefined) {
107 | this.executionDateDefined = executionDateDefined;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/EventDto.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.event;
2 |
3 | import com.cedarsoftware.util.io.JsonWriter;
4 | import java.util.HashMap;
5 | import org.cricketmsf.util.JsonReader;
6 |
7 | /**
8 | *
9 | * @author greg
10 | */
11 | public class EventDto {
12 |
13 | public String eventClassName;
14 | public HashMap data;
15 |
16 | public EventDto() {
17 | }
18 |
19 | public EventDto(String eventClassName, HashMap data) {
20 | this.eventClassName = eventClassName;
21 | this.data = data;
22 | }
23 |
24 | public EventDto(Event event){
25 | eventClassName=event.getClass().getName();
26 | data=(HashMap)event.getData();
27 | }
28 |
29 | public String toJson() {
30 | return JsonWriter.objectToJson(this);
31 | }
32 |
33 | public static EventDto fromJson(String json) {
34 | return (EventDto) JsonReader.jsonToJava(json);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/EventMaster.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | import java.util.TreeMap;
19 | import org.cricketmsf.exception.EventException;
20 |
21 | /**
22 | *
23 | * @author greg
24 | */
25 | public class EventMaster {
26 |
27 | public static TreeMap register = new TreeMap<>();
28 |
29 | public static void registerEventCategories(String[] categories, String eventClassName) throws EventException {
30 |
31 | for (int i = 0; i < categories.length; i++) {
32 | if (register.containsKey(categories[i])) {
33 | throw new EventException(EventException.CATEGORY_ALREADY_DEFINED, "Event category " + categories[i] + " alredy registered by " + register.get(categories[i]));
34 | }
35 | register.put(categories[i], eventClassName);
36 | }
37 |
38 | }
39 |
40 | public static void registerEventCategories(Class cls) throws EventException {
41 | try {
42 | if (cls.getSuperclass().isInstance(cls.newInstance())) {
43 | register.put(cls.getName(), cls.getName());
44 | } else {
45 | throw new EventException(EventException.MUST_EXTEND_DECORATOR, cls.getSuperclass().getName()+" is not EventDecorator subclass");
46 | }
47 | } catch (InstantiationException|IllegalAccessException ex) {
48 | throw new EventException(EventException.MUST_EXTEND_DECORATOR, cls.getSuperclass().getName()+" is not EventDecorator subclass");
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/GreeterEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | import java.util.HashMap;
19 |
20 | /**
21 | * To be removed
22 | * @author greg
23 | */
24 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Base")
25 | @org.cricketmsf.livingdoc.design.Event()
26 | public class GreeterEvent extends Event {
27 |
28 | public GreeterEvent(HashMap parameters) {
29 | super();
30 | setData(parameters);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/HttpEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | /**
19 | * To be removed
20 | * @author greg
21 | */
22 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Base")
23 | @org.cricketmsf.livingdoc.design.Event()
24 | public class HttpEvent extends Event {
25 |
26 | public HttpEvent(int procedure, Object request) {
27 | super();
28 | setData(request);
29 | setProcedure(procedure);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/ProceduresIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.event;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public interface ProceduresIface {
8 | public int getId(String name);
9 | public String getName(int id);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/ShutdownRequested.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | /**
19 | * To be removed
20 | * @author greg
21 | */
22 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Base")
23 | @org.cricketmsf.livingdoc.design.Event()
24 | public class ShutdownRequested extends Event {
25 |
26 | public ShutdownRequested(long delay) {
27 | super();
28 | super.setEventDelay(delay);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/event/StatusRequested.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.event;
17 |
18 | import java.util.HashMap;
19 |
20 | /**
21 | * To be removed
22 | * @author greg
23 | */
24 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Base")
25 | @org.cricketmsf.livingdoc.design.Event()
26 | public class StatusRequested extends Event {
27 |
28 | public StatusRequested() {
29 | super();
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/AdapterException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class AdapterException extends Exception {
23 |
24 | public static final int UNSUPPORTED_CONTENT_TYPE = 700;
25 | public static final int IO_EXCEPTION = 701;
26 | public static final int CRYPTOGRAPHY_EXCEPTION = 702;
27 | public static final int STRANGE_CODE = 703;
28 | public static final int UNKNOWN = 777;
29 |
30 | private int code = UNKNOWN;
31 | private String message;
32 |
33 | public AdapterException(int code) {
34 | this.code = code;
35 | switch (code) {
36 | case UNKNOWN:
37 | message = "unknown error";
38 | break;
39 | default:
40 | this.code= UNKNOWN;
41 | message = "unknown error";
42 | break;
43 | }
44 | }
45 |
46 | public AdapterException(int code, String message) {
47 | this.code = code;
48 | this.message = message;
49 | }
50 |
51 | public String getMessage() {
52 | return message;
53 | }
54 |
55 | public int getCode() {
56 | return code;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/DispatcherException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 |
19 | /**
20 | *
21 | * @author greg
22 | */
23 | public class DispatcherException extends Exception {
24 |
25 | public static int UNKNOWN = 999;
26 | public static int NOT_IMPLEMENTED = 998;
27 | public static int QUEUE_EXCEPTION = 997;
28 | public static int UNKNOWN_EVENT = 996;
29 | public static int QUEUE_CLIENT_NOT_DEFINED = 995;
30 |
31 | private int code = NOT_IMPLEMENTED;
32 | private String message;
33 |
34 | public DispatcherException(int code){
35 | this.code = code;
36 | switch (code){
37 | case 998:
38 | message = "operation not implemented";
39 | break;
40 | case 997:
41 | message = "queue client exception";
42 | break;
43 | case 996:
44 | message = "unknown event";
45 | break;
46 | case 995:
47 | message = "queue client not defined";
48 | break;
49 | case 999:
50 | message = "unknown error";
51 | break;
52 | }
53 | }
54 |
55 | public DispatcherException(int code, String message){
56 | this.code = code;
57 | this.message = message;
58 | }
59 |
60 | public String getMessage(){
61 | return message;
62 | }
63 |
64 | public int getCode(){
65 | return code;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/EventException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 |
19 | /**
20 | *
21 | * @author greg
22 | */
23 | public class EventException extends Exception {
24 |
25 | public static final int UNKNOWN = 999;
26 | public static final int NOT_IMPLEMENTED = 1;
27 | public static final int CATEGORY_ALREADY_DEFINED = 2;
28 | public static final int MUST_OVERRIDE_REGISTER = 3;
29 | public static final int MUST_EXTEND_DECORATOR = 4;
30 |
31 | private int code = NOT_IMPLEMENTED;
32 | private String message;
33 |
34 | public EventException(int code){
35 | this.code = code;
36 | switch (code){
37 | case 1:
38 | message = "operation not implemented";
39 | break;
40 | case 2:
41 | message = "event category already defined";
42 | break;
43 | case 3:
44 | message = "class does not override required method";
45 | break;
46 | case 4:
47 | message = "class does not extend EventDecoraor";
48 | break;
49 | case 999:
50 | message = "unknown error";
51 | break;
52 | }
53 | }
54 |
55 | public EventException(int code, String message){
56 | this.code = code;
57 | this.message = message;
58 | }
59 |
60 | public String getMessage(){
61 | return message;
62 | }
63 |
64 | public int getCode(){
65 | return code;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/InitException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 |
19 | /**
20 | *
21 | * @author greg
22 | */
23 | public class InitException extends Exception {
24 |
25 | public static final int UNKNOWN = 999;
26 |
27 |
28 | private int code = UNKNOWN;
29 | private String message;
30 |
31 | public InitException(int code){
32 | this.code = code;
33 | switch (code){
34 | case 999:
35 | message = "unknown error";
36 | break;
37 | }
38 | }
39 |
40 | public InitException(int code, String message){
41 | this.code = code;
42 | this.message = message;
43 | }
44 |
45 | public String getMessage(){
46 | return message;
47 | }
48 |
49 | public int getCode(){
50 | return code;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/QueueException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class QueueException extends Exception {
23 |
24 | public static final int UNKNOWN = 888;
25 | public static int NOT_IMPLEMENTED = 887;
26 | public static int QUEUE_NOT_DEFINED = 886;
27 | public static int CLIENT_NOT_DEFINED = 885;
28 | public static int SUBSCRIPTION_NOT_POSSIBLE = 884;
29 |
30 | private int code = NOT_IMPLEMENTED;
31 | private String message;
32 |
33 | public QueueException(int code) {
34 | this.code = code;
35 | switch (code) {
36 | case 887:
37 | message = "operation not implemented";
38 | break;
39 | case 886:
40 | message = "queue not defined";
41 | break;
42 | case 888:
43 | message = "unknown error";
44 | break;
45 | }
46 | }
47 |
48 | public QueueException(int code, String message) {
49 | this.code = code;
50 | this.message = message;
51 | }
52 |
53 | public String getMessage() {
54 | return message;
55 | }
56 |
57 | public int getCode() {
58 | return code;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/exception/WebsocketException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.exception;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class WebsocketException extends Exception {
23 |
24 | public static int CONTEXT_NOT_DEFINED = 1;
25 | public static int IO_EXCEPTION = 2;
26 | public static int NOT_IMPLEMENTED = 99;
27 | public static int UNDEFINED = 100;
28 |
29 | private int code = NOT_IMPLEMENTED;
30 | private String message;
31 |
32 | public WebsocketException(int code) {
33 | this.code = code;
34 | switch (code) {
35 | case 99:
36 | message = "operation not implemented";
37 | break;
38 | case 1:
39 | message = "unknown context";
40 | break;
41 | case 2:
42 | message = "IO exception";
43 | break;
44 | case 100:
45 | message = "unknown error";
46 | break;
47 | }
48 | }
49 |
50 | public WebsocketException(int code, String message) {
51 | this.code = code;
52 | this.message = message;
53 | }
54 |
55 | public String getMessage() {
56 | return message;
57 | }
58 |
59 | public int getCode() {
60 | return code;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/InboundAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in;
17 |
18 | import java.util.Map;
19 |
20 | /**
21 | *
22 | * @author Grzegorz Skorupa
23 | */
24 | public interface InboundAdapterIface {
25 | public String getProperty(String name);
26 | public String setProperty(String name, String value);
27 | public Map getStatus(String name);
28 | public String getName();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/ResultNotUsed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in;
17 |
18 | import com.sun.net.httpserver.Headers;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | @Deprecated
25 | public interface ResultNotUsed {
26 |
27 | /**
28 | * @return the status code
29 | */
30 | public int getCode();
31 |
32 | /**
33 | * @param code the status code to set
34 | */
35 | public void setCode(int code);
36 |
37 | /**
38 | * @return the status message
39 | */
40 | public String getMessage();
41 |
42 | /**
43 | * @param message the message to set
44 | */
45 | public void setMessage(String message);
46 |
47 | public byte[] getPayload();
48 |
49 | public void setPayload(byte[] payload);
50 |
51 | public void buildPayload(String payload);
52 |
53 | public void setHeader(String name, String value);
54 |
55 | public Headers getHeaders();
56 | public void setResponseTime(long time);
57 | public long getResponseTime();
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/cli/CliEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.cli;
17 |
18 | import org.cricketmsf.event.*;
19 | import java.util.HashMap;
20 |
21 | /**
22 | * To be removed
23 | * @author greg
24 | */
25 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Content Management")
26 | @org.cricketmsf.livingdoc.design.Event()
27 | public class CliEvent extends Event {
28 |
29 | public CliEvent(String command) {
30 | super();
31 | setData(command);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/cli/CliIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.cli;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface CliIface {
23 |
24 | public void start();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/event/EventHandler.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.event;
2 |
3 | import org.cricketmsf.event.Event;
4 | import org.cricketmsf.Kernel;
5 |
6 | /**
7 | *
8 | * @author greg
9 | */
10 | public class EventHandler implements Runnable {
11 |
12 | Event event;
13 |
14 | public EventHandler(Event event){
15 | this.event=event;
16 | }
17 |
18 | @Override
19 | public void run() {
20 | Kernel.getInstance().handleEvent(event);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/event/EventListenerIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.event;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public interface EventListenerIface {
8 | public boolean isReady();
9 | public void start();
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/file/FileEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.file;
17 |
18 | import org.cricketmsf.event.*;
19 |
20 | /**
21 | * To be removed
22 | * @author greg
23 | */
24 | @org.cricketmsf.livingdoc.design.BoundedContext(name="Content Management")
25 | @org.cricketmsf.livingdoc.design.Event()
26 | public class FileEvent extends Event {
27 |
28 | public FileEvent(byte[] content) {
29 | super();
30 | setData(content);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/file/NotDirectoryFilter.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.file;
2 |
3 | import java.io.File;
4 | import java.io.FileFilter;
5 |
6 | /**
7 | *
8 | * @author greg
9 | */
10 | public class NotDirectoryFilter implements FileFilter{
11 |
12 | @Override
13 | public boolean accept(File file) {
14 | return file.isFile();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/file/WatchdogIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.file;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface WatchdogIface {
23 |
24 | public void checkStatus();
25 | public void shutdown();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/AdapterError.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.http;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | @Deprecated
8 | public class AdapterError {
9 |
10 | public int code;
11 | public String message;
12 |
13 | public AdapterError() {
14 | }
15 |
16 | public AdapterError(int errorCode, String message) {
17 | this.code = errorCode;
18 | this.message = message;
19 | }
20 |
21 | /**
22 | * @return the code
23 | */
24 | public int getCode() {
25 | return code;
26 | }
27 |
28 | /**
29 | * @param code the code to set
30 | */
31 | public void setCode(int code) {
32 | this.code = code;
33 | }
34 |
35 | /**
36 | * @return the message
37 | */
38 | public String getMessage() {
39 | return message;
40 | }
41 |
42 | /**
43 | * @param message the message to set
44 | */
45 | public void setMessage(String message) {
46 | this.message = message;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/CorsProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import com.sun.net.httpserver.Headers;
19 | import java.util.ArrayList;
20 | import org.cricketmsf.config.HttpHeader;
21 |
22 | /**
23 | *
24 | * @author greg
25 | */
26 | public class CorsProcessor {
27 |
28 | public static Headers getResponseHeaders(Headers responseHeaders, Headers requestHeaders, ArrayList corsConfig) {
29 | String origin = requestHeaders.getFirst("Origin");
30 | if(origin==null){
31 | origin = requestHeaders.getFirst("Referer"); //TODO: this is workaround - see HttpAdapter 188
32 | }
33 | if(origin==null){
34 |
35 | }
36 | // boolean withCredentials = "true".equals(requestHeaders.getFirst("Access-Control-Allow-Credentials"));
37 | HttpHeader h;
38 | //if (!withCredentials) {
39 | // for (int i = 0; i < corsConfig.size(); i++) {
40 | // h = (HttpHeader) corsConfig.get(i);
41 | // responseHeaders.set(h.name, h.value);
42 | // }
43 | //}else{
44 | for (int i = 0; i < corsConfig.size(); i++) {
45 | h = (HttpHeader) corsConfig.get(i);
46 | if("Access-Control-Allow-Origin".equals(h.name)){
47 | if("*".equals(h.value) && origin!=null){
48 | responseHeaders.set(h.name, origin);
49 | }else{
50 | responseHeaders.set(h.name, h.value);
51 | }
52 | }else{
53 | responseHeaders.set(h.name, h.value);
54 | }
55 | }
56 | //}
57 | return responseHeaders;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/CsvFormatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import org.cricketmsf.api.ResultIface;
19 | import java.io.IOException;
20 | import java.util.List;
21 | import java.util.Map;
22 | import org.apache.commons.csv.CSVFormat;
23 | import org.apache.commons.csv.CSVPrinter;
24 | import org.apache.commons.csv.QuoteMode;
25 |
26 | /**
27 | *
28 | * @author Grzegorz Skorupa
29 | */
30 | public class CsvFormatter {
31 |
32 | private static CsvFormatter instance = null;
33 |
34 | public static CsvFormatter getInstance() {
35 | if (instance != null) {
36 | return instance;
37 | } else {
38 | instance = new CsvFormatter();
39 | return instance;
40 | }
41 | }
42 |
43 | public String format(List list) {
44 | StringBuilder sb = new StringBuilder();
45 | try {
46 | CSVPrinter printer = new CSVPrinter(sb, CSVFormat.EXCEL.withRecordSeparator("\r\n"));
47 | if (list.size() > 0) {
48 | for (int i = 0; i < list.size(); i++) {
49 | printer.printRecord((List) list.get(i));
50 | }
51 | }
52 | } catch (IOException e) {
53 | sb.append(e.getMessage());
54 | }
55 | return sb.append("\r\n").toString();
56 | }
57 |
58 | public String format(Map data) {
59 | StringBuilder sb = new StringBuilder();
60 | try {
61 | CSVPrinter printer = new CSVPrinter(sb, CSVFormat.EXCEL.withRecordSeparator("\r\n"));
62 | printer.printRecord(data.values());
63 | } catch (IOException e) {
64 | sb.append(e.getMessage());
65 |
66 | }
67 | return sb.append("\r\n").toString();
68 | }
69 |
70 | public String format(ResultIface r) {
71 | if (r.getData() instanceof List) {
72 | return format((List) r.getData());
73 | } else if (r.getData() instanceof Map) {
74 | return format((Map) r.getData());
75 | } else {
76 | return "unsupported data format\r\n";
77 | //TODO: error code?
78 | }
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/GreeterAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import java.util.HashMap;
19 | import org.cricketmsf.RequestObject;
20 | import org.cricketmsf.event.Procedures;
21 | import org.cricketmsf.api.ResultIface;
22 | import org.cricketmsf.api.StandardResult;
23 | import org.cricketmsf.event.GreeterEvent;
24 | import org.cricketmsf.event.ProcedureCall;
25 |
26 | /**
27 | *
28 | * @author Grzegorz Skorupa
29 | */
30 | public class GreeterAdapter
31 | extends HttpPortedAdapter /*implements Adapter, HttpAdapterIface, HttpHandler, InboundAdapterIface/*, org.eclipse.jetty.server.Handler*/ {
32 |
33 | public static int PARAM_NOT_FOUND = 1;
34 |
35 | public GreeterAdapter() {
36 | super();
37 | }
38 |
39 | @Override
40 | protected ProcedureCall preprocess(RequestObject request) {
41 | // validation and translation
42 | String name = (String) request.parameters.getOrDefault("name", "");
43 | if (name.isEmpty() || !"world".equalsIgnoreCase(name)) {
44 | HashMap err = new HashMap<>();
45 | err.put("code", PARAM_NOT_FOUND); //code<100 || code >1000
46 | // http status codes can be used directly:
47 | // err.put("code", 404);
48 | err.put("message", "unknown name or name parameter not found (must be 'world')");
49 | return ProcedureCall.toRespond(PARAM_NOT_FOUND, err);
50 | }
51 | // building resulting call
52 | HashMapdata=new HashMap<>();
53 | data.put("name", name);
54 | GreeterEvent event = new GreeterEvent(data);
55 | event.setProcedure(Procedures.GREET);
56 | return ProcedureCall.toForward(event);
57 | }
58 |
59 | @Override
60 | protected ResultIface postprocess(ResultIface fromService){
61 | StandardResult result=new StandardResult(fromService.getData());
62 | result.setHeader("Content-type", "text/plain");
63 | return result;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/HtmlGenAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | /**
19 | *
20 | * @author Grzegorz Skorupa
21 | */
22 | public interface HtmlGenAdapterIface {
23 |
24 | public boolean useCache();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/HttpAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import java.util.Map;
19 | import org.cricketmsf.in.InboundAdapterIface;
20 | import org.cricketmsf.in.openapi.Operation;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public interface HttpAdapterIface extends InboundAdapterIface{
27 | public void defineApi();
28 | public void addOperationConfig(Operation operation);
29 | public Map getOperations();
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/JsonFormatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import com.cedarsoftware.util.io.JsonWriter;
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public class JsonFormatter {
27 |
28 | private static JsonFormatter instance = null;
29 | private Map args;
30 |
31 | public JsonFormatter(){
32 | args = new HashMap();
33 | }
34 |
35 | public static JsonFormatter getInstance() {
36 | if (instance != null) {
37 | return instance;
38 | } else {
39 | instance = new JsonFormatter();
40 | return instance;
41 | }
42 | }
43 |
44 | /**
45 | * Translates response object to JSON representation
46 | * @param prettyPrint pretty print JSON or not
47 | * @param o response object
48 | * @return response as JSON String
49 | */
50 | public String format(boolean prettyPrint, Object o) {
51 | args.clear();
52 | args.put(JsonWriter.PRETTY_PRINT, prettyPrint);
53 | args.put(JsonWriter.DATE_FORMAT, "dd/MMM/yyyy:kk:mm:ss Z");
54 | args.put(JsonWriter.TYPE, false);
55 | return JsonWriter.objectToJson(o, args)+"\r\n";
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/StatusAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import org.cricketmsf.RequestObject;
19 | import org.cricketmsf.event.Event;
20 | import org.cricketmsf.event.Procedures;
21 | import org.cricketmsf.event.ProcedureCall;
22 |
23 | /**
24 | *
25 | * @author Grzegorz Skorupa
26 | */
27 | public class StatusAdapter
28 | extends HttpPortedAdapter /*implements Adapter, HttpAdapterIface, HttpHandler, InboundAdapterIface/*, org.eclipse.jetty.server.Handler*/ {
29 |
30 | public StatusAdapter() {
31 | super();
32 | }
33 |
34 | @Override
35 | protected ProcedureCall preprocess(RequestObject request) {
36 | Event event = new Event();
37 | event.setProcedure(Procedures.SYSTEM_STATUS);
38 | return ProcedureCall.toForward(event);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/Tester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import org.cricketmsf.RequestObject;
19 | import org.cricketmsf.api.ResponseCode;
20 | import org.cricketmsf.event.ProcedureCall;
21 | import org.cricketmsf.microsite.out.cms.ContentRequestProcessor;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | /**
26 | *
27 | * @author Grzegorz Skorupa
28 | */
29 | public class Tester extends HttpPortedAdapter {
30 |
31 | private static final Logger logger = LoggerFactory.getLogger(Tester.class);
32 |
33 | @Override
34 | protected ProcedureCall preprocess(RequestObject request) {
35 | logger.info(dumpRequest(request));
36 | return ProcedureCall.toRespond(ResponseCode.OK, "");
37 | }
38 |
39 | public static String dumpRequest(RequestObject req) {
40 | StringBuilder sb = new StringBuilder();
41 | sb.append("************** REQUEST ****************").append("\r\n");
42 | sb.append("URI:").append(req.uri).append("\r\n");
43 | sb.append("PATHEXT:").append(req.pathExt).append("\r\n");
44 | sb.append("METHOD:").append(req.method).append("\r\n");
45 | sb.append("ACCEPT:").append(req.acceptedResponseType).append("\r\n");
46 | sb.append("CLIENT IP:").append(req.clientIp).append("\r\n");
47 | sb.append("***BODY:").append("\r\n");
48 | sb.append(req.body).append(req.body.isEmpty()?"":"\r\n");
49 | sb.append("***BODY.").append("\r\n");
50 | sb.append("***HEADERS:").append("\r\n");
51 | req.headers.keySet().forEach(key -> {
52 | sb.append(key)
53 | .append(":")
54 | .append(req.headers.getFirst(key))
55 | .append("\r\n");
56 | });
57 | sb.append("***HEADERS.").append("\r\n");
58 | sb.append("***PARAMETERS:").append("\r\n");
59 | req.parameters.keySet().forEach(key -> {
60 | sb.append(key)
61 | .append(":")
62 | .append(req.parameters.get(key))
63 | .append("\r\n");
64 | });
65 | sb.append("***PARAMETERS.").append("\r\n");
66 | return sb.toString();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/http/XmlFormatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.http;
17 |
18 | import java.io.StringWriter;
19 | import javax.xml.bind.JAXBContext;
20 | import javax.xml.bind.JAXBException;
21 | import javax.xml.bind.Marshaller;
22 |
23 | /**
24 | *
25 | * @author Grzegorz Skorupa
26 | */
27 | public class XmlFormatter {
28 |
29 | private static XmlFormatter instance = null;
30 |
31 | public static XmlFormatter getInstance() {
32 | if (instance != null) {
33 | return instance;
34 | } else {
35 | instance = new XmlFormatter();
36 | return instance;
37 | }
38 | }
39 |
40 | /**
41 | *
42 | * @param prettyPrint TODO doc
43 | * @param r response object (Result or Result.getData())
44 | * @return TODO doc
45 | */
46 | public String format(boolean prettyPrint, Object r) {
47 | try {
48 | JAXBContext jaxbContext = JAXBContext.newInstance(r.getClass());
49 | Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
50 | // output pretty printed
51 | jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint);
52 | StringWriter sw = new StringWriter();
53 | jaxbMarshaller.marshal(r, sw);
54 | return sw.toString();
55 | } catch (JAXBException e) {
56 | return ""+e.getErrorCode()+"
"+e.toString()+"";
57 | }
58 | }
59 |
60 | /*
61 | public String format(boolean prettyPrint, Result r) {
62 | XStream xstream = new XStream(new StaxDriver());
63 | xstream.alias("result", r.getClass());
64 | String result = "";
65 | if (prettyPrint) {
66 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
67 | xstream.marshal(r, new PrettyPrintWriter(new OutputStreamWriter(baos)));
68 | result = baos.toString();
69 | } else {
70 | result = xstream.toXML(r);
71 | }
72 | return result;
73 | }
74 | */
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/mqtt/Callback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.mqtt;
17 |
18 | import java.util.logging.Level;
19 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
20 | import org.eclipse.paho.client.mqttv3.MqttCallback;
21 | import org.eclipse.paho.client.mqttv3.MqttClient;
22 | import org.eclipse.paho.client.mqttv3.MqttException;
23 | import org.eclipse.paho.client.mqttv3.MqttMessage;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | /**
28 | *
29 | * @author Grzegorz Skorupa
30 | */
31 | public class Callback implements MqttCallback, MqttSubscriberCallback {
32 |
33 | private static final Logger logger = LoggerFactory.getLogger(Callback.class);
34 |
35 | private MqttClient client;
36 |
37 | public Callback() {
38 | }
39 |
40 | @Override
41 | public void setClient(MqttClient client){
42 | this.client=client;
43 | }
44 |
45 | @Override
46 | public void messageArrived(String topic, MqttMessage message) throws Exception {
47 |
48 | }
49 |
50 | @Override
51 | public void connectionLost(Throwable cause) {
52 | try {
53 | client.reconnect();
54 | } catch (MqttException ex) {
55 | logger.warn(ex.getMessage());
56 | }
57 | }
58 |
59 | @Override
60 | public void deliveryComplete(IMqttDeliveryToken token) {
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/mqtt/EventSubscriberCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.mqtt;
17 |
18 | import org.cricketmsf.event.Event;
19 | import org.cricketmsf.Kernel;
20 | import org.cricketmsf.out.dispatcher.MessageDispatcher;
21 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
22 | import org.eclipse.paho.client.mqttv3.MqttCallback;
23 | import org.eclipse.paho.client.mqttv3.MqttMessage;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | /**
28 | *
29 | * @author Grzegorz Skorupa
30 | */
31 | public class EventSubscriberCallback implements MqttCallback {
32 |
33 | private static final Logger logger = LoggerFactory.getLogger(EventSubscriberCallback.class);
34 | private String rootTopic;
35 | private String typeSuffix;
36 | private int prefixLength = 0;
37 |
38 | public EventSubscriberCallback(String rootTopic, String typeSuffix) {
39 | this.rootTopic = rootTopic;
40 | if (!this.rootTopic.endsWith("/")) {
41 | this.rootTopic = this.rootTopic.concat("/");
42 | }
43 | prefixLength = this.rootTopic.length();
44 | this.typeSuffix = typeSuffix;
45 | }
46 |
47 | @Override
48 | public void messageArrived(String topic, MqttMessage message) throws Exception {
49 | String detailedTopic = topic.substring(prefixLength);
50 | if (detailedTopic.indexOf("/") < 1) {
51 | logger.warn("Unable to deserialize event " + detailedTopic);
52 | return;
53 | }
54 | String className = detailedTopic.substring(0, detailedTopic.indexOf("/"));
55 | String procedurename = detailedTopic.substring(detailedTopic.indexOf("/") + 1);
56 | Event event = (Event)Class.forName(className).newInstance();
57 | event.setProcedure(Integer.parseInt(procedurename));
58 | //event.setType(type + typeSuffix);
59 | event.setData(message.toString());
60 | Kernel.getInstance().dispatchEvent(event);
61 | }
62 |
63 | @Override
64 | public void connectionLost(Throwable cause) {
65 | cause.printStackTrace();
66 | }
67 |
68 | @Override
69 | public void deliveryComplete(IMqttDeliveryToken token) {
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/mqtt/MqttSubscriberCallback.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.mqtt;
2 |
3 | import org.eclipse.paho.client.mqttv3.MqttClient;
4 |
5 | /**
6 | *
7 | * @author greg
8 | */
9 | public interface MqttSubscriberCallback {
10 | public void setClient(MqttClient client);
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/BodyContent.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.openapi;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public class BodyContent {
8 |
9 | private String name;
10 | private Schema schema;
11 |
12 | public BodyContent(String name, Schema schema) {
13 | this.name = name;
14 | this.schema = schema;
15 | }
16 |
17 | /**
18 | * @return the name
19 | */
20 | public String getName() {
21 | return name;
22 | }
23 |
24 | /**
25 | * @return the schema
26 | */
27 | public Schema getSchema() {
28 | return schema;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/Content.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class Content {
23 |
24 | private String name;
25 | private Object object;
26 |
27 | public Content(String name) {
28 | this.name = name;
29 | }
30 |
31 | /**
32 | * @return the name
33 | */
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | /**
39 | * @param name the name to set
40 | */
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | /**
46 | * @return the object
47 | */
48 | public Object getObject() {
49 | return object;
50 | }
51 |
52 | /**
53 | * @param object the object to set
54 | */
55 | public void setObject(Object object) {
56 | this.object = object;
57 | }
58 |
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/Element.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class Element {
23 | protected String indentStep=" ";
24 | protected String lf="\r\n";
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/OpenApiIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.openapi;
2 |
3 | import org.cricketmsf.Kernel;
4 |
5 | /**
6 | *
7 | * @author greg
8 | */
9 | public interface OpenApiIface {
10 |
11 | public void init(Kernel service);
12 | public String toJson();
13 | public String toYaml();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/Parameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class Parameter extends Element{
23 |
24 | private String name;
25 | private ParameterLocation in;
26 | private String description;
27 | private boolean required;
28 | private Schema schema;
29 |
30 | public Parameter(String name, ParameterLocation in, boolean required, String description) {
31 | this(name,in,required,description,new Schema());
32 | }
33 |
34 | public Parameter(String name, ParameterLocation in, boolean required, String description, Schema schema) {
35 | this.name = name;
36 | this.in = in;
37 | if (in == ParameterLocation.path) {
38 | this.required = true;
39 | } else {
40 | this.required = required;
41 | }
42 | this.description = description;
43 | this.schema = schema;
44 | }
45 |
46 | /**
47 | * @return the name
48 | */
49 | public String getName() {
50 | return name;
51 | }
52 |
53 | /**
54 | * @return the in
55 | */
56 | public ParameterLocation getIn() {
57 | return in;
58 | }
59 |
60 | /**
61 | * @return the description
62 | */
63 | public String getDescription() {
64 | return description;
65 | }
66 |
67 | /**
68 | * @return the required
69 | */
70 | public boolean isRequired() {
71 | return required;
72 | }
73 |
74 | public String toYaml(String indent) {
75 | StringBuilder sb = new StringBuilder();
76 | sb.append(indent).append("in: ").append(getIn().name()).append(lf);
77 | sb.append(indent).append("description: \"").append(getDescription()).append("\"").append(lf);
78 | sb.append(indent).append("required: ").append(isRequired()).append(lf);
79 | //sb.append(indent).append("schema:").append(lf);
80 | sb.append(schema.toYaml(indent));
81 | return sb.toString();
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/ParameterLocation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public enum ParameterLocation {
23 | path,
24 | query,
25 | header,
26 | cookie
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/RequestBody.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | import java.util.HashMap;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class RequestBody {
25 | private String description;
26 | private boolean required = false;
27 | private HashMap content;
28 |
29 | public RequestBody(BodyContent content, boolean required, String description){
30 | this.content=new HashMap<>();
31 | this.content.put(content.getName(), content);
32 | this.description=description;
33 | this.required=required;
34 | }
35 |
36 | public RequestBody content(BodyContent content){
37 | this.getContent().put(content.getName(), content);
38 | return this;
39 | }
40 |
41 |
42 | /**
43 | * @return the description
44 | */
45 | public String getDescription() {
46 | return description;
47 | }
48 |
49 | /**
50 | * @return the required
51 | */
52 | public boolean isRequired() {
53 | return required;
54 | }
55 |
56 | /**
57 | * @return the content
58 | */
59 | public HashMap getContent() {
60 | return content;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/Response.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | import java.util.ArrayList;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class Response extends Element{
25 |
26 | String codeName;
27 | private String description;
28 | private ArrayList content;
29 |
30 | public Response(String codeName) {
31 | this.codeName = codeName;
32 | description = "";
33 | content = new ArrayList<>();
34 | }
35 |
36 | public Response description(String description) {
37 | this.description = description;
38 | return this;
39 | }
40 |
41 | public Response content(Content content) {
42 | this.content.add(content);
43 | return this;
44 | }
45 |
46 | public Response content(String content) {
47 | this.content.add(new Content(content));
48 | return this;
49 | }
50 |
51 | /**
52 | * @return the description
53 | */
54 | public String getDescription() {
55 | return description;
56 | }
57 |
58 | /**
59 | * @param description the description to set
60 | */
61 | public void setDescription(String description) {
62 | this.description = description;
63 | }
64 |
65 | public String toYaml(String indent) {
66 | StringBuilder sb = new StringBuilder();
67 | sb.append(indent).append(codeName).append(":").append(lf);
68 | if (null != description) {
69 | sb.append(indent).append(indentStep).append("description: \"").append(getDescription()).append("\"").append(lf);
70 | }
71 | if (content.size() > 0) {
72 | sb.append(indent).append(indentStep).append("content:").append(lf);
73 | content.forEach(cnt -> {
74 | sb.append(indent).append(indentStep).append(indentStep).append("\"").append(cnt.getName()).append("\":").append(" {}").append(lf);
75 | });
76 | }
77 |
78 | return sb.toString();
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/SchemaFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public enum SchemaFormat {
23 | int32,
24 | int64,
25 | _float,
26 | _double,
27 | _byte,
28 | binary,
29 | _date,
30 | _date_time,
31 | password;
32 |
33 | @Override
34 | public String toString() {
35 | String result = name();
36 | if (result.startsWith("_")) {
37 | result = result.substring(1);
38 | }
39 | if(result.indexOf("_")>0){
40 | result=result.replaceFirst("_", "-");
41 | }
42 | return result;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/SchemaProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class SchemaProperty {
23 |
24 | private final String name;
25 | private final SchemaType type;
26 | private final String format;
27 | private final String description;
28 |
29 | public SchemaProperty(String name, SchemaType type, String format, String description) {
30 | this.name = name;
31 | this.type = type;
32 | this.format = format;
33 | this.description = description;
34 | }
35 |
36 | /**
37 | * @return the name
38 | */
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | /**
44 | * @return the type
45 | */
46 | public SchemaType getType() {
47 | return type;
48 | }
49 |
50 | /**
51 | * @return the description
52 | */
53 | public String getDescription() {
54 | return description;
55 | }
56 |
57 | /**
58 | * @return the format
59 | */
60 | public String getFormat() {
61 | return format;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/SchemaType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public enum SchemaType {
23 | string,
24 | integer,
25 | number,
26 | array,
27 | _boolean,
28 | object;
29 |
30 | @Override
31 | public String toString() {
32 | String result = name();
33 | if (result.startsWith("_")) {
34 | result = result.substring(1);
35 | }
36 | if (result.indexOf("_") > 0) {
37 | result = result.replaceFirst("_", "-");
38 | }
39 | return result;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/openapi/Server.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.openapi;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class Server extends Element {
23 |
24 | private String url = null;
25 | private String description = null;
26 |
27 | public Server(String url) {
28 | this.url = url;
29 | }
30 |
31 | Server description (String description) {
32 | this.description = description;
33 | return this;
34 | }
35 |
36 | public String toYaml(String indent) {
37 | StringBuilder sb = new StringBuilder();
38 | sb.append(indent).append("- url: \"").append(this.getUrl()).append("\"").append(lf);
39 | if (null != description) {
40 | sb.append(indent+indentStep).append("description: ").append(this.description).append(lf);
41 | }
42 | return sb.toString();
43 | }
44 |
45 | /**
46 | * @return the url
47 | */
48 | public String getUrl() {
49 | return url;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/quartz/QuartzJob.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.quartz;
2 |
3 | import java.util.HashMap;
4 | import org.cricketmsf.event.Event;
5 | import org.quartz.Job;
6 | import org.quartz.JobExecutionContext;
7 | import org.quartz.JobExecutionException;
8 |
9 | public class QuartzJob extends Event implements Job {
10 |
11 | private HashMap data;
12 |
13 | public QuartzJob(){
14 | super();
15 | data=new HashMap<>();
16 | }
17 |
18 | public HashMap getData(){
19 | return data;
20 | }
21 |
22 | @Override
23 | public void execute(JobExecutionContext context)
24 | throws JobExecutionException {
25 | System.out.println("Dummy Quartz Job");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/quartz/QuartzSchedulerIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.quartz;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public interface QuartzSchedulerIface {
8 |
9 | public boolean handleJob(QuartzJob job);
10 | public void clearJobs();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/scheduler/SchedulerIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.scheduler;
17 |
18 | import org.cricketmsf.event.Event;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public interface SchedulerIface {
25 |
26 | public boolean handleEvent(Event event);
27 | public boolean handleEvent(Event event, boolean restored, boolean systemStart);
28 | //public boolean forceHandleEvent(Event event);
29 | public boolean isRestored();
30 | public long getThreadsCount();
31 | public boolean isScheduled(String eventID);
32 | public String getProperty(String name);
33 | public void initScheduledTasks();
34 | public void reschedule(String className, int procedure, Long newDelay);
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/in/websocket/ClientList.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.in.websocket;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | /**
7 | *
8 | * @author greg
9 | */
10 | public class ClientList extends ArrayList {
11 |
12 | HashMap properties;
13 |
14 | public ClientList(HashMap properties){
15 | this.properties=properties;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/auth/AuthorizationFilterResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.auth;
17 |
18 | import org.cricketmsf.microsite.out.auth.Token;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class AuthorizationFilterResult {
25 | public int code = 200;
26 | public String message = "";
27 | public Token token;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/event/auth/AuthEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.event.auth;
17 |
18 | import java.util.HashMap;
19 | import org.cricketmsf.event.Event;
20 |
21 | /**
22 | *
23 | * @author greg
24 | */
25 | public class AuthEvent extends Event {
26 |
27 | HashMap data;
28 |
29 | public AuthEvent() {
30 | super();
31 | data=new HashMap<>();
32 | }
33 |
34 | public AuthEvent(String login, String password, String token) {
35 | super();
36 | data=new HashMap<>();
37 | data.put("login",login);
38 | data.put("password", password);
39 | data.put("token", token);
40 | }
41 |
42 | @Override
43 | public HashMap getData(){
44 | return data;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/event/cms/CmsEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.event.cms;
17 |
18 | import org.cricketmsf.event.Event;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class CmsEvent extends Event {
25 |
26 | Object data;
27 |
28 | public CmsEvent(){
29 |
30 | }
31 |
32 | public CmsEvent(Object data) {
33 | super();
34 | this.data = data;
35 | }
36 |
37 | @Override
38 | public Object getData() {
39 | return data;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/event/user/UserEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.event.user;
17 |
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import org.cricketmsf.event.Event;
21 | import org.cricketmsf.microsite.out.user.User;
22 |
23 | /**
24 | *
25 | * @author greg
26 | */
27 | public class UserEvent extends Event {
28 |
29 | Object data;
30 |
31 | public UserEvent() {
32 | super();
33 | }
34 |
35 | public UserEvent(String token) {
36 | super();
37 | data = token;
38 | }
39 |
40 | public UserEvent(Long number) {
41 | super();
42 | data = number;
43 | }
44 |
45 | public UserEvent(User user) {
46 | super();
47 | this.data = user;
48 | }
49 |
50 | public UserEvent(String uid, String requesterID, Long userNumber, String requesterRoles) {
51 | super();
52 | try {
53 | HashMap map = new HashMap();
54 | map.put("uid", uid);
55 | map.put("requester", requesterID);
56 | map.put("userNumber", userNumber);
57 | map.put("roles", requesterRoles);
58 | data = map;
59 | } catch (NullPointerException ex) {
60 | ex.printStackTrace();
61 | }
62 | }
63 |
64 | public UserEvent(User user, String requesterID, String requesterRoles) {
65 | super();
66 | HashMap map = new HashMap();
67 | map.put("user", user);
68 | map.put("requester", requesterID);
69 | map.put("roles", requesterRoles);
70 | data = map;
71 | }
72 |
73 | public UserEvent(String uid, String requesterID, String requesterRoles) {
74 | super();
75 | HashMap map = new HashMap();
76 | map.put("uid", uid);
77 | map.put("requester", requesterID);
78 | map.put("roles", requesterRoles);
79 | data = map;
80 | }
81 |
82 | public UserEvent(String uid, Long userNumber) {
83 | super();
84 | HashMap map = new HashMap();
85 | map.put("uid", uid);
86 | map.put("number", userNumber);
87 | data = map;
88 | }
89 |
90 | @Override
91 | public Object getData() {
92 | return data;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/in/siteadmin/SiteAdminApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.in.siteadmin;
17 |
18 | import java.util.Base64;
19 | import java.util.HashMap;
20 | import org.cricketmsf.RequestObject;
21 | import org.cricketmsf.event.Procedures;
22 | import org.cricketmsf.event.ProcedureCall;
23 | import org.cricketmsf.in.http.HttpPortedAdapter;
24 | import org.cricketmsf.api.ResponseCode;
25 | import org.cricketmsf.api.ResultIface;
26 | import org.cricketmsf.api.StandardResult;
27 | import org.cricketmsf.event.Event;
28 | import org.cricketmsf.microsite.event.auth.AuthEvent;
29 | import org.slf4j.Logger;
30 | import org.slf4j.LoggerFactory;
31 |
32 | /**
33 | *
34 | * @author Grzegorz Skorupa
35 | */
36 | public class SiteAdminApi extends HttpPortedAdapter {
37 |
38 | private static final Logger logger = LoggerFactory.getLogger(SiteAdminApi.class);
39 |
40 | /**
41 | * This method is executed while adapter is instantiated during the service
42 | * start. It's used to configure the adapter according to the configuration.
43 | *
44 | * @param properties map of properties readed from the configuration file
45 | * @param adapterName name of the adapter set in the configuration file (can
46 | * be different from the interface and class name.
47 | */
48 | @Override
49 | public void loadProperties(HashMap properties, String adapterName) {
50 | super.loadProperties(properties, adapterName);
51 | //super.getServiceHooks(adapterName);
52 | setContext(properties.get("context"));
53 | logger.info("\tcontext=" + getContext());
54 | }
55 |
56 | @Override
57 | protected ProcedureCall preprocess(RequestObject request) {
58 | if ("post".equalsIgnoreCase(request.method)) {
59 | Event event=new Event();
60 | event.setData(request);
61 | return ProcedureCall.toForward(event, Procedures.SA_ANY);
62 | } else if ("get".equalsIgnoreCase(request.method)) {
63 | Event event=new Event();
64 | event.setData(request);
65 | return ProcedureCall.toForward(event, Procedures.SA_ANY);
66 | } else if ("options".equalsIgnoreCase(request.method)) {
67 | return ProcedureCall.toRespond(ResponseCode.OK, "");
68 | } else {
69 | return ProcedureCall.toRespond(ResponseCode.METHOD_NOT_ALLOWED, "");
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/auth/AuthException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.auth;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class AuthException extends Exception {
23 |
24 | public static int ACCESS_DENIED = 403;
25 | public static int UNAUTHORIZED = 1;
26 | public static int EXPIRED = 401;
27 |
28 | public static int HELPER_NOT_AVAILABLE = 100;
29 | public static int HELPER_EXCEPTION = 101;
30 |
31 | public static int UNKNOWN = 1000;
32 |
33 | private String message;
34 | private int code;
35 |
36 | public AuthException(int code){
37 | this.code = code;
38 | switch (code){
39 | case 1000:
40 | default:
41 | message = "unknown error";
42 | break;
43 | }
44 | }
45 |
46 | public AuthException(int code, String message){
47 | this.code = code;
48 | this.message = message;
49 | }
50 |
51 | public String getMessage(){
52 | return message;
53 | }
54 |
55 | public int getCode(){
56 | return code;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/auth/UserProxy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) Grzegorz Skorupa 2021
3 | * Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
4 | */
5 | package org.cricketmsf.microsite.out.auth;
6 |
7 | import java.util.Arrays;
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * @author greg
13 | */
14 | public class UserProxy {
15 |
16 | private String uid;
17 | private String role;
18 |
19 | public UserProxy() {
20 | role = "";
21 | }
22 |
23 | public UserProxy(String uid, String role) {
24 | setUid(uid);
25 | setRole(role);
26 | }
27 |
28 | /**
29 | * @return the uid
30 | */
31 | public String getUid() {
32 | return uid;
33 | }
34 |
35 | /**
36 | * @param uid the uid to set
37 | */
38 | public void setUid(String uid) {
39 | this.uid = uid;
40 | }
41 |
42 | public String getRole() {
43 | return null != role ? role : "";
44 | }
45 |
46 | public List getRoles() {
47 | return Arrays.asList(getRole().split(","));
48 | }
49 |
50 | public boolean hasRole(String role) {
51 | return getRoles().contains(role);
52 | }
53 |
54 | /**
55 | * @param role the role to set
56 | */
57 | public void setRole(String role) {
58 | if (null == role) {
59 | role = "";
60 | } else {
61 | this.role = role.toLowerCase();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/CmsException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class CmsException extends Exception {
23 |
24 | public static int UNSUPPORTED_DB_ADAPTER = 0;
25 | public static int UNSUPPORTED_FILE_ADAPTER = 1;
26 | public static int UNSUPPORTED_LOGGER_ADAPTER = 2;
27 | public static int NOT_INITIALIZED = 3;
28 |
29 | public static int UNSUPPORTED_STATUS = 10;
30 | public static int UNSUPPORTED_LANGUAGE = 11;
31 | public static int MALFORMED_UID = 12;
32 |
33 | public static int HELPER_EXCEPTION = 20;
34 |
35 | public static int NOT_FOUND = 404;
36 | public static int ALREADY_EXISTS = 409;
37 |
38 | public static int LANGUAGE_NOT_SUPPORTED = 600;
39 | public static int TRANSLATION_NOT_POSSIBLE = 601;
40 | public static int TRANSLATION_NOT_CONFIGURED = 603;
41 |
42 | public static int UNKNOWN = 1000;
43 |
44 | private String message;
45 | private int code;
46 |
47 | public CmsException(int code){
48 | this.code = code;
49 | switch (code){
50 | case 1000:
51 | default:
52 | message = "unknown error";
53 | break;
54 | }
55 | }
56 |
57 | public CmsException(int code, String message){
58 | this.code = code;
59 | this.message = message;
60 | }
61 |
62 | public String getMessage(){
63 | return message;
64 | }
65 |
66 | public int getCode(){
67 | return code;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/CmsIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import java.io.File;
19 | import java.util.List;
20 | import java.util.Map;
21 | import org.cricketmsf.RequestObject;
22 | import org.cricketmsf.api.Result;
23 | import org.cricketmsf.api.ResultIface;
24 | import org.cricketmsf.out.db.KeyValueDBIface;
25 |
26 | /**
27 | *
28 | * @author greg
29 | */
30 | public interface CmsIface {
31 | public void destroy() throws CmsException;
32 |
33 | public List getPaths() throws CmsException;
34 | public List getTags() throws CmsException;
35 | public Document getDocument(String uid, String language) throws CmsException;
36 | public Document getDocument(String uid, String language, String status, Listroles) throws CmsException;
37 | public void addDocument(Document doc, Listroles) throws CmsException;
38 | public void addDocument(Map parameters, String userID, Listroles) throws CmsException;
39 | public void updateDocument(Document doc, Listroles) throws CmsException;
40 | public void updateDocument(String uid, String language, Map parameters, Listroles) throws CmsException;
41 | public void removeDocument(String uid, Listroles) throws CmsException;
42 | //public List findByPath(String path, String language, String status) throws CmsException;
43 | public List findByPathAndTag(String path, String tag, String language, String status, Listroles) throws CmsException;
44 | public List getComments(String uid) throws CmsException;
45 | public void addComment(String documentUid, Comment comment) throws CmsException;
46 | public void acceptComment(String documentUid, String commentUid) throws CmsException;
47 | public void removeComment(String documentUid, String commentUid) throws CmsException;
48 | //public Result getFile(String uid, String language) throws CmsException;
49 | public ResultIface getFile(RequestObject request, KeyValueDBIface cache, String tableName, String language);
50 | public ResultIface getFile(RequestObject request, KeyValueDBIface cache, String tableName, String language, boolean updateCache);
51 | public byte[] readFile(File file);
52 | public void updateCache(RequestObject request, KeyValueDBIface cache, String tableName, String language, String fileContent);
53 | public String getDefaultLanguage();
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/Comment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import java.util.Date;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class Comment {
25 | String uid;
26 | String documentUid;
27 | String text;
28 | Date created;
29 | boolean accepted;
30 | String authorUid;
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/DeeplTranslator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import org.cricketmsf.microsite.out.cms.TranslatorIface;
19 | import java.util.HashMap;
20 | import org.cricketmsf.Adapter;
21 | import org.cricketmsf.out.OutboundAdapter;
22 |
23 | /**
24 | *
25 | * @author greg
26 | */
27 | public class DeeplTranslator extends OutboundAdapter implements TranslatorIface, Adapter {
28 |
29 | @Override
30 | public void loadProperties(HashMap properties, String adapterName) {
31 | super.loadProperties(properties, adapterName);
32 | }
33 |
34 | @Override
35 | public Document translate(Document doc, String targetLanguage) throws CmsException {
36 | throw new CmsException(CmsException.TRANSLATION_NOT_CONFIGURED, "service not configured");
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/DefaultRuleEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import java.util.ArrayList;
19 | import java.util.HashMap;
20 | import java.util.List;
21 | import org.cricketmsf.Adapter;
22 | import org.cricketmsf.out.OutboundAdapter;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | /**
27 | *
28 | * @author Grzegorz Skorupa
29 | */
30 | public class DefaultRuleEngine extends OutboundAdapter implements Adapter, RuleEngineIface {
31 | private static final Logger logger = LoggerFactory.getLogger(DefaultRuleEngine.class);
32 | public DefaultRuleEngine() {
33 | }
34 |
35 | @Override
36 | public void loadProperties(HashMap properties, String adapterName) {
37 | super.loadProperties(properties, adapterName);
38 | logger.info("\tadapter-class: " + this.getClass().getName());
39 | }
40 |
41 | @Override
42 | public Document processDocument(Document doc, List roles) {
43 | if (doc == null) {
44 | return null;
45 | }
46 | if (roles == null) {
47 | return doc.setRights(Document.READONLY);
48 | }
49 | if (roles.contains("redactor") || roles.contains("redactor." + doc.getLanguage())) {
50 | return doc.setRights(Document.READWRITE);
51 | } else {
52 | return doc.setRights(Document.READONLY);
53 | }
54 | }
55 |
56 | @Override
57 | public ArrayList processDocumentsList(List documents, List roles) {
58 | ArrayList result = new ArrayList<>();
59 | if(documents!=null){
60 | for (Document document : documents) {
61 | if (null != roles && (roles.contains("redactor") || roles.contains("redactor." + document.getLanguage()))) {
62 | result.add(document.setRights(Document.READWRITE));
63 | } else {
64 | result.add(document.setRights(Document.READONLY));
65 | }
66 | }}
67 | return result;
68 | }
69 |
70 | @Override
71 | public void checkDocument(Document doc, List roles) throws CmsException {
72 | if (!(roles.contains("redactor") || roles.contains("redactor." + doc.getLanguage()))) {
73 | throw new CmsException(CmsException.HELPER_EXCEPTION, "not authorized");
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/DocumentPathAndTagComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import java.util.Arrays;
19 | import java.util.HashSet;
20 | import java.util.Set;
21 | import org.cricketmsf.out.db.ComparatorIface;
22 |
23 | /**
24 | *
25 | * @author Grzegorz Skorupa
26 | */
27 | public class DocumentPathAndTagComparator implements ComparatorIface {
28 |
29 | @Override
30 | public int compare(Object source, Object pattern) {
31 | try {
32 | Document s = (Document) source;
33 | Document p = (Document) pattern;
34 | String path = p.getPath();
35 | if (!path.isEmpty()) {
36 | if (!path.equals(s.getPath())) {
37 | return 1;
38 | }
39 | }
40 | if (!p.getTags().isEmpty()) {
41 | Set patternSet = new HashSet(Arrays.asList(p.tagsAsArray()));
42 | Set sourceSet = new HashSet(Arrays.asList(s.tagsAsArray()));
43 | sourceSet.retainAll(patternSet);
44 | if (sourceSet.isEmpty()) {
45 | return 1;
46 | }
47 | }
48 | return 0;
49 | } catch (ClassCastException e) {
50 | e.printStackTrace();
51 | return -1;
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/RuleEngineIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | *
22 | * @author Grzegorz Skorupa
23 | */
24 | public interface RuleEngineIface {
25 | public Document processDocument(Document doc, Listroles);
26 | public List processDocumentsList(Listdocuments, Listroles);
27 | public void checkDocument(Document doc, Listroles) throws CmsException;
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/cms/TranslatorIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.cms;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface TranslatorIface {
23 |
24 | public Document translate(Document doc, String targetLanguage) throws CmsException;
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/notification/EmailSenderIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.notification;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface EmailSenderIface {
23 |
24 | public String send(String recipient, String subject, String text);
25 | public String send(String to, String cc, String bcc, String subject, String text);
26 | public String send(String[] recipients, String[] names, String subject, String text);
27 | }
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/siteadmin/SiteAdministrationIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.siteadmin;
17 |
18 | import org.cricketmsf.api.StandardResult;
19 | import org.cricketmsf.microsite.out.user.UserAdapterIface;
20 | import org.cricketmsf.out.db.KeyValueDBIface;
21 |
22 | /**
23 | *
24 | * @author greg
25 | */
26 | public interface SiteAdministrationIface {
27 |
28 | public void initDatabases(
29 | KeyValueDBIface database,
30 | KeyValueDBIface userDB,
31 | KeyValueDBIface authDB
32 | );
33 |
34 | public void backupDatabases(
35 | KeyValueDBIface database,
36 | KeyValueDBIface userDB,
37 | KeyValueDBIface authDB,
38 | KeyValueDBIface cmsDB,
39 | String errorLevel
40 | );
41 |
42 | public void clearUserData(String userId);
43 |
44 | public void clearData(
45 | boolean demoMode,
46 | String category,
47 | String type,
48 | UserAdapterIface userAdapter,
49 | KeyValueDBIface database);
50 |
51 | public StandardResult getServiceInfo();
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/user/HashMaker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.user;
17 |
18 | import java.io.UnsupportedEncodingException;
19 | import java.security.MessageDigest;
20 | import java.security.NoSuchAlgorithmException;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | /**
25 | *
26 | * @author grzesk
27 | */
28 |
29 |
30 | public class HashMaker {
31 | private static final Logger logger = LoggerFactory.getLogger(HashMaker.class);
32 | public static void main(String args[]){
33 | System.out.println(HashMaker.md5Java(args[0]));
34 | }
35 |
36 | public static String md5Java(String message) {
37 | String digest = null;
38 | try {
39 | MessageDigest md = MessageDigest.getInstance("MD5");
40 | byte[] hash = md.digest(message.getBytes("UTF-8"));
41 | //converting byte array to Hexadecimal String
42 | StringBuilder sb = new StringBuilder(2 * hash.length);
43 | for (byte b : hash) {
44 | sb.append(String.format("%02x", b & 0xff));
45 | }
46 | digest = sb.toString();
47 | } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
48 | logger.error(ex.getMessage());
49 | }
50 | return digest;
51 |
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/user/UserAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.user;
17 |
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 | import org.cricketmsf.api.Result;
22 |
23 | /**
24 | *
25 | * @author greg
26 | */
27 | public interface UserAdapterIface {
28 | public Result handleGet(HashMap params);
29 | public Result handleRegisterUser(User newUser);
30 | public Result handleUpdateUser(HashMap params);
31 | public Result handleDeleteUser(HashMap params);
32 |
33 | public User get(String uid) throws UserException;
34 | public User getByNumber(long number) throws UserException;
35 | public Map getAll() throws UserException;
36 | public User register(User user) throws UserException;
37 | public void modify(User user) throws UserException;
38 | public void confirmRegistration(String uid) throws UserException;
39 | //public void unregister(String uid) throws UserException;
40 | public void remove(String uid) throws UserException;
41 | public boolean checkPassword(String uid, String password) throws UserException;
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/microsite/out/user/UserException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.microsite.out.user;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class UserException extends Exception {
23 |
24 | public static int USER_ALREADY_EXISTS = 0;
25 | public static int UNKNOWN_USER = 1;
26 |
27 | public static int HELPER_NOT_AVAILABLE = 100;
28 | public static int HELPER_EXCEPTION = 101;
29 |
30 | public static int UNKNOWN = 1000;
31 |
32 | private String message;
33 | private int code;
34 |
35 | public UserException(int code){
36 | this.code = code;
37 | switch (code){
38 | case 1000:
39 | default:
40 | message = "unknown error";
41 | break;
42 | }
43 | }
44 |
45 | public UserException(int code, String message){
46 | this.code = code;
47 | this.message = message;
48 | }
49 |
50 | public String getMessage(){
51 | return message;
52 | }
53 |
54 | public int getCode(){
55 | return code;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/OutboundAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out;
17 |
18 | import org.cricketmsf.out.dispatcher.DispatcherIface;
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public class OutboundAdapter implements OutboundAdapterIface {
27 |
28 | protected HashMap statusMap = null;
29 | public HashMap properties;
30 | protected String name;
31 |
32 | public OutboundAdapter() {
33 | }
34 |
35 | public void destroy() {
36 | }
37 |
38 | public void loadProperties(HashMap properties, String adapterName) {
39 | this.name = adapterName;
40 | this.properties = (HashMap) properties.clone();
41 | getStatus(adapterName); //required if we need to overwrite updateStatusItem() method
42 | }
43 |
44 | @Override
45 | public Map getStatus(String name) {
46 | if (statusMap == null) {
47 | statusMap = new HashMap();
48 | statusMap.put("name", name);
49 | statusMap.put("class", getClass().getName());
50 | statusMap.put("properties", properties);
51 | }
52 | return statusMap;
53 | }
54 |
55 | public void updateStatusItem(String key, String value) {
56 | statusMap.put(key, value);
57 | }
58 |
59 | @Override
60 | public String getProperty(String name) {
61 | return properties.get(name);
62 | }
63 |
64 | @Override
65 | public String setProperty(String name, String value){
66 | return properties.put(name, value);
67 | }
68 |
69 | public DispatcherIface getDispatcher() {
70 | return null;
71 | }
72 |
73 | @Override
74 | public String getName() {
75 | return name;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/OutboundAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out;
17 |
18 | import java.util.Map;
19 |
20 | /**
21 | *
22 | * @author Grzegorz Skorupa
23 | */
24 | public interface OutboundAdapterIface {
25 | public String getProperty(String name);
26 | public String setProperty(String name, String value);
27 | public Map getStatus(String name);
28 | public String getName();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/archiver/ZipArchiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Grzegorz Skorupa.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.archiver;
17 |
18 | import java.io.File;
19 | import java.io.FileOutputStream;
20 | import java.io.IOException;
21 | import java.nio.file.Files;
22 | import java.nio.file.Path;
23 | import java.util.zip.ZipEntry;
24 | import java.util.zip.ZipOutputStream;
25 | import org.slf4j.LoggerFactory;
26 |
27 | /**
28 | *
29 | * @author greg
30 | */
31 | public class ZipArchiver {
32 |
33 | private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ZipArchiver.class);
34 |
35 | Path filePath;
36 | private ZipOutputStream out;
37 | private File file;
38 |
39 | public ZipArchiver(String prefix, String suffix) throws IOException {
40 | filePath = Files.createTempFile(prefix, suffix);
41 | file = filePath.toFile();
42 | out = new ZipOutputStream(new FileOutputStream(file));
43 | }
44 |
45 | public void addFileContent(String fileName, String fileContent) throws IOException {
46 | ZipEntry e = new ZipEntry(fileName);
47 | out.putNextEntry(e);
48 | byte[] data = fileContent.getBytes();
49 | out.write(data, 0, data.length);
50 | out.closeEntry();
51 | }
52 |
53 | public void addFile(String fileName, byte[] fileContent) throws IOException {
54 | ZipEntry e = new ZipEntry(fileName);
55 | out.putNextEntry(e);
56 | out.write(fileContent, 0, fileContent.length);
57 | out.closeEntry();
58 | }
59 |
60 | public File getFile() throws IOException {
61 | out.close();
62 | return file;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/auth/AuthAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.auth;
17 |
18 | import org.cricketmsf.microsite.out.auth.AuthException;
19 | import org.cricketmsf.microsite.out.auth.Token;
20 | import org.cricketmsf.microsite.out.auth.UserProxy;
21 | import org.cricketmsf.microsite.out.user.User;
22 |
23 | /**
24 | *
25 | * @author greg
26 | */
27 | public interface AuthAdapterIface {
28 |
29 | public Token login(String login, String password);
30 |
31 | public boolean checkToken(String tokenID);
32 |
33 | public boolean logout(String tokenID);
34 |
35 | public boolean refreshToken(String tokenID);
36 |
37 | public void userAuthorize(String userId, String role) throws AuthException;
38 |
39 | public void cmsAuthorize(String docId, String role) throws AuthException;
40 |
41 | public Token createToken(UserProxy user) throws AuthException;
42 |
43 | public Token createConfirmationToken(User user, String token, long timeout) throws AuthException;
44 |
45 | public Token createPermanentToken(UserProxy user, UserProxy issuer, boolean neverExpires, String payload) throws AuthException;
46 |
47 | public Token getToken(String tokenID);
48 |
49 | /**
50 | * Removes permanent token from database
51 | *
52 | * @param tokenID token identifier
53 | * @throws AuthException TODO doc
54 | */
55 | public void removePermanentToken(String tokenID) throws AuthException;
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/autostart/Autostart.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.autostart;
17 |
18 | import java.io.IOException;
19 | import java.nio.file.Files;
20 | import java.nio.file.Path;
21 | import java.nio.file.Paths;
22 | import java.util.HashMap;
23 | import org.cricketmsf.Adapter;
24 | import org.cricketmsf.exception.InitException;
25 | import org.cricketmsf.out.OutboundAdapter;
26 | import org.cricketmsf.out.OutboundAdapterIface;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | public class Autostart extends OutboundAdapter implements OutboundAdapterIface, Adapter, AutostartIface {
31 | private static final Logger logger = LoggerFactory.getLogger(Autostart.class);
32 |
33 | HashMap properties;
34 | String[] paths;
35 |
36 | @Override
37 | public String getProperty(String name) {
38 | return properties.get(name);
39 | }
40 |
41 | @Override
42 | public void loadProperties(HashMap properties, String adapterName) {
43 | String pathNames = properties.getOrDefault("subfolders", "");
44 | logger.info("\tsubfolders: " + pathNames);
45 | paths = pathNames.split(":");
46 | }
47 |
48 | @Override
49 | public void execute() throws InitException {
50 | Path path;
51 | for (int i = 0; i < paths.length; i++) {
52 | path = Paths.get(paths[i]);
53 | if (!Files.exists(path)) {
54 | try {
55 | Files.createDirectories(path);
56 | } catch (IOException e) {
57 | throw new InitException(1, "unable to create directory: "+paths[i]);
58 | }
59 | } else {
60 | if (!Files.isDirectory(path)) {
61 | throw new InitException(1, "not a directory: "+paths[i]);
62 | } else {
63 | if (!Files.isWritable(path)) {
64 | throw new InitException(1, "read-only directory: "+paths[i]);
65 | }
66 | }
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/autostart/AutostartIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.autostart;
17 |
18 | import org.cricketmsf.exception.InitException;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public interface AutostartIface {
25 | public void execute() throws InitException;
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/ComparatorIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface ComparatorIface {
23 |
24 | public int compare(Object storedObject, Object pattern);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/DBException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class DBException extends Exception {
23 |
24 | public static int UNKNOWN = 999;
25 | public static int CANNOT_CREATE = 1;
26 | public static int CANNOT_DELETE = 2;
27 | public static int TABLE_NOT_EXISTS = 3;
28 | public static int CANNOT_WRITE = 4;
29 | public static int CANNOT_RESTORE = 5;
30 | public static int NOT_SUPPORTED = 6;
31 | public static int NOT_IMPLEMENTED = 7;
32 |
33 | private int code = UNKNOWN;
34 | private String message;
35 |
36 | public DBException(int code){
37 | this.code = code;
38 | switch (code){
39 | case 1:
40 | message = "unable to create table";
41 | break;
42 | case 2:
43 | message = "unable to delete key";
44 | break;
45 | case 3:
46 | message = "table does not exists";
47 | break;
48 | case 999:
49 | message = "unknown error";
50 | break;
51 | }
52 | }
53 |
54 | public DBException(int code, String message){
55 | this.code = code;
56 | this.message = message;
57 | }
58 |
59 | public String getMessage(){
60 | return message;
61 | }
62 |
63 | public int getCode(){
64 | return code;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/KeyValueCacheAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | import java.util.List;
19 | import java.util.Map;
20 | import org.cricketmsf.out.db.ComparatorIface;
21 |
22 | /**
23 | *
24 | * @author greg
25 | */
26 | public interface KeyValueCacheAdapterIface {
27 |
28 | public void start();
29 | public void put(Object key, Object value);
30 | public Object get(Object key);
31 | public Object get(Object key, Object defaultValue);
32 | public Map getAll();
33 | public List search(ComparatorIface comparator, Object pattern);
34 | public boolean containsKey(Object key);
35 | public boolean remove(Object key);
36 | public void clear();
37 | public long getSize();
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/KeyValueDBException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public class KeyValueDBException extends DBException {
23 |
24 | public static int UNKNOWN = 999;
25 | public static int CANNOT_CREATE = 1;
26 | public static int CANNOT_DELETE = 2;
27 | public static int TABLE_NOT_EXISTS = 3;
28 | public static int CANNOT_WRITE = 4;
29 | public static int CANNOT_RESTORE = 5;
30 | public static int NOT_SUPPORTED = 6;
31 | public static int NOT_IMPLEMENTED = 7;
32 | public static int TABLE_EXISTS = 9;
33 | public static int NOT_INITIALIZED = 10;
34 |
35 | private int code = UNKNOWN;
36 | private String message;
37 |
38 | public KeyValueDBException(int code){
39 | super(code);
40 | }
41 |
42 | public KeyValueDBException(int code, String message){
43 | super(code, message);
44 | }
45 |
46 | /*public KeyValueDBException(int code){
47 | this.code = code;
48 | switch (code){
49 | case 1:
50 | message = "unable to create table";
51 | break;
52 | case 2:
53 | message = "unable to delete key";
54 | break;
55 | case 3:
56 | message = "table does not exists";
57 | break;
58 | case 999:
59 | message = "unknown error";
60 | break;
61 | }
62 | }
63 |
64 | public KeyValueDBException(int code, String message){
65 | this.code = code;
66 | this.message = message;
67 | }
68 |
69 | public String getMessage(){
70 | return message;
71 | }
72 |
73 | public int getCode(){
74 | return code;
75 | }
76 |
77 | */
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/LimitedMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | import java.util.LinkedHashMap;
19 | import java.util.Map;
20 |
21 | /**
22 | *
23 | * @author greg
24 | */
25 | public class LimitedMap extends LinkedHashMap {
26 |
27 | private int maxSize = 0;
28 |
29 | @Override
30 | protected boolean removeEldestEntry(Map.Entry eldest) {
31 | return removeEldest(eldest);
32 | }
33 |
34 | private synchronized boolean removeEldest(Map.Entry eldest) {
35 | return maxSize > 0 ? size() > maxSize : false;
36 | }
37 |
38 | /**
39 | * @return the maxSize
40 | */
41 | public int getMaxSize() {
42 | return maxSize;
43 | }
44 |
45 | /**
46 | * @param maxSize the maxSize to set
47 | */
48 | public void setMaxSize(int maxSize) {
49 | this.maxSize = maxSize;
50 | }
51 |
52 | @Override
53 | public synchronized void clear() {
54 | super.clear();
55 | }
56 |
57 | @Override
58 | public Object clone() {
59 | LimitedMap result = (LimitedMap) super.clone();
60 | /*super.keySet().forEach( key -> {
61 | result.put(key, super.get(key));
62 | });*/
63 | return result;
64 | }
65 |
66 | public synchronized Object remove(String key) {
67 | return super.remove(key);
68 | }
69 |
70 | public synchronized void put(String key, Object value) {
71 | super.put(key, value);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/db/SqlDBIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.db;
17 |
18 | import java.io.File;
19 | import java.sql.Connection;
20 | import java.sql.SQLException;
21 | import java.util.List;
22 |
23 | /**
24 | *
25 | * @author Grzegorz Skorupa
26 | */
27 | public interface SqlDBIface extends KeyValueDBIface{
28 |
29 | /**
30 | * Creates database
31 | * @param conn database connection
32 | * @param version TODO doc
33 | */
34 | public void createDatabase(Connection conn, String version);
35 |
36 | /**
37 | * Gets new database connection from the connection pool
38 | * @return database connection
39 | * @throws SQLException TODO doc
40 | */
41 | public Connection getConnection() throws SQLException;
42 |
43 | /**
44 | * Get service database version name
45 | * @return version name
46 | */
47 | public String getVersion();
48 |
49 | /**
50 | * Returns list of objects matching the givens SQL statement and parameters
51 | * @param tableName the database table name
52 | * @param statement SQL prepared statement
53 | * @param parameters array of the statement parameters
54 | * @return list of objects matching the statement
55 | * @throws KeyValueDBException TODO doc
56 | */
57 | @Override
58 | public List search(String tableName, String statement, Object[] parameters) throws KeyValueDBException;
59 |
60 | /**
61 | * Executes database query
62 | *
63 | * @param query TODO doc
64 | * @return query result
65 | * @throws SQLException TODO doc
66 | */
67 | public List execute(String query) throws SQLException;
68 |
69 | public File getBackupFile();
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/dispatcher/DispatcherIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.dispatcher;
17 |
18 | import org.cricketmsf.exception.DispatcherException;
19 | import org.cricketmsf.event.Event;
20 |
21 | /**
22 | *
23 | * @author Grzegorz Skorupa
24 | */
25 | public interface DispatcherIface {
26 | public void dispatch(Event event) throws DispatcherException;
27 | public void registerEventTypes(String categories) throws DispatcherException;
28 | public String getName();
29 | public void start();
30 | public boolean isReady();
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/event/EventDispatcherIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.event;
17 |
18 | import org.cricketmsf.out.dispatcher.*;
19 | import org.cricketmsf.exception.DispatcherException;
20 | import org.cricketmsf.event.Event;
21 |
22 | /**
23 | *
24 | * @author Grzegorz Skorupa
25 | */
26 | public interface EventDispatcherIface {
27 | public void dispatch(Event event) throws DispatcherException;
28 | public void registerEventTypes(String categories) throws DispatcherException;
29 | public String getName();
30 | public void start();
31 | public boolean isReady();
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/file/CommandRunner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.file;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.IOException;
20 | import java.io.InputStreamReader;
21 | import java.util.HashMap;
22 | import org.cricketmsf.Adapter;
23 | import org.cricketmsf.Kernel;
24 | import org.cricketmsf.in.http.HttpPortedAdapter;
25 | import org.cricketmsf.out.OutboundAdapter;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | /**
30 | *
31 | * @author greg
32 | */
33 | public class CommandRunner extends OutboundAdapter implements Adapter, CommandRunnerIface {
34 | private static final Logger logger = LoggerFactory.getLogger(CommandRunner.class);
35 |
36 | private String command;
37 |
38 | /**
39 | * This method is executed while adapter is instantiated during the service
40 | * start. It's used to configure the adapter according to the configuration.
41 | *
42 | * @param properties map of properties readed from the configuration file
43 | * @param adapterName name of the adapter set in the configuration file (can
44 | * be different from the interface and class name.
45 | */
46 | @Override
47 | public void loadProperties(HashMap properties, String adapterName) {
48 | super.loadProperties(properties, adapterName);
49 | command = properties.getOrDefault("command", "");
50 | logger.info("\tcommand: " + command);
51 |
52 | }
53 |
54 | @Override
55 | public String execute() {
56 | try {
57 | Process p = Runtime.getRuntime().exec(command);
58 | p.waitFor();
59 | BufferedReader reader
60 | = new BufferedReader(new InputStreamReader(p.getInputStream()));
61 | String line;
62 | StringBuilder sb = new StringBuilder();
63 | while ((line = reader.readLine()) != null) {
64 | sb.append(line).append("\n");
65 | }
66 | return sb.toString();
67 | } catch (IOException | InterruptedException e) {
68 | return "";
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/file/CommandRunnerIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.file;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface CommandRunnerIface {
23 | public String execute();
24 | public String getProperty(String name);
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/file/FileObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.file;
17 |
18 | import java.util.Date;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class FileObject {
25 |
26 | public byte[] content;
27 | public Date modified;
28 | public String filePath;
29 | public String fileExtension;
30 | public String modifiedString;
31 | public String mimeType;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/file/FileReaderAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.file;
17 |
18 | import java.io.File;
19 | import java.io.FileNotFoundException;
20 | import java.io.IOException;
21 | import org.cricketmsf.RequestObject;
22 | import org.cricketmsf.out.db.KeyValueCacheAdapterIface;
23 | import org.cricketmsf.out.db.KeyValueDBIface;
24 | import org.cricketmsf.api.ResultIface;
25 |
26 | /**
27 | *
28 | * @author greg
29 | */
30 | public interface FileReaderAdapterIface {
31 |
32 | public byte[] readFile(File file) throws FileNotFoundException, IOException;
33 | public byte[] readFile(String filePath) throws FileNotFoundException, IOException;
34 | public String getFilePath(RequestObject request);
35 | public String getFileExt(String filePath);
36 | public byte[] getFileBytes(File file, String filePath);
37 | public ResultIface getFile(RequestObject request, KeyValueDBIface cache, String tableName);
38 | public String getRootPath();
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/log/LoggerAdapterIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.log;
17 |
18 | import org.cricketmsf.event.Event;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public interface LoggerAdapterIface {
25 |
26 | public void log(Event event);
27 | public void print(String message);
28 | public void printIndented(String message);
29 | public boolean isAvailable();
30 | public boolean isFineLevel();
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/mqtt/MqttPublisher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.mqtt;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttClient;
19 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
20 | import org.eclipse.paho.client.mqttv3.MqttException;
21 | import org.eclipse.paho.client.mqttv3.MqttMessage;
22 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
23 |
24 | /**
25 | *
26 | * @author Grzegorz Skorupa
27 | */
28 | public class MqttPublisher {
29 |
30 | public static void publish(String brokerURL, String clientID, int qos, boolean debug, String topic, String payload) throws MqttPublisherException {
31 | MemoryPersistence persistence = new MemoryPersistence();
32 | try {
33 | MqttClient sampleClient = new MqttClient(brokerURL, clientID, persistence);
34 | MqttConnectOptions connOpts = new MqttConnectOptions();
35 | connOpts.setCleanSession(true);
36 | sampleClient.connect(connOpts);
37 | MqttMessage message = new MqttMessage(payload.getBytes());
38 | message.setQos(qos);
39 | sampleClient.publish(topic, message);
40 | sampleClient.disconnect();
41 | } catch (MqttException me) {
42 | if(debug) me.printStackTrace();
43 | throw new MqttPublisherException(me.getReasonCode(), me.getMessage());
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/mqtt/MqttPublisherException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.mqtt;
17 |
18 | public class MqttPublisherException extends Exception {
19 |
20 | public static int UNKNOWN = 999;
21 | public static int NOT_IMPLEMENTED = 998;
22 |
23 | private int code = NOT_IMPLEMENTED;
24 | private String message;
25 |
26 | public MqttPublisherException(int code){
27 | this.code = code;
28 | switch (code){
29 | case 998:
30 | message = "operation not implemented";
31 | break;
32 | case 999:
33 | message = "unknown error";
34 | break;
35 | }
36 | }
37 |
38 | public MqttPublisherException(int code, String message){
39 | this.code = code;
40 | this.message = message;
41 | }
42 |
43 | public String getMessage(){
44 | return message;
45 | }
46 |
47 | public int getCode(){
48 | return code;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/mqtt/MqttPublisherIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.out.mqtt;
17 |
18 | /**
19 | *
20 | * @author Grzegorz Skorupa
21 | */
22 | public interface MqttPublisherIface {
23 |
24 | public void publish(String clientID, int qos, String topic, String message) throws MqttPublisherException;
25 | public void publish(int qos, String topic, String message) throws MqttPublisherException;
26 | public void publish(String topic, String message) throws MqttPublisherException;
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/out/websocket/WebsocketClientIface.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.out.websocket;
2 |
3 | /**
4 | *
5 | * @author greg
6 | */
7 | public interface WebsocketClientIface {
8 | public void sendMessage(String message);
9 | public void onClose(int statusCode, String reason);
10 | public void onText(String message);
11 | public void onOpen();
12 | public void sendMessage(Object data);
13 | public void start();
14 | public void stop();
15 | public int getStatusCode();
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/queue/QueueCallbackIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.queue;
17 |
18 | /**
19 | *
20 | * @author greg
21 | */
22 | public interface QueueCallbackIface {
23 |
24 | public void call(String channel, Object value);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/queue/QueueClientIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.queue;
17 |
18 | import org.cricketmsf.exception.QueueException;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public interface QueueClientIface {
25 |
26 | public void publish(String channel, String key, Object value) throws QueueException;
27 | public void publish(String channel, Object value) throws QueueException;
28 | public Object getCopy(String channel, String key) throws QueueException;
29 | public Object getCopy(String channel) throws QueueException;
30 | public Object get(String channel, String key) throws QueueException;
31 | public void push(String channel, Object value) throws QueueException;
32 | public Object pop(String channel) throws QueueException;
33 | public void purge(String channel) throws QueueException;
34 | public long getQueueSize(String channel) throws QueueException;
35 | public long getQueueSize() throws QueueException;
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/queue/SubscriberIface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.in.queue;
17 |
18 | import org.cricketmsf.exception.QueueException;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public interface SubscriberIface {
25 |
26 | public void subscribe(String channel) throws QueueException;
27 | public void unsubscribe(String channel) throws QueueException;
28 | public void init() throws QueueException;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/services/BasicEventRouter.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.services;
2 |
3 | import java.util.HashMap;
4 | import org.cricketmsf.Kernel;
5 | import org.cricketmsf.RequestObject;
6 | import org.cricketmsf.annotation.EventHook;
7 | import org.cricketmsf.api.Result;
8 | import org.cricketmsf.api.ResultIface;
9 | import org.cricketmsf.api.StandardResult;
10 | import org.cricketmsf.event.Event;
11 | import org.cricketmsf.event.GreeterEvent;
12 | import org.cricketmsf.event.HttpEvent;
13 | import org.cricketmsf.event.Procedures;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 |
17 | /**
18 | *
19 | * @author greg
20 | */
21 | public class BasicEventRouter {
22 |
23 | private static final Logger logger = LoggerFactory.getLogger(BasicEventRouter.class);
24 |
25 | private BasicService service;
26 |
27 | public BasicEventRouter(BasicService service){
28 | this.service=service;
29 | }
30 |
31 | @EventHook(className = "org.cricketmsf.event.Event", procedure = Procedures.SYSTEM_STATUS)
32 | public ResultIface handleStatusRequest(Event requestEvent) {
33 | logger.info("Hello from {}", this.getClass().getName());
34 | return new StandardResult(((BasicService) Kernel.getInstance()).reportStatus());
35 | }
36 |
37 | @EventHook(className = "org.cricketmsf.event.Event", procedure = Procedures.PRINT_INFO)
38 | public Result printInfo(Event event) {
39 | logger.info("INFO {} {} {}", service.getProceduresDictionary().getName(event.getProcedure()), event.getTimeDefinition(), event.getData());
40 | return null;
41 | }
42 |
43 | /**
44 | *
45 | * @param event
46 | * @return ParameterMapResult with the file content as a byte array
47 | */
48 | @EventHook(className = "org.cricketmsf.event.HttpEvent"/*, procedure = Procedures.WWW*/)
49 | public ResultIface doGet(HttpEvent event) {
50 | return service.wwwFileReader.getFile(
51 | (RequestObject) event.getData(),
52 | service.cacheDB,
53 | "webcache"
54 | );
55 | }
56 |
57 | @EventHook(className = "org.cricketmsf.event.GreeterEvent", procedure = Procedures.GREET)
58 | public ResultIface doGreet(GreeterEvent event) {
59 | String name = ((HashMap) event.getData()).get("name");
60 | ResultIface result = new Result("Hello " + name);
61 | result.setProcedure(Procedures.GREET);
62 | try {
63 | Thread.sleep(10000);
64 | } catch (InterruptedException ex) {
65 |
66 | }
67 | return result;
68 | }
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/services/MinimalService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.services;
17 |
18 | import org.cricketmsf.Kernel;
19 | import org.cricketmsf.exception.InitException;
20 | import org.cricketmsf.in.openapi.OpenApiIface;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | /**
25 | * EchoService
26 | *
27 | * @author greg
28 | */
29 | public class MinimalService extends Kernel {
30 |
31 | private static final Logger logger = LoggerFactory.getLogger(MinimalService.class);
32 |
33 | // adapterClasses
34 | OpenApiIface apiGenerator = null;
35 |
36 | public MinimalService() {
37 | super();
38 | this.configurationBaseName = "MinimalService";
39 | }
40 |
41 | @Override
42 | public void getAdapters() {
43 | apiGenerator = (OpenApiIface) getRegistered("OpenApi");
44 | }
45 |
46 | @Override
47 | public void runInitTasks() {
48 | try {
49 | super.runInitTasks();
50 | } catch (InitException ex) {
51 | ex.printStackTrace();
52 | shutdown();
53 | }
54 | if(null!=apiGenerator){
55 | apiGenerator.init(this);
56 | }
57 | setInitialized(true);
58 | }
59 |
60 | @Override
61 | public void runFinalTasks() {
62 |
63 | }
64 |
65 | @Override
66 | public void runOnce() {
67 | super.runOnce();
68 | if(null!=apiGenerator){
69 | apiGenerator.init(this);
70 | }
71 | logger.info("MinimalService.runOnce() executed");
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/util/FileReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Grzegorz Skorupa.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.util;
17 |
18 | import java.io.BufferedInputStream;
19 | import java.io.File;
20 | import java.io.FileInputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 |
26 | /**
27 | *
28 | * @author greg
29 | */
30 | public class FileReader {
31 |
32 | private static final Logger logger = LoggerFactory.getLogger(FileReader.class);
33 |
34 | public static byte[] readFile(File file) throws IOException {
35 | byte[] result = new byte[(int) file.length()];
36 | InputStream input = null;
37 | try {
38 | int totalBytesRead = 0;
39 | input = new BufferedInputStream(new FileInputStream(file));
40 | while (totalBytesRead < result.length) {
41 | int bytesRemaining = result.length - totalBytesRead;
42 | //input.read() returns -1, 0, or more :
43 | int bytesRead = input.read(result, totalBytesRead, bytesRemaining);
44 | if (bytesRead > 0) {
45 | totalBytesRead = totalBytesRead + bytesRead;
46 | }
47 | }
48 | } finally {
49 | try {
50 | if (input != null) {
51 | input.close();
52 | }
53 | } catch (IOException e) {
54 | }
55 | }
56 | return result;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/util/JsonReader.java:
--------------------------------------------------------------------------------
1 | package org.cricketmsf.util;
2 |
3 | public class JsonReader {
4 |
5 | public static Object jsonToJava(String source, Class cls) {
6 | String jsonString = source;
7 | jsonString = "{\"@type\":\"" + cls.getName() + "\","
8 | + jsonString.substring(jsonString.indexOf("{") + 1);
9 | return com.cedarsoftware.util.io.JsonReader.jsonToJava(jsonString);
10 | }
11 |
12 | public static Object jsonToJava(String source) {
13 | return com.cedarsoftware.util.io.JsonReader.jsonToJava(source);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/cricketmsf/util/Stopwatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Grzegorz Skorupa .
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.cricketmsf.util;
17 |
18 | import java.util.concurrent.TimeUnit;
19 |
20 | /**
21 | *
22 | * @author greg
23 | */
24 | public class Stopwatch {
25 |
26 | public long start = System.nanoTime();
27 |
28 | public long time() {
29 | return System.nanoTime() - start;
30 | }
31 |
32 | public long time(TimeUnit unit) {
33 | return unit.convert(time(), TimeUnit.NANOSECONDS);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/resources/BasicService-help.txt:
--------------------------------------------------------------------------------
1 |
2 | Usage:
3 | java -jar cricketms-1.4.4.jar [options]
4 | java -cp cricketms-1.4.4.jar org.cricketmsf.Runner [options]
5 |
6 | Runs selected service class.
7 |
8 | Options:
9 | --help | -h Print this usage information and exit
10 | --run | -r Run the configured service on the embeded http server
11 | --config | -c PATH Use external configuration file at PATH
12 | --force | -f PARAMS Overwrite selected configuration
13 | --service | -s SERVICE_ID Run selected service from the configuration file
14 | --print | -p Print settings and exit
15 | --export | -e Export settings and logging config to files
16 | --lift | -l class Run specified class (on classpath) as a service
17 |
18 | PARAMS format:
19 | service_id^property_name=value^adapter_name^property_name=value
20 | service_id^^adapter_name^property_name=value
21 | service_id^property_name=value
22 |
23 | Without -r option, the runOnce() method of selected service will be executed.
24 | Without -s option, default BasicService will be used.
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 | logs/service.log
18 |
19 | %date{yyyy-MM-dd HH:mm:ss.SSS, Etc/UTC} %level [%thread] %logger{1} [%file:%line] %msg%n
20 |
21 |
22 |
23 |
24 |
25 | %msg%n
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/other/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Example
5 |
6 |
7 |
8 |
9 | Hello World!
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/other/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ## uncomment example environment variables
4 | # export CRICKET_VAR1 = varA
5 | # export CRICKET_VAR2 = varB
6 |
7 | java -jar cricket.jar -s BasicService -r
8 |
--------------------------------------------------------------------------------
/src/other/run_8.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | java -jar {{distribution}} -c config/cricket.json -s Microsite -r
--------------------------------------------------------------------------------