├── .gitignore ├── .travis.yml ├── LICENSE ├── README.adoc ├── pom.xml ├── snoopee-config ├── README.adoc ├── pom.xml ├── snoopee-config-client │ ├── README.adoc │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── eu │ │ └── agilejava │ │ └── snoopee │ │ └── config │ │ ├── Configuration.java │ │ ├── SnoopEEConfig.java │ │ └── SnoopEEConfigProducer.java ├── snoopee-config-service │ ├── README.adoc │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── eu │ │ │ └── agilejava │ │ │ └── snoopee │ │ │ └── config │ │ │ ├── ApplicationConfig.java │ │ │ └── api │ │ │ └── ConfigurationsResource.java │ │ ├── resources │ │ └── snoopee.yml │ │ ├── webapp │ │ ├── WEB-INF │ │ │ └── jboss-web.xml │ │ ├── index.html │ │ └── resources │ │ │ └── images │ │ │ └── favicon.ico │ │ └── wildfly │ │ └── standalone-snoopee.xml └── snoopee-config-source │ ├── pom.xml │ └── src │ └── main │ └── java │ └── eu │ └── agilejava │ └── snoopee │ └── config │ ├── Configuration.java │ └── SnoopEEConfigSource.java └── snoopee-discovery ├── FAQ.adoc ├── LICENSE ├── README.adoc ├── pom.xml ├── service-consumption.adoc ├── service-discovery.adoc ├── service-registration.adoc ├── snoopee-client ├── pom.xml └── src │ └── main │ ├── java │ └── eu │ │ └── agilejava │ │ └── snoopee │ │ ├── SnoopEEConfigurationException.java │ │ ├── SnoopEEExtensionHelper.java │ │ ├── annotation │ │ ├── SnoopEE.java │ │ └── package-info.java │ │ ├── client │ │ ├── SnoopEEConfig.java │ │ ├── SnoopEEProducer.java │ │ ├── SnoopEEServiceClient.java │ │ ├── SnoopEEServiceUnavailableException.java │ │ └── package-info.java │ │ └── package-info.java │ └── resources │ └── META-INF │ └── microprofile-config.properties ├── snoopee-micro ├── pom.xml └── src │ └── main │ ├── java │ └── eu │ │ └── agilejava │ │ └── snoopee │ │ ├── annotation │ │ ├── EnableSnoopEEClient.java │ │ ├── SnoopEEClient.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── scan │ │ ├── SnoopEEExtensionHelper.java │ │ ├── SnoopEERegistrationClient.java │ │ ├── SnoopEEScannerExtension.java │ │ └── package-info.java │ └── resources │ └── META-INF │ ├── beans.xml │ └── services │ └── javax.enterprise.inject.spi.Extension ├── snoopee-service.adoc ├── snoopee-service ├── README.adoc ├── loglevels.sh ├── pom.xml └── src │ └── main │ ├── glassfish │ ├── custom-logger-0.5.jar │ └── logging.properties │ ├── java │ └── eu │ │ └── agilejava │ │ └── snoopee │ │ ├── SnoopEEClientRegistry.java │ │ ├── SnoopEEConfig.java │ │ ├── SnoopEEEndpoint.java │ │ ├── SnoopEEService.java │ │ ├── SnoopEEStatusEndpoint.java │ │ ├── api │ │ └── ServicesResource.java │ │ ├── config │ │ └── ApplicatonConfig.java │ │ ├── package-info.java │ │ └── ui │ │ └── SnoopController.java │ ├── webapp │ ├── WEB-INF │ │ ├── glassfish-web.xml │ │ ├── jboss-web.xml │ │ ├── template.xhtml │ │ └── web.xml │ ├── resources │ │ ├── css │ │ │ ├── cssLayout.css │ │ │ └── default.css │ │ └── images │ │ │ └── favicon.ico │ └── services.xhtml │ └── wildfly │ └── standalone-snoopee.xml └── snoopee ├── pom.xml └── src └── main ├── java └── eu │ └── agilejava │ └── snoopee │ ├── annotation │ ├── EnableSnoopEEClient.java │ ├── SnoopEEClient.java │ └── package-info.java │ ├── package-info.java │ └── scan │ ├── SnoopEERegistrationClient.java │ ├── SnoopEEScannerExtension.java │ └── package-info.java └── resources └── META-INF ├── beans.xml └── services └── javax.enterprise.inject.spi.Extension /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | nbactions.xml 8 | nb-configuration.xml 9 | .idea/ 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ivar Grimstad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE - The Lean Microservice Framework for Java EE 2 | 3 | SnoopEE [ˈsnuːpı] consist of the following sub projects 4 | 5 | * SnoopEE Discovery - a registration and discovery service for Java EE based microservices 6 | * SnoopEE Config - a flexible configuration service for Java EE based microservices 7 | 8 | 9 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoopee-root 6 | 2.0.0-SNAPSHOT 7 | pom 8 | 9 | SnoopEE Root 10 | SnoopEE - A Microservice framework for Java EE 11 | 12 | http://snoopee.agilejava.eu 13 | 14 | 15 | 16 | MIT License 17 | http://www.opensource.org/licenses/mit-license.php 18 | 19 | 20 | 21 | 22 | 23 | Ivar Grimstad 24 | ivar.grimstad@gmail.com 25 | AgileJava 26 | http://www.agilejava.eu 27 | 28 | 29 | 30 | 31 | UTF-8 32 | 1.8 33 | 1.8 34 | mit 35 | 0.4.13 36 | 37 | 38 | 39 | snoopee-discovery 40 | snoopee-config 41 | 42 | 43 | 44 | 45 | ossrh 46 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 47 | 48 | 49 | ossrh 50 | https://oss.sonatype.org/content/repositories/snapshots 51 | 52 | 53 | 54 | 55 | scm:git:ssh://git@github.com:ivargrimstad/snoopee.git 56 | scm:git:ssh://git@github.com:ivargrimstad/snoopee.git 57 | git@github.com:ivargrimstad/snoopee.git 58 | HEAD 59 | 60 | 61 | 62 | 63 | 64 | org.jacoco 65 | jacoco-maven-plugin 66 | 0.7.5.201505241946 67 | 68 | 69 | 70 | report 71 | 72 | report 73 | 74 | 75 | 76 | 77 | org.sonatype.plugins 78 | nexus-staging-maven-plugin 79 | 1.6.3 80 | true 81 | 82 | ossrh 83 | https://oss.sonatype.org/ 84 | true 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | release 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-source-plugin 98 | 2.2.1 99 | 100 | 101 | attach-sources 102 | 103 | jar-no-fork 104 | 105 | 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-javadoc-plugin 111 | 2.9.1 112 | 113 | 114 | attach-javadocs 115 | 116 | jar 117 | 118 | 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-gpg-plugin 124 | 1.5 125 | 126 | 127 | sign-artifacts 128 | verify 129 | 130 | sign 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /snoopee-config/README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE Config - a flexible configuration service for Java EE based microservices 2 | -------------------------------------------------------------------------------- /snoopee-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | eu.agilejava 6 | snoopee-config 7 | 2.0.0-SNAPSHOT 8 | pom 9 | 10 | SnoopEE Config 11 | SnoopEE - A Configuration Service for Java EE 12 | 13 | 14 | eu.agilejava 15 | snoopee-root 16 | 2.0.0-SNAPSHOT 17 | 18 | 19 | 20 | snoopee-config-client 21 | snoopee-config-service 22 | snoopee-config-source 23 | 24 | 25 | 26 | 27 | javax 28 | javaee-web-api 29 | 7.0 30 | provided 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-client/README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE Config Client 2 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoopee-config-client 6 | 2.0.0-SNAPSHOT 7 | jar 8 | 9 | SnoopEE Config Client 10 | SnoopEE - A Config Client for Java EE. 11 | 12 | 13 | false 14 | 15 | 16 | 17 | eu.agilejava 18 | snoopee-config 19 | 2.0.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | eu.agilejava 25 | snoopee-client 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-client/src/main/java/eu/agilejava/snoopee/config/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import java.util.Objects; 27 | import javax.xml.bind.annotation.XmlAccessType; 28 | import javax.xml.bind.annotation.XmlAccessorType; 29 | import javax.xml.bind.annotation.XmlRootElement; 30 | 31 | /** 32 | * 33 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 34 | */ 35 | @XmlRootElement 36 | @XmlAccessorType(XmlAccessType.FIELD) 37 | public class Configuration { 38 | 39 | private String key; 40 | private String value; 41 | 42 | Configuration() { 43 | } 44 | 45 | public Configuration(final String key, final String value) { 46 | this.key = key; 47 | this.value = value; 48 | } 49 | 50 | public String getKey() { 51 | return key; 52 | } 53 | 54 | public String getValue() { 55 | return value; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | int hash = 7; 61 | hash = 79 * hash + Objects.hashCode(this.key); 62 | hash = 79 * hash + Objects.hashCode(this.value); 63 | return hash; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (this == obj) { 69 | return true; 70 | } 71 | if (obj == null) { 72 | return false; 73 | } 74 | if (getClass() != obj.getClass()) { 75 | return false; 76 | } 77 | final Configuration other = (Configuration) obj; 78 | if (!Objects.equals(this.key, other.key)) { 79 | return false; 80 | } 81 | if (!Objects.equals(this.value, other.value)) { 82 | return false; 83 | } 84 | return true; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "Configuration{" + "key=" + key + ", value=" + value + '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-client/src/main/java/eu/agilejava/snoopee/config/SnoopEEConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import static java.lang.annotation.ElementType.TYPE; 27 | import static java.lang.annotation.ElementType.FIELD; 28 | import static java.lang.annotation.ElementType.PARAMETER; 29 | import static java.lang.annotation.ElementType.METHOD; 30 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 31 | import java.lang.annotation.Retention; 32 | import java.lang.annotation.Target; 33 | import javax.enterprise.util.Nonbinding; 34 | import javax.inject.Qualifier; 35 | 36 | /** 37 | * 38 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 39 | */ 40 | @Qualifier 41 | @Retention(RUNTIME) 42 | @Target({METHOD, FIELD, PARAMETER, TYPE}) 43 | public @interface SnoopEEConfig { 44 | 45 | @Nonbinding 46 | String key() default ""; 47 | 48 | @Nonbinding 49 | String defaultValue() default ""; 50 | } 51 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-client/src/main/java/eu/agilejava/snoopee/config/SnoopEEConfigProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import eu.agilejava.snoopee.SnoopEEConfigurationException; 27 | import eu.agilejava.snoopee.SnoopEEExtensionHelper; 28 | import eu.agilejava.snoopee.annotation.SnoopEE; 29 | import eu.agilejava.snoopee.client.SnoopEEServiceClient; 30 | import java.util.HashMap; 31 | import java.util.List; 32 | import java.util.Map; 33 | import java.util.NoSuchElementException; 34 | import java.util.logging.Logger; 35 | import static java.util.stream.Collectors.toMap; 36 | import javax.annotation.PostConstruct; 37 | import javax.enterprise.context.Dependent; 38 | import javax.enterprise.inject.Produces; 39 | import javax.enterprise.inject.spi.InjectionPoint; 40 | import javax.inject.Inject; 41 | import javax.ws.rs.core.GenericType; 42 | 43 | /** 44 | * 45 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 46 | */ 47 | @Dependent 48 | public class SnoopEEConfigProducer { 49 | 50 | private static final Logger LOGGER = Logger.getLogger(SnoopEEConfigProducer.class.getName()); 51 | 52 | @Inject 53 | @SnoopEE(serviceName = "snoopee-config") 54 | private SnoopEEServiceClient configService; 55 | 56 | private final Map configurations = new HashMap<>(); 57 | 58 | @Produces 59 | @SnoopEEConfig 60 | public String getStringConfigValue(final InjectionPoint ip) { 61 | return getValue(ip.getAnnotated().getAnnotation(SnoopEEConfig.class)); 62 | } 63 | 64 | @Produces 65 | @SnoopEEConfig 66 | public int getIntConfigValue(InjectionPoint ip) { 67 | return Integer.parseInt(getStringConfigValue(ip)); 68 | } 69 | 70 | private String getValue(final SnoopEEConfig config) { 71 | 72 | if (configurations.containsKey(config.key())) { 73 | return configurations.get(config.key()); 74 | } else if (!config.defaultValue().isEmpty()) { 75 | LOGGER.warning(() -> "No value for key: " + config.key() + ". Using DEFAULT value: " + config.defaultValue()); 76 | return config.defaultValue(); 77 | } else { 78 | LOGGER.severe(() -> "No value for key: " + config.key()); 79 | throw new SnoopEEConfigurationException("No value for key:" + config.key()); 80 | } 81 | } 82 | 83 | @PostConstruct 84 | private void init() { 85 | 86 | try { 87 | 88 | configurations.putAll(configService.simpleGet("services/" + SnoopEEExtensionHelper.getServiceName() + "/configurations") 89 | .filter(r -> r.getStatus() == 200) 90 | .map(r -> r.readEntity(new GenericType>() {})) 91 | .get() 92 | .stream() 93 | .collect(toMap(Configuration::getKey, Configuration::getValue))); 94 | 95 | } catch (NoSuchElementException e) { 96 | LOGGER.warning(() -> "No configurations found for service: " + SnoopEEExtensionHelper.getServiceName()); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE Config Service 2 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoopee-config-service 6 | 2.0.0-SNAPSHOT 7 | war 8 | 9 | SnoopEE Config Service 10 | SnoopEE - A Config Service for Java EE. 11 | 12 | 13 | false 14 | 0.20.0 15 | 16 | 17 | 18 | eu.agilejava 19 | snoopee-config 20 | 2.0.0-SNAPSHOT 21 | 22 | 23 | 24 | 25 | eu.agilejava 26 | snoopee 27 | 2.0.0-SNAPSHOT 28 | 29 | 30 | eu.agilejava 31 | snoopee-config-client 32 | 2.0.0-SNAPSHOT 33 | 34 | 35 | 36 | 37 | 38 | 39 | io.fabric8 40 | docker-maven-plugin 41 | ${version.docker-maven-plugin} 42 | 43 | 44 | 45 | wildfly 46 | ivargrimstad/${project.artifactId}:${project.version} 47 | 48 | Ivar Grimstad (ivar.grimstad@gmail.com) 49 | jboss/wildfly:10.1.0.Final 50 | 51 | jboss:jboss:jboss 52 | /opt/jboss/wildfly/standalone 53 | 54 | 55 | 56 | ${basedir}/target/${project.build.finalName}.war 57 | deployments 58 | 59 | 60 | ${basedir}/src/main/wildfly/standalone-snoopee.xml 61 | configuration 62 | 63 | 64 | 65 | 66 | 67 | 68 | /opt/jboss/wildfly/bin/standalone.sh 69 | -c 70 | standalone-snoopee.xml 71 | -b 72 | 0.0.0.0 73 | 74 | 75 | 76 | 77 | 78 | http://localhost 79 | 8082 80 | snoopee-config-service/api 81 | 130.190.101.232:8081/snoopee-service/ 82 | 83 | 84 | 8082:8080 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/java/eu/agilejava/snoopee/config/ApplicationConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import eu.agilejava.snoopee.annotation.EnableSnoopEEClient; 27 | import eu.agilejava.snoopee.config.api.ConfigurationsResource; 28 | import java.util.HashSet; 29 | import java.util.Set; 30 | import javax.ws.rs.ApplicationPath; 31 | import javax.ws.rs.core.Application; 32 | 33 | /** 34 | * 35 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 36 | */ 37 | @EnableSnoopEEClient(serviceName = "snoopee-config") 38 | @ApplicationPath("api") 39 | public class ApplicationConfig extends Application { 40 | 41 | @Override 42 | public Set> getClasses() { 43 | Set> resources = new HashSet<>(); 44 | 45 | resources.add(ConfigurationsResource.class); 46 | 47 | return resources; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/java/eu/agilejava/snoopee/config/api/ConfigurationsResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config.api; 25 | 26 | import eu.agilejava.snoopee.config.Configuration; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import javax.ws.rs.GET; 30 | import javax.ws.rs.Path; 31 | import javax.ws.rs.PathParam; 32 | import javax.ws.rs.Produces; 33 | import javax.ws.rs.core.GenericEntity; 34 | import javax.ws.rs.core.MediaType; 35 | import javax.ws.rs.core.Response; 36 | 37 | /** 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 40 | */ 41 | @Path("services") 42 | public class ConfigurationsResource { 43 | 44 | @GET 45 | @Path("{serviceName}/configurations") 46 | @Produces(MediaType.APPLICATION_JSON) 47 | public Response getConfigurationsForService(@PathParam("serviceName") String serviceName) { 48 | 49 | List configurations = new ArrayList<>(); 50 | configurations.add(new Configuration("message", "Duke")); 51 | 52 | return Response.ok(new GenericEntity>(configurations) {}).build(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/resources/snoopee.yml: -------------------------------------------------------------------------------- 1 | snoopee: 2 | host: http://localhost 3 | port: 8082 4 | serviceRoot: snoopee-config-service/api 5 | 6 | # snoopeeService: localhost:8080/snoopee-service/ 7 | snoopeeService: 10.19.210.62:8081/snoopee-service/ -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | /snoopee-config-service 4 | 5 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | SnoopEE Configuration Service 28 | 29 | 30 | 31 | 32 | 33 | 34 |
Welcome to the SnoopEE Configuration Service
35 | 36 | 37 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/webapp/resources/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivargrimstad/snoopee/da1086ce0634d76a302b5b9e74cd76b7e4dc1fcc/snoopee-config/snoopee-config-service/src/main/webapp/resources/images/favicon.ico -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-service/src/main/wildfly/standalone-snoopee.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 143 | h2 144 | 145 | sa 146 | sa 147 | 148 | 149 | 150 | 151 | org.h2.jdbcx.JdbcDataSource 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | false 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | ${jboss.bind.address:127.0.0.1} 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-source/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | eu.agilejava 7 | snoopee-config-source 8 | 2.0.0-SNAPSHOT 9 | jar 10 | 11 | SnoopEE Config Provider 12 | SnoopEE - A Configuration Provider for Eclipse MicroProfile Config 13 | 14 | 15 | snoopee-config 16 | eu.agilejava 17 | 2.0.0-SNAPSHOT 18 | 19 | 20 | 21 | 22 | org.eclipse.microprofile.config 23 | microprofile-config-api 24 | 1.1 25 | provided 26 | 27 | 28 | eu.agilejava 29 | snoopee-client 30 | 2.0.0-SNAPSHOT 31 | 32 | 33 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-source/src/main/java/eu/agilejava/snoopee/config/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2017 Ivar Grimstad (ivar.grimstad@cybercom.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import javax.xml.bind.annotation.XmlAccessType; 27 | import javax.xml.bind.annotation.XmlAccessorType; 28 | import javax.xml.bind.annotation.XmlRootElement; 29 | import java.util.Objects; 30 | 31 | /** 32 | * 33 | * @author Ivar Grimstad (ivar.grimstad@cybercom.com) 34 | */ 35 | @XmlRootElement 36 | @XmlAccessorType(XmlAccessType.FIELD) 37 | public class Configuration { 38 | 39 | private String key; 40 | private String value; 41 | 42 | Configuration() { 43 | } 44 | 45 | public Configuration(final String key, final String value) { 46 | this.key = key; 47 | this.value = value; 48 | } 49 | 50 | public String getKey() { 51 | return key; 52 | } 53 | 54 | public String getValue() { 55 | return value; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | int hash = 7; 61 | hash = 79 * hash + Objects.hashCode(this.key); 62 | hash = 79 * hash + Objects.hashCode(this.value); 63 | return hash; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (this == obj) { 69 | return true; 70 | } 71 | if (obj == null) { 72 | return false; 73 | } 74 | if (getClass() != obj.getClass()) { 75 | return false; 76 | } 77 | final Configuration other = (Configuration) obj; 78 | if (!Objects.equals(this.key, other.key)) { 79 | return false; 80 | } 81 | if (!Objects.equals(this.value, other.value)) { 82 | return false; 83 | } 84 | return true; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "Configuration{" + "key=" + key + ", value=" + value + '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /snoopee-config/snoopee-config-source/src/main/java/eu/agilejava/snoopee/config/SnoopEEConfigSource.java: -------------------------------------------------------------------------------- 1 | package eu.agilejava.snoopee.config; 2 | 3 | import eu.agilejava.snoopee.SnoopEEConfigurationException; 4 | import eu.agilejava.snoopee.SnoopEEExtensionHelper; 5 | import eu.agilejava.snoopee.annotation.SnoopEE; 6 | import eu.agilejava.snoopee.client.SnoopEEServiceClient; 7 | import org.eclipse.microprofile.config.spi.ConfigSource; 8 | 9 | import javax.annotation.PostConstruct; 10 | import javax.enterprise.context.ApplicationScoped; 11 | import javax.inject.Inject; 12 | import javax.ws.rs.core.GenericType; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.util.NoSuchElementException; 17 | import java.util.logging.Logger; 18 | 19 | import static java.util.stream.Collectors.toMap; 20 | 21 | @ApplicationScoped 22 | public class SnoopEEConfigSource implements ConfigSource { 23 | 24 | private static final Logger LOGGER = Logger.getLogger(SnoopEEConfigSource.class.getName()); 25 | 26 | @Inject 27 | @SnoopEE(serviceName = "snoopee-config") 28 | private SnoopEEServiceClient configService; 29 | 30 | private final Map configurations = new HashMap<>(); 31 | 32 | @Override 33 | public Map getProperties() { 34 | return configurations; 35 | } 36 | 37 | @Override 38 | public String getValue(String key) { 39 | if (configurations.containsKey(key)) { 40 | return configurations.get(key); 41 | } else { 42 | LOGGER.severe(() -> "No value for key: " + key); 43 | throw new SnoopEEConfigurationException("No value for key:" + key); 44 | } 45 | } 46 | 47 | @Override 48 | public String getName() { 49 | return "SnoopEE Config Source"; 50 | } 51 | 52 | @Override 53 | public int getOrdinal() { 54 | return 350; 55 | } 56 | 57 | @PostConstruct 58 | private void init() { 59 | 60 | try { 61 | 62 | configurations.putAll(configService.simpleGet("services/" + SnoopEEExtensionHelper.getServiceName() + "/configurations") 63 | .filter(r -> r.getStatus() == 200) 64 | .map(r -> r.readEntity(new GenericType>() { 65 | })) 66 | .get() 67 | .stream() 68 | .collect(toMap(Configuration::getKey, Configuration::getValue))); 69 | 70 | } catch (NoSuchElementException e) { 71 | LOGGER.warning(() -> "No configurations found for service: " + SnoopEEExtensionHelper.getServiceName()); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /snoopee-discovery/FAQ.adoc: -------------------------------------------------------------------------------- 1 | = Frequently Asked Questions about SnoopEE 2 | 3 | ## Is SnoopEE a Load Balancer? 4 | *No*, the intention of SnoopEE is to provide a service registration and lookup 5 | mechanism. If you are running multiple instances of a microservice, this should 6 | be load balanced using any load balancer tool and it is the _load balancer's IP/hostname_ 7 | that is registered with SnoopEE Service using the SnoopEE configuration parameters. 8 | 9 | _[todo] example_ 10 | 11 | 12 | link:README.adoc[[home\]] 13 | -------------------------------------------------------------------------------- /snoopee-discovery/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ivar Grimstad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /snoopee-discovery/README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE - A Discovery Service for Java EE 2 | 3 | SnoopEE [ˈsnuːpı] is an experimental registration and discovery service for Java EE based microservices. 4 | 5 | == Getting Started 6 | 7 | . Start the link:snoopee-service.adoc[SnoopEE Service] 8 | . link:service-registration.adoc[Service Registration] 9 | . link:service-discovery.adoc[Service Discovery] 10 | 11 | == Maven 12 | 13 | . Released artifacts are available in link:http://search.maven.org/#search%7Cga%7C1%7Csnoopee[Maven Central] 14 | . Snapshots configuration: 15 | 16 | 17 | 18 | OSSRH 19 | https://oss.sonatype.org/content/groups/public 20 | 21 | true 22 | 23 | 24 | 25 | 26 | == Examples 27 | 28 | - link:https://github.com/ivargrimstad/snoopee-samples[snoopee-samples@GitHub (works with SnoopEE 1.0] 29 | - link:https://github.com/arun-gupta/microservices[https://github.com/arun-gupta/microservices] 30 | 31 | == FAQ 32 | 33 | - link:FAQ.adoc[Frequently Asked Questions] 34 | -------------------------------------------------------------------------------- /snoopee-discovery/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | eu.agilejava 6 | snoopee-discovery 7 | 2.0.0-SNAPSHOT 8 | pom 9 | 10 | SnoopEE Discovery 11 | SnoopEE - A Discovery Service for Java EE 12 | 13 | 14 | eu.agilejava 15 | snoopee-root 16 | 2.0.0-SNAPSHOT 17 | 18 | 19 | 20 | snoopee 21 | snoopee-micro 22 | snoopee-client 23 | snoopee-service 24 | 25 | 26 | 27 | 28 | 29 | javax 30 | javaee-web-api 31 | 7.0 32 | 33 | 34 | org.eclipse.microprofile 35 | microprofile 36 | 1.3 37 | pom 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /snoopee-discovery/service-consumption.adoc: -------------------------------------------------------------------------------- 1 | == Consuming a SnoopEE Service 2 | 3 | . link:service-discovery.adoc[Discover the Service] 4 | 5 | . Call the service 6 | .. Use the Client API. 7 | + 8 | [source,java] 9 | String helloResponse = helloService.simpleGet("hello") 10 | .filter(r -> r.getStatus() == 200) 11 | .map(r -> r.readEntity(String.class)) 12 | .orElse("goodbye"); 13 | 14 | .. Or use `WebTarget` directly. 15 | + 16 | [source,java] 17 | try { 18 | WebTarget endpoint = helloService.getServiceRoot(); 19 | ... 20 | } catch(SnoopEEServiceUnavailableException e) { 21 | ... 22 | } 23 | 24 | link:README.adoc[[home\]] 25 | -------------------------------------------------------------------------------- /snoopee-discovery/service-discovery.adoc: -------------------------------------------------------------------------------- 1 | == Service Discovery 2 | 3 | . Maven Dependency 4 | 5 | 6 | eu.agilejava 7 | snoopee-client 8 | ${snoopee.version}/version> 9 | 10 | 11 | . Configure the client 12 | .. Using `snoopee.yml` 13 | 14 | snoopee: 15 | snoopeeService: 192.168.59.103:8081/snoopee-service/ 16 | 17 | .. Or by environment variable 18 | 19 | docker run -it -p 8080:8080 -e "snoopeeService=192.168.59.103:8081/snoopee-service/" ivargrimstad/snoopee-helloworld:1.0.0-SNAPSHOT 20 | 21 | .. Or by system properties 22 | 23 | -DsnoopeeService=192.168.59.103:8081/snoopee-service/ 24 | 25 | . To discover a service, use the @SnoopEE qualifier to inject a client to the registered service. 26 | + 27 | [source,java] 28 | @Inject 29 | @SnoopEE(serviceName = "hello") 30 | private SnoopEEDiscoveryClient helloService; 31 | 32 | . link:service-consumption.adoc[Consume the Service] 33 | 34 | link:README.adoc[[home\]] 35 | -------------------------------------------------------------------------------- /snoopee-discovery/service-registration.adoc: -------------------------------------------------------------------------------- 1 | == Service Registration 2 | 3 | . Maven Dependency 4 | 5 | 6 | eu.agilejava 7 | snoopee 8 | ${snoopee.version} 9 | 10 | 11 | . Enable SnoopEE 12 | + 13 | [source,java] 14 | @EnableSnoopEEClient(serviceName="myservice") 15 | @ApplicationPath("api") 16 | public class ApplicationConfig extends Application { 17 | ... 18 | } 19 | 20 | . Configure the service 21 | .. Use `snoopee.yml` 22 | 23 | snoopee: 24 | host: http://localhost 25 | port: 8080 26 | serviceRoot: snoopee-hello-service/api 27 | snoopeeService: 192.168.59.103:8081/snoopee-service/ 28 | 29 | .. Or by environment variables (remember prefix with service name) 30 | 31 | docker run -it -p 8080:8080 -e "hello.host=http://192.168.59.103" -e "hello.port=8080" -e "hello.serviceRoot=snoopee-hello-service/api" -e "hello.snoopeeService=192.168.59.103:8081/snoopee-service/" ivargrimstad/snoopee-hello 32 | 33 | .. Or by system properties 34 | 35 | -Dhost=http://192.168.59.103 -Dport=8080 -DserviceRoot=snoopee-hello-service/api -DsnoopeeService: 192.168.59.103:8081/snoopee-service/ 36 | 37 | link:README.adoc[[home\]] 38 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | eu.agilejava 6 | snoopee-client 7 | 2.0.0-SNAPSHOT 8 | jar 9 | 10 | SnoopEE Client 11 | SnoopEE Discovery Client 12 | 13 | 14 | eu.agilejava 15 | snoopee-discovery 16 | 2.0.0-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.microprofile 23 | microprofile 24 | pom 25 | provided 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | /** 27 | * This exception indicates that the SnoopEE configuration is erroneous. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public class SnoopEEConfigurationException extends RuntimeException { 32 | 33 | public SnoopEEConfigurationException(String message) { 34 | super(message); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/SnoopEEExtensionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | /** 27 | * Singleton to store the information gathered from annotation scan. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public final class SnoopEEExtensionHelper { 32 | 33 | private String serviceName; 34 | private boolean snoopEnabled; 35 | 36 | private static final SnoopEEExtensionHelper INSTANCE = new SnoopEEExtensionHelper(); 37 | 38 | public static String getServiceName() { 39 | return INSTANCE.serviceName; 40 | } 41 | 42 | public static void setServiceName(String serviceName) { 43 | INSTANCE.serviceName = serviceName; 44 | } 45 | 46 | public static boolean isSnoopEnabled() { 47 | return INSTANCE.snoopEnabled; 48 | } 49 | 50 | public static void setSnoopEnabled(final boolean snoopEnabled) { 51 | INSTANCE.snoopEnabled = snoopEnabled; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/annotation/SnoopEE.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import static java.lang.annotation.ElementType.FIELD; 28 | import static java.lang.annotation.ElementType.METHOD; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | import javax.enterprise.util.Nonbinding; 34 | import javax.inject.Qualifier; 35 | 36 | /** 37 | * Annotation for looking up a service registered with SnoopEE. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | @Qualifier 42 | @Retention(RUNTIME) 43 | @Documented 44 | @Target({FIELD, METHOD}) 45 | public @interface SnoopEE { 46 | 47 | /** 48 | * The name of the service. 49 | * 50 | * @return The service name 51 | */ 52 | @Nonbinding 53 | String serviceName() default ""; 54 | } 55 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.client; 25 | 26 | import java.io.StringReader; 27 | import java.io.StringWriter; 28 | import java.io.Writer; 29 | import javax.json.Json; 30 | import javax.json.JsonObject; 31 | import javax.json.JsonReader; 32 | import javax.json.stream.JsonGenerator; 33 | 34 | /** 35 | * Holds the meta data for the registered service. 36 | * 37 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 38 | */ 39 | public class SnoopEEConfig { 40 | 41 | private String serviceName; 42 | private String serviceHome; 43 | private String serviceRoot; 44 | 45 | public String getServiceName() { 46 | return serviceName; 47 | } 48 | 49 | public void setServiceName(String serviceName) { 50 | this.serviceName = serviceName; 51 | } 52 | 53 | public String getServiceHome() { 54 | return serviceHome; 55 | } 56 | 57 | public void setServiceHome(String serviceHome) { 58 | this.serviceHome = serviceHome; 59 | } 60 | 61 | public String getServiceRoot() { 62 | return serviceRoot; 63 | } 64 | 65 | public void setServiceRoot(String serviceRoot) { 66 | this.serviceRoot = serviceRoot; 67 | } 68 | 69 | public String toJSON() { 70 | 71 | Writer w = new StringWriter(); 72 | try (JsonGenerator generator = Json.createGenerator(w)) { 73 | 74 | generator.writeStartObject() 75 | .write("serviceName", serviceName) 76 | .write("serviceHome", serviceHome) 77 | .write("serviceRoot", serviceRoot) 78 | .writeEnd(); 79 | } 80 | 81 | return w.toString(); 82 | } 83 | 84 | public static SnoopEEConfig fromJSON(String json) { 85 | 86 | SnoopEEConfig config = new SnoopEEConfig(); 87 | 88 | try (JsonReader reader = Json.createReader(new StringReader(json))) { 89 | 90 | JsonObject configJson = reader.readObject(); 91 | 92 | config.setServiceName(configJson.getString("serviceName")); 93 | config.setServiceHome(configJson.getString("serviceHome")); 94 | config.setServiceRoot(configJson.getString("serviceRoot")); 95 | } 96 | 97 | return config; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.client; 25 | 26 | import eu.agilejava.snoopee.annotation.SnoopEE; 27 | import org.eclipse.microprofile.config.inject.ConfigProperty; 28 | 29 | import javax.enterprise.context.ApplicationScoped; 30 | import javax.enterprise.context.Dependent; 31 | import javax.enterprise.inject.Produces; 32 | import javax.enterprise.inject.spi.InjectionPoint; 33 | import javax.inject.Inject; 34 | import java.util.logging.Logger; 35 | 36 | /** 37 | * CDI Producer for SnoopEEServiceClient. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | @ApplicationScoped 42 | public class SnoopEEProducer { 43 | 44 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 45 | 46 | @ConfigProperty(name = "snoopeeService", defaultValue = "http://localhost:8081/snoopee-service/") 47 | @Inject 48 | private String serviceUrl; 49 | 50 | /** 51 | * Creates a SnoopEEServiceClient for the named service. 52 | * 53 | * @param ip The injection point 54 | * @return a configured SnoopEE service client 55 | */ 56 | @SnoopEE 57 | @Produces 58 | @Dependent 59 | public SnoopEEServiceClient lookup(InjectionPoint ip) { 60 | 61 | final String applicationName = ip.getAnnotated().getAnnotation(SnoopEE.class).serviceName(); 62 | 63 | LOGGER.config(() -> "producing " + applicationName); 64 | LOGGER.config(() -> "Service URL: " + serviceUrl); 65 | 66 | return new SnoopEEServiceClient.Builder(applicationName) 67 | .serviceUrl(serviceUrl) 68 | .build(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEServiceClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.client; 25 | 26 | import java.util.Optional; 27 | import java.util.logging.Logger; 28 | import javax.ws.rs.ProcessingException; 29 | import javax.ws.rs.client.Client; 30 | import javax.ws.rs.client.ClientBuilder; 31 | import javax.ws.rs.client.Entity; 32 | import javax.ws.rs.client.WebTarget; 33 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 34 | 35 | import javax.ws.rs.core.MultivaluedHashMap; 36 | import javax.ws.rs.core.Response; 37 | 38 | /** 39 | * Client API for calling services registered with SnoopEE. 40 | * 41 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 42 | */ 43 | public class SnoopEEServiceClient { 44 | 45 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 46 | private static final String DEFAULT_BASE_URI = "http://localhost:8081/snoopee-service/"; 47 | private static final String DEFAULT_ENCODING = "charset=utf8"; 48 | 49 | private final String applicationName; 50 | private final String serviceUrl; 51 | 52 | static final class Builder { 53 | 54 | private final String applicationName; 55 | private String serviceUrl = DEFAULT_BASE_URI; 56 | 57 | Builder(final String applicationName) { 58 | this.applicationName = applicationName; 59 | } 60 | 61 | Builder serviceUrl(final String serviceUrl) { 62 | this.serviceUrl = serviceUrl; 63 | return this; 64 | } 65 | 66 | SnoopEEServiceClient build() { 67 | return new SnoopEEServiceClient(this); 68 | } 69 | } 70 | 71 | private SnoopEEServiceClient(final Builder builder) { 72 | this.applicationName = builder.applicationName; 73 | this.serviceUrl = builder.serviceUrl; 74 | LOGGER.info(() -> "client created for " + applicationName); 75 | } 76 | 77 | /** 78 | * Locator to get the service root for the service registered with SnoopEE. 79 | * 80 | * Use this method if the convenience methods simpleXXX are not sufficient or to avoid the extra call to SnoopEE for 81 | * every request. 82 | * 83 | * @return the serviceRoot 84 | * 85 | * @throws SnoopEEServiceUnavailableException if service is not available 86 | */ 87 | public WebTarget getServiceRoot() throws SnoopEEServiceUnavailableException { 88 | 89 | SnoopEEConfig snoopEEConfig = getConfigFromSnoopEE(); 90 | LOGGER.fine(() -> "looking up service for " + applicationName); 91 | 92 | return ClientBuilder.newClient() 93 | .target(snoopEEConfig.getServiceHome()) 94 | .path(snoopEEConfig.getServiceRoot()); 95 | } 96 | 97 | /** 98 | * Convenience method for making a simple GET request on a resource. 99 | * 100 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 101 | * addition to the actual GET request. 102 | * 103 | * @param resourcePath The relative path to the resource 104 | * @return an optional response that is empty if the service is unavailable. 105 | */ 106 | public Optional simpleGet(String resourcePath) { 107 | 108 | Optional returnValue = Optional.empty(); 109 | 110 | try { 111 | 112 | returnValue = Optional.of(getServiceRoot() 113 | .path(resourcePath) 114 | .request() 115 | .get()); 116 | 117 | } catch (SnoopEEServiceUnavailableException e) { 118 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 119 | } 120 | 121 | return returnValue; 122 | } 123 | 124 | /** 125 | * Convenience method for making a simple DELETE request on a resource. 126 | * 127 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 128 | * addition to the actual DELETE request. 129 | * 130 | * @param resourcePath The relative path to the resource 131 | * @return an optional response that is empty if the service is unavailable. 132 | */ 133 | public Optional simpleDelete(String resourcePath) { 134 | 135 | Optional returnValue = Optional.empty(); 136 | 137 | try { 138 | 139 | returnValue = Optional.of(getServiceRoot() 140 | .path(resourcePath) 141 | .request() 142 | .delete()); 143 | 144 | } catch (SnoopEEServiceUnavailableException e) { 145 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 146 | } 147 | 148 | return returnValue; 149 | } 150 | 151 | /** 152 | * Convenience method for making a simple PUT request on a resource. 153 | * 154 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 155 | * addition to the actual PUT request. 156 | * 157 | * @param resourcePath The relative path to the resource 158 | * @param resource The changes made to this resource 159 | * @return an optional response that is empty if the service is unavailable. 160 | */ 161 | public Optional simplePut(String resourcePath, Object resource) { 162 | 163 | Optional returnValue = Optional.empty(); 164 | 165 | try { 166 | 167 | returnValue = Optional.of(getServiceRoot() 168 | .path(resourcePath) 169 | .request() 170 | .put(Entity.entity(resource, APPLICATION_JSON))); 171 | 172 | } catch (SnoopEEServiceUnavailableException e) { 173 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 174 | } 175 | 176 | return returnValue; 177 | } 178 | 179 | /** 180 | * Convenience method for making a simple POST request on a resource. 181 | * 182 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 183 | * addition to the actual POST request. 184 | * 185 | * @param resourcePath The relative path to the resource 186 | * @param resource The new resource 187 | * @return an optional response that is empty if the service is unavailable. 188 | */ 189 | public Optional simplePost(String resourcePath, Object resource) { 190 | 191 | Optional returnValue = Optional.empty(); 192 | 193 | try { 194 | 195 | returnValue = Optional.of(getServiceRoot() 196 | .path(resourcePath) 197 | .request() 198 | .post(Entity.entity(resource, APPLICATION_JSON))); 199 | 200 | } catch (SnoopEEServiceUnavailableException e) { 201 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 202 | } 203 | 204 | return returnValue; 205 | } 206 | 207 | private SnoopEEConfig getConfigFromSnoopEE() throws SnoopEEServiceUnavailableException { 208 | 209 | try { 210 | Response response = ClientBuilder.newClient() 211 | .target(serviceUrl) 212 | .path("api") 213 | .path("services") 214 | .path(applicationName) 215 | .request(APPLICATION_JSON) 216 | .get(); 217 | 218 | if (response.getStatus() == 200) { 219 | return response.readEntity(SnoopEEConfig.class); 220 | } else { 221 | throw new SnoopEEServiceUnavailableException("Response from \"" + serviceUrl + "\"=" + response.getStatus()); 222 | } 223 | 224 | } catch (ProcessingException e) { 225 | throw new SnoopEEServiceUnavailableException(e); 226 | } 227 | } 228 | 229 | /** 230 | * Method for making a GET request on a resource with setting explicit headers. 231 | * 232 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 233 | * addition to the actual GET request. 234 | * 235 | * @param headers The headers to set 236 | * @param resourcePath The relative path to the resource 237 | * @return an optional response that is empty if the service is unavailable. 238 | */ 239 | public Optional get(MultivaluedHashMap headers, String resourcePath) { 240 | 241 | Optional returnValue = Optional.empty(); 242 | 243 | try { 244 | returnValue = Optional.of(getServiceRoot() 245 | .path(resourcePath) 246 | .request() 247 | .headers(headers) 248 | .get()); 249 | 250 | } catch (SnoopEEServiceUnavailableException e) { 251 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 252 | } 253 | 254 | return returnValue; 255 | } 256 | 257 | /** 258 | * Method for making a DELETE request on a resource with setting explicit headers. 259 | * 260 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 261 | * addition to the actual DELETE request. 262 | * 263 | * @param headers The headers to set 264 | * @param resourcePath The relative path to the resource 265 | * @return an optional response that is empty if the service is unavailable. 266 | */ 267 | public Optional delete(MultivaluedHashMap headers, String resourcePath) { 268 | 269 | Optional returnValue = Optional.empty(); 270 | 271 | try { 272 | returnValue = Optional.of(getServiceRoot() 273 | .path(resourcePath) 274 | .request() 275 | .headers(headers) 276 | .delete()); 277 | 278 | } catch (SnoopEEServiceUnavailableException e) { 279 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 280 | } 281 | 282 | return returnValue; 283 | } 284 | 285 | /** 286 | * Method for making a simple PUT request on a resource with setting explicit headers. 287 | * 288 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 289 | * addition to the actual PUT request. 290 | * 291 | * @param headers The headers to set 292 | * @param resourcePath The relative path to the resource 293 | * @param resource The changes made to this resource 294 | * @return an optional response that is empty if the service is unavailable. 295 | */ 296 | public Optional put(MultivaluedHashMap headers, String resourcePath, Object resource) { 297 | 298 | Optional returnValue = Optional.empty(); 299 | 300 | try { 301 | returnValue = Optional.of(getServiceRoot() 302 | .path(resourcePath) 303 | .request() 304 | .headers(headers) 305 | .put(Entity.entity(resource, APPLICATION_JSON + "; " + DEFAULT_ENCODING))); 306 | } catch (SnoopEEServiceUnavailableException e) { 307 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 308 | } 309 | 310 | return returnValue; 311 | } 312 | 313 | /** 314 | * Method for making a simple POST request on a resource with setting explicit headers. 315 | * 316 | * Calling this method will result in a call to SnoopEE to retrieve the current configuration for the service in 317 | * addition to the actual POST request. 318 | * 319 | * @param headers The headers to set 320 | * @param resourcePath The relative path to the resource 321 | * @param resource The new resource 322 | * @return an optional response that is empty if the service is unavailable. 323 | */ 324 | public Optional post(MultivaluedHashMap headers, String resourcePath, Object resource) { 325 | 326 | Optional returnValue = Optional.empty(); 327 | 328 | try { 329 | returnValue = Optional.of(getServiceRoot() 330 | .path(resourcePath) 331 | .request() 332 | .headers(headers) 333 | .post(Entity.entity(resource, APPLICATION_JSON + "; " + DEFAULT_ENCODING))); 334 | } catch (SnoopEEServiceUnavailableException e) { 335 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 336 | } 337 | 338 | return returnValue; 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/SnoopEEServiceUnavailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.client; 25 | 26 | /** 27 | * This exception is thrown if the SnoopEE service is not available. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public class SnoopEEServiceUnavailableException extends RuntimeException { 32 | 33 | public SnoopEEServiceUnavailableException(String message) { 34 | super(message); 35 | } 36 | 37 | public SnoopEEServiceUnavailableException(Throwable cause) { 38 | super(cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.client; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/java/eu/agilejava/snoopee/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-client/src/main/resources/META-INF/microprofile-config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivargrimstad/snoopee/da1086ce0634d76a302b5b9e74cd76b7e4dc1fcc/snoopee-discovery/snoopee-client/src/main/resources/META-INF/microprofile-config.properties -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | eu.agilejava 6 | snoopee-micro 7 | 2.0.0-SNAPSHOT 8 | jar 9 | 10 | SnoopEE Micro 11 | SnoopEE MicroProfile Registration Client 12 | 13 | 14 | eu.agilejava 15 | snoopee-discovery 16 | 2.0.0-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | eu.agilejava 23 | snoopee-client 24 | 2.0.0-SNAPSHOT 25 | 26 | 27 | 28 | org.eclipse.microprofile 29 | microprofile 30 | pom 31 | provided 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/annotation/EnableSnoopEEClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | import javax.enterprise.util.Nonbinding; 35 | 36 | /** 37 | * Annotation for enabling application as SnoopEE client. Use this annotation to register the application (service) with 38 | * SnoopEE. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Stereotype 43 | @Retention(RUNTIME) 44 | @Documented 45 | @ApplicationScoped 46 | @Target(TYPE) 47 | public @interface EnableSnoopEEClient { 48 | 49 | /** 50 | * The service name. This is the unique identifier for this service when it is registered with SnoopEE. 51 | * 52 | * @return The name of the service 53 | */ 54 | @Nonbinding 55 | String serviceName(); 56 | } 57 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/annotation/SnoopEEClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | 35 | /** 36 | * Annotation for enabling application as SnoopEE client. Use this annotation to register the application (service) with 37 | * SnoopEE. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | @Stereotype 42 | @Retention(RUNTIME) 43 | @Documented 44 | @ApplicationScoped 45 | @Target(TYPE) 46 | public @interface SnoopEEClient { 47 | } 48 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/scan/SnoopEEExtensionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | 26 | /** 27 | * Singleton to store the information gathered from annotation scan. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public final class SnoopEEExtensionHelper { 32 | 33 | private String serviceName; 34 | private boolean snoopEnabled; 35 | 36 | private static final SnoopEEExtensionHelper INSTANCE = new SnoopEEExtensionHelper(); 37 | 38 | public static String getServiceName() { 39 | return INSTANCE.serviceName; 40 | } 41 | 42 | public static void setServiceName(String serviceName) { 43 | INSTANCE.serviceName = serviceName; 44 | } 45 | 46 | public static boolean isSnoopEnabled() { 47 | return INSTANCE.snoopEnabled; 48 | } 49 | 50 | public static void setSnoopEnabled(final boolean snoopEnabled) { 51 | INSTANCE.snoopEnabled = snoopEnabled; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/scan/SnoopEERegistrationClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | 26 | import eu.agilejava.snoopee.SnoopEEConfigurationException; 27 | import eu.agilejava.snoopee.annotation.SnoopEEClient; 28 | import eu.agilejava.snoopee.client.SnoopEEConfig; 29 | import org.eclipse.microprofile.config.inject.ConfigProperty; 30 | 31 | import javax.annotation.PreDestroy; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.context.Initialized; 34 | import javax.enterprise.event.Event; 35 | import javax.enterprise.event.Observes; 36 | import javax.inject.Inject; 37 | import javax.ws.rs.client.Client; 38 | import javax.ws.rs.client.ClientBuilder; 39 | import javax.ws.rs.client.Entity; 40 | import javax.ws.rs.core.Response; 41 | import java.util.Calendar; 42 | import java.util.Timer; 43 | import java.util.TimerTask; 44 | import java.util.logging.Logger; 45 | 46 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 47 | 48 | /** 49 | * Registers with SnoopEE and gives heartbeats every 10 second. 50 | * 51 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 52 | */ 53 | @SnoopEEClient 54 | public class SnoopEERegistrationClient { 55 | 56 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 57 | 58 | @Inject 59 | @ConfigProperty(name = "snoopeeService", defaultValue = "http://localhost:8081/snoopee-service/jalla") 60 | private String serviceUrl; 61 | 62 | @Inject 63 | @ConfigProperty(name="port") 64 | private int port; 65 | 66 | @Inject 67 | @ConfigProperty(name="host") 68 | private String host; 69 | 70 | @Inject 71 | @ConfigProperty(name = "serviceRoot", defaultValue = "/") 72 | private String serviceRoot; 73 | 74 | private final SnoopEEConfig applicationConfig = new SnoopEEConfig(); 75 | 76 | private Timer timer; 77 | 78 | @Inject 79 | private Event configuredEvent; 80 | 81 | private void init(@Observes @Initialized(ApplicationScoped.class) Object init) { 82 | LOGGER.config("Checking if SnoopEE is enabled"); 83 | 84 | if (SnoopEEExtensionHelper.isSnoopEnabled()) { 85 | 86 | Client client = ClientBuilder.newClient(); 87 | 88 | try { 89 | readConfiguration(); 90 | LOGGER.config(() -> "Registering " + applicationConfig.getServiceName()); 91 | 92 | Response response = client 93 | .target(serviceUrl) 94 | .path("api") 95 | .path("services") 96 | .request() 97 | .post(Entity.entity(applicationConfig, APPLICATION_JSON)); 98 | 99 | LOGGER.config(() -> "Fire health event"); 100 | configuredEvent.fire(applicationConfig); 101 | 102 | } catch (SnoopEEConfigurationException e) { 103 | LOGGER.severe(() -> "SnoopEE is enabled but not configured properly: " + e.getMessage()); 104 | } finally { 105 | client.close(); 106 | } 107 | 108 | } else { 109 | LOGGER.config("SnoopEE is not enabled. Use @EnableSnoopEEClient!"); 110 | } 111 | } 112 | 113 | private void health() { 114 | 115 | LOGGER.config(() -> "health update: " + Calendar.getInstance().getTime()); 116 | Client client = ClientBuilder.newClient(); 117 | try { 118 | Response response = client 119 | .target(serviceUrl) 120 | .path("api") 121 | .path("services") 122 | .path(applicationConfig.getServiceName()) 123 | .request() 124 | .put(Entity.entity(applicationConfig, APPLICATION_JSON)); 125 | } finally { 126 | client.close(); 127 | } 128 | } 129 | 130 | @PreDestroy 131 | private void deRegister() { 132 | 133 | LOGGER.config(() -> "deRegistering " + applicationConfig.getServiceName()); 134 | 135 | Client client = ClientBuilder.newClient(); 136 | try { 137 | Response response = ClientBuilder.newClient() 138 | .target(serviceUrl) 139 | .path("api") 140 | .path("services") 141 | .path(applicationConfig.getServiceName()) 142 | .request() 143 | .delete(); 144 | } finally { 145 | client.close(); 146 | } 147 | } 148 | 149 | private void readConfiguration() throws SnoopEEConfigurationException { 150 | 151 | applicationConfig.setServiceName(SnoopEEExtensionHelper.getServiceName()); 152 | applicationConfig.setServiceHome(host + ":" + port); 153 | applicationConfig.setServiceRoot(serviceRoot); 154 | 155 | LOGGER.config(() -> "application config: " + applicationConfig.toJSON()); 156 | } 157 | 158 | public void init(@Observes SnoopEEConfig configEvent) { 159 | 160 | LOGGER.config("EVENT"); 161 | TimerTask health = new HealthPing(); 162 | timer = new Timer(); 163 | timer.scheduleAtFixedRate(health, 0, 10000); 164 | } 165 | 166 | private final class HealthPing extends TimerTask { 167 | 168 | @Override 169 | public void run() { 170 | LOGGER.config(() -> "I am healthy!"); 171 | health(); 172 | } 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/scan/SnoopEEScannerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | 26 | import java.util.logging.Logger; 27 | import javax.enterprise.event.Observes; 28 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 29 | import javax.enterprise.inject.spi.BeanManager; 30 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 31 | import javax.enterprise.inject.spi.Extension; 32 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 33 | import javax.enterprise.inject.spi.WithAnnotations; 34 | import eu.agilejava.snoopee.annotation.EnableSnoopEEClient; 35 | import java.lang.annotation.Annotation; 36 | import java.lang.reflect.Type; 37 | import java.util.Collections; 38 | import java.util.HashSet; 39 | import java.util.Set; 40 | import javax.enterprise.context.ApplicationScoped; 41 | import javax.enterprise.context.spi.CreationalContext; 42 | import javax.enterprise.inject.Any; 43 | import javax.enterprise.inject.Default; 44 | import javax.enterprise.inject.spi.AnnotatedType; 45 | import javax.enterprise.inject.spi.Bean; 46 | import javax.enterprise.inject.spi.InjectionPoint; 47 | import javax.enterprise.inject.spi.InjectionTarget; 48 | import javax.enterprise.util.AnnotationLiteral; 49 | 50 | /** 51 | * CDI Extension that scans for @EnableSnoopEEClient annotations. 52 | * 53 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 54 | */ 55 | public class SnoopEEScannerExtension implements Extension { 56 | 57 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 58 | 59 | private String serviceName; 60 | private boolean snoopEnabled; 61 | 62 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 63 | LOGGER.config("Scanning for SnoopEE clients"); 64 | } 65 | 66 | void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) { 67 | 68 | LOGGER.config("Discovering SnoopEE clients"); 69 | SnoopEEExtensionHelper.setServiceName(serviceName); 70 | SnoopEEExtensionHelper.setSnoopEnabled(snoopEnabled); 71 | 72 | AnnotatedType at = bm.createAnnotatedType(SnoopEERegistrationClient.class); 73 | final InjectionTarget it = bm.createInjectionTarget(at); 74 | 75 | abd.addBean(new Bean() { 76 | @Override 77 | public Class getBeanClass() { 78 | return SnoopEERegistrationClient.class; 79 | } 80 | 81 | @Override 82 | public Set getInjectionPoints() { 83 | return it.getInjectionPoints(); 84 | } 85 | 86 | @Override 87 | public boolean isNullable() { 88 | return false; 89 | } 90 | 91 | @Override 92 | public SnoopEERegistrationClient create(CreationalContext creationalContext) { 93 | SnoopEERegistrationClient instance = it.produce(creationalContext); 94 | it.inject(instance, creationalContext); 95 | it.postConstruct(instance); 96 | 97 | return instance; 98 | } 99 | 100 | @Override 101 | public void destroy(SnoopEERegistrationClient instance, CreationalContext creationalContext) { 102 | it.preDestroy(instance); 103 | it.dispose(instance); 104 | creationalContext.release(); 105 | } 106 | 107 | @Override 108 | public Set getTypes() { 109 | Set types = new HashSet(); 110 | types.add(SnoopEERegistrationClient.class); 111 | types.add(Object.class); 112 | return types; 113 | } 114 | 115 | @Override 116 | public Set getQualifiers() { 117 | Set qualifiers = new HashSet(); 118 | qualifiers.add(new AnnotationLiteral() { 119 | }); 120 | qualifiers.add(new AnnotationLiteral() { 121 | }); 122 | return qualifiers; 123 | } 124 | 125 | @Override 126 | public Class getScope() { 127 | return ApplicationScoped.class; 128 | } 129 | 130 | @Override 131 | public String getName() { 132 | return "snoopEERegistrationClient"; 133 | } 134 | 135 | @Override 136 | public Set> getStereotypes() { 137 | return Collections.emptySet(); 138 | } 139 | 140 | @Override 141 | public boolean isAlternative() { 142 | return false; 143 | } 144 | 145 | }); 146 | 147 | 148 | LOGGER.config("Finished scanning for SnoopEE clients"); 149 | } 150 | 151 | void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopEEClient.class) ProcessAnnotatedType pat) { 152 | 153 | // workaround for WELD bug revealed by JDK8u60 154 | final ProcessAnnotatedType snoopAnnotated = pat; 155 | 156 | LOGGER.config(() -> "Found @EnableSnoopEEClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName()); 157 | snoopEnabled = true; 158 | serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopEEClient.class).serviceName(); 159 | LOGGER.config(() -> "SnoopEE Service name is: " + serviceName); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/java/eu/agilejava/snoopee/scan/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-micro/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | eu.agilejava.snoopee.scan.SnoopEEScannerExtension -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service.adoc: -------------------------------------------------------------------------------- 1 | == SnoopEE Service 2 | 3 | Start the SnoopEE Service 4 | 5 | docker run -it -p 8081:8080 ivargrimstad/snoopee-service 6 | 7 | link:README.adoc[[home\]] 8 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/README.adoc: -------------------------------------------------------------------------------- 1 | If you want to see logging of client registrations, heartbeats and discoveries. 2 | 3 | == Start the SnoopEE Service 4 | 5 | ``` 6 | docker run -it -p 8081:8080 ivargrimstad/snoopee-service 7 | ``` 8 | 9 | == Set log levels 10 | 11 | ``` 12 | docker ps 13 | ./loglevels.sh [insert docker instance id here] 14 | ``` 15 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/loglevels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker exec $1 /opt/jboss/wildfly/bin/jboss-cli.sh --connect "/subsystem=logging/console-handler=CONSOLE:change-log-level(level="CONFIG")" 4 | docker exec $1 /opt/jboss/wildfly/bin/jboss-cli.sh --connect "/subsystem=logging/logger=eu.agilejava.snoopee:add(level=CONFIG)" 5 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoopee-service 6 | 2.0.0-SNAPSHOT 7 | war 8 | 9 | SnoopEE Service 10 | SnoopEE - A Discovery Service for Java EE. 11 | 12 | 13 | eu.agilejava 14 | snoopee-discovery 15 | 2.0.0-SNAPSHOT 16 | 17 | 18 | 19 | 0.20.0 20 | 21 | 22 | 23 | 24 | javax 25 | javaee-web-api 26 | provided 27 | 28 | 29 | 30 | 31 | 32 | glassfish 33 | 34 | true 35 | 36 | 37 | 38 | 39 | io.fabric8 40 | docker-maven-plugin 41 | ${version.docker-maven-plugin} 42 | 43 | 44 | 45 | 46 | glassfish 47 | ivargrimstad/${project.artifactId}:${project.version} 48 | 49 | Ivar Grimstad (ivar.grimstad@gmail.com) 50 | glassfish:4.1-jdk8 51 | 52 | /usr/local/glassfish4/glassfish/domains/domain1 53 | 54 | 55 | 56 | ${basedir}/target/${project.build.finalName}.war 57 | autodeploy 58 | 59 | 60 | ${basedir}/src/main/glassfish/logging.properties 61 | config 62 | 63 | 64 | ${basedir}/src/main/glassfish/custom-logger-0.5.jar 65 | lib/ext 66 | 67 | 68 | 69 | 70 | 71 | 72 | asadmin 73 | start-domain 74 | --verbose 75 | 76 | 77 | 78 | 79 | 80 | 8081:8080 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/glassfish/custom-logger-0.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivargrimstad/snoopee/da1086ce0634d76a302b5b9e74cd76b7e4dc1fcc/snoopee-discovery/snoopee-service/src/main/glassfish/custom-logger-0.5.jar -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/glassfish/logging.properties: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | # 4 | # Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. 5 | # 6 | # The contents of this file are subject to the terms of either the GNU 7 | # General Public License Version 2 only ("GPL") or the Common Development 8 | # and Distribution License("CDDL") (collectively, the "License"). You 9 | # may not use this file except in compliance with the License. You can 10 | # obtain a copy of the License at 11 | # https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html 12 | # or packager/legal/LICENSE.txt. See the License for the specific 13 | # language governing permissions and limitations under the License. 14 | # 15 | # When distributing the software, include this License Header Notice in each 16 | # file and include the License file at packager/legal/LICENSE.txt. 17 | # 18 | # GPL Classpath Exception: 19 | # Oracle designates this particular file as subject to the "Classpath" 20 | # exception as provided by Oracle in the GPL Version 2 section of the License 21 | # file that accompanied this code. 22 | # 23 | # Modifications: 24 | # If applicable, add the following below the License Header, with the fields 25 | # enclosed by brackets [] replaced by your own identifying information: 26 | # "Portions Copyright [year] [name of copyright owner]" 27 | # 28 | # Contributor(s): 29 | # If you wish your version of this file to be governed by only the CDDL or 30 | # only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | # elects to include this software in this distribution under the [CDDL or GPL 32 | # Version 2] license." If you don't indicate a single choice of license, a 33 | # recipient has the option to distribute your version of this file under 34 | # either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | # its licensees as provided above. However, if you add GPL Version 2 code 36 | # and therefore, elected the GPL Version 2 license, then the option applies 37 | # only if the new code is made subject to such option by the copyright 38 | # holder. 39 | # 40 | 41 | #GlassFish logging.properties list 42 | #Update Thurs Oct 18 2012 43 | #All attributes details 44 | handlers=java.util.logging.ConsoleHandler 45 | java.util.logging.ConsoleHandler.formatter=eu.agilejava.logger.CustomFormatter 46 | 47 | #All log level details 48 | java.util.logging.ConsoleHandler.level=CONFIG 49 | eu.agilejava.level=CONFIG 50 | 51 | #javax.enterprise.system.tools.admin.level=INFO 52 | #org.apache.jasper.level=INFO 53 | #javax.enterprise.system.core.level=INFO 54 | #javax.enterprise.system.core.classloading.level=INFO 55 | #javax.enterprise.system.tools.deployment.level=INFO 56 | #javax.enterprise.system.core.transaction.level=INFO 57 | #org.apache.catalina.level=INFO 58 | #org.apache.coyote.level=INFO 59 | #javax.level=INFO 60 | #javax.enterprise.system.util.level=INFO 61 | #javax.enterprise.resource.resourceadapter.level=INFO 62 | #javax.enterprise.system.core.config.level=INFO 63 | #javax.enterprise.system.level=INFO 64 | #javax.enterprise.system.core.security.level=INFO 65 | #javax.enterprise.system.container.cmp.level=INFO 66 | #javax.enterprise.system.core.selfmanagement.level=INFO 67 | #javax.enterprise.resource.jdo.level=INFO 68 | #javax.enterprise.resource.sqltrace.level=FINE 69 | #org.jvnet.hk2.osgiadapter.level=INFO 70 | #javax.enterprise.system.ssl.security.level=INFO 71 | 72 | #javax.enterprise.resource.corba.level=INFO 73 | #javax.enterprise.resource.jta.level=INFO 74 | #javax.enterprise.system.webservices.saaj.level=INFO 75 | #javax.enterprise.system.container.ejb.level=INFO 76 | #javax.enterprise.system.container.ejb.mdb.level=INFO 77 | #javax.enterprise.resource.javamail.level=INFO 78 | #javax.enterprise.system.webservices.rpc.level=INFO 79 | #javax.enterprise.system.container.web.level=INFO 80 | #javax.enterprise.resource.jms.level=INFO 81 | #javax.enterprise.system.webservices.registry.level=INFO 82 | #javax.enterprise.resource.webcontainer.jsf.application.level=INFO 83 | #javax.enterprise.resource.webcontainer.jsf.resource.level=INFO 84 | #javax.enterprise.resource.webcontainer.jsf.config.level=INFO 85 | #javax.enterprise.resource.webcontainer.jsf.context.level=INFO 86 | #javax.enterprise.resource.webcontainer.jsf.facelets.level=INFO 87 | #javax.enterprise.resource.webcontainer.jsf.lifecycle.level=INFO 88 | #javax.enterprise.resource.webcontainer.jsf.managedbean.level=INFO 89 | #javax.enterprise.resource.webcontainer.jsf.renderkit.level=INFO 90 | #javax.enterprise.resource.webcontainer.jsf.taglib.level=INFO 91 | #javax.enterprise.resource.webcontainer.jsf.timing.level=INFO 92 | #javax.org.glassfish.persistence.level=INFO 93 | #javax.enterprise.system.tools.backup.level=INFO 94 | #org.glassfish.admingui.level=INFO 95 | #org.glassfish.naming.level=INFO 96 | #org.eclipse.persistence.session.level=INFO 97 | 98 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/SnoopEEClientRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | import java.util.Calendar; 27 | import java.util.Collection; 28 | import java.util.Map; 29 | import java.util.Optional; 30 | import java.util.Set; 31 | import java.util.concurrent.ConcurrentHashMap; 32 | import java.util.logging.Logger; 33 | import java.util.stream.Collectors; 34 | import javax.ejb.Singleton; 35 | import static java.util.Calendar.getInstance; 36 | 37 | /** 38 | * Register of clients that have registered themselves. Automatically disregarded after a minute without heartbeat. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Singleton 43 | public class SnoopEEClientRegistry { 44 | 45 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 46 | 47 | private final Map clients = new ConcurrentHashMap<>(); 48 | private final Map clientConfigurations = new ConcurrentHashMap<>(); 49 | 50 | public void register(final SnoopEEConfig client) { 51 | Calendar now = getInstance(); 52 | clients.put(client.getServiceName(), now.getTimeInMillis()); 53 | clientConfigurations.put(client.getServiceName(), client); 54 | 55 | LOGGER.config(() -> "Client: " + client.getServiceName() + " registered up at " + now.getTime()); 56 | } 57 | 58 | public void deRegister(final String clientId) { 59 | clients.remove(clientId); 60 | clientConfigurations.remove(clientId); 61 | 62 | LOGGER.warning(() -> "Client: " + clientId + " deregistered at " + Calendar.getInstance().getTime()); 63 | } 64 | 65 | public Set getClients() { 66 | 67 | return clients.keySet().stream() 68 | .filter(c -> clients.get(c) > System.currentTimeMillis() - 60000) 69 | .collect(Collectors.toSet()); 70 | } 71 | 72 | public Collection getServiceConfigs() { 73 | return clientConfigurations.values(); 74 | } 75 | 76 | public Optional getClientConfig(String clientId) { 77 | 78 | if (getClients().contains(clientId)) { 79 | 80 | return Optional.ofNullable(clientConfigurations.get(clientId)); 81 | 82 | } else { 83 | return Optional.empty(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/SnoopEEConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | import java.io.StringReader; 27 | import java.io.StringWriter; 28 | import java.io.Writer; 29 | import javax.json.Json; 30 | import javax.json.JsonObject; 31 | import javax.json.JsonReader; 32 | import javax.json.stream.JsonGenerator; 33 | 34 | /** 35 | * 36 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 37 | */ 38 | public class SnoopEEConfig { 39 | 40 | private String serviceName; 41 | private String serviceHome; 42 | private String serviceRoot; 43 | 44 | public String getServiceName() { 45 | return serviceName; 46 | } 47 | 48 | public void setServiceName(String serviceName) { 49 | this.serviceName = serviceName; 50 | } 51 | 52 | public String getServiceHome() { 53 | return serviceHome; 54 | } 55 | 56 | public void setServiceHome(String serviceHome) { 57 | this.serviceHome = serviceHome; 58 | } 59 | 60 | public String getServiceRoot() { 61 | return serviceRoot; 62 | } 63 | 64 | public void setServiceRoot(String serviceRoot) { 65 | this.serviceRoot = serviceRoot; 66 | } 67 | 68 | public String toJSON() { 69 | 70 | Writer w = new StringWriter(); 71 | try (JsonGenerator generator = Json.createGenerator(w)) { 72 | 73 | generator.writeStartObject() 74 | .write("serviceName", serviceName) 75 | .write("serviceHome", serviceHome) 76 | .write("serviceRoot", serviceRoot) 77 | .writeEnd(); 78 | } 79 | 80 | return w.toString(); 81 | } 82 | 83 | public static SnoopEEConfig fromJSON(String json) { 84 | 85 | SnoopEEConfig config = new SnoopEEConfig(); 86 | 87 | try (JsonReader reader = Json.createReader(new StringReader(json))) { 88 | 89 | JsonObject configJson = reader.readObject(); 90 | 91 | config.setServiceName(configJson.getString("serviceName")); 92 | config.setServiceHome(configJson.getString("serviceHome")); 93 | config.setServiceRoot(configJson.getString("serviceRoot")); 94 | } 95 | 96 | return config; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/SnoopEEEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | import static eu.agilejava.snoopee.SnoopEEConfig.fromJSON; 27 | import java.util.logging.Logger; 28 | import javax.ejb.EJB; 29 | import javax.ejb.Stateless; 30 | import javax.websocket.OnMessage; 31 | import javax.websocket.server.ServerEndpoint; 32 | 33 | /** 34 | * WebSocket endpoint for client registration. 35 | * 36 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 37 | */ 38 | @ServerEndpoint("/snoopee") 39 | @Stateless 40 | public class SnoopEEEndpoint { 41 | 42 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 43 | 44 | @EJB 45 | private SnoopEEClientRegistry clients; 46 | 47 | @OnMessage 48 | public String onMessage(String message) { 49 | LOGGER.config(() -> "Registering: " + message); 50 | 51 | SnoopEEConfig client = fromJSON(message); 52 | 53 | clients.register(client); 54 | return "snoopeestatus/" + message; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/SnoopEEService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | import java.util.logging.Logger; 27 | import javax.annotation.PostConstruct; 28 | import javax.annotation.PreDestroy; 29 | import javax.ejb.Singleton; 30 | import javax.ejb.Startup; 31 | 32 | /** 33 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 34 | */ 35 | @Startup 36 | @Singleton 37 | public class SnoopEEService { 38 | 39 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 40 | 41 | @PostConstruct 42 | private void start() { 43 | 44 | // // http://www.network-science.de/ascii/ Font: big 45 | // LOGGER.config(" _____ ______ ______ "); 46 | // LOGGER.config(" / ____| | ____| ____|"); 47 | // LOGGER.config("| (___ _ __ ___ ___ _ __ | |__ | |__ "); 48 | // LOGGER.config(" \\___ \\| '_ \\ / _ \\ / _ \\| '_ \\| __| | __| "); 49 | // LOGGER.config(" ____) | | | | (_) | (_) | |_) | |____| |____ "); 50 | // LOGGER.config("|_____/|_| |_|\\___/ \\___/| .__/|______|______|"); 51 | // LOGGER.config(" | | "); 52 | // LOGGER.config(" |_| "); 53 | 54 | // http://www.ascii-art-generator.org/ Font: slant 55 | LOGGER.config(() -> ""); 56 | LOGGER.config(() -> " _____ ____________ __ ____ "); 57 | LOGGER.config(() ->" / ___/____ ____ ____ ____ / ____/ ____/ / |/ (_)_____________ "); 58 | LOGGER.config(() ->" \\__ \\/ __ \\/ __ \\/ __ \\/ __ \\/ __/ / __/ / /|_/ / / ___/ ___/ __ \\"); 59 | LOGGER.config(() ->" ___/ / / / / /_/ / /_/ / /_/ / /___/ /___ / / / / / /__/ / / /_/ /"); 60 | LOGGER.config(() ->"/____/_/ /_/\\____/\\____/ .___/_____/_____/ /_/ /_/_/\\___/_/ \\____/ "); 61 | LOGGER.config(() -> ""); 62 | } 63 | 64 | 65 | @PreDestroy 66 | private void stop() { 67 | LOGGER.severe("SnoopEE stopped"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/SnoopEEStatusEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | 26 | import static eu.agilejava.snoopee.SnoopEEConfig.fromJSON; 27 | import java.util.logging.Logger; 28 | import javax.ejb.EJB; 29 | import javax.ejb.Stateless; 30 | import javax.websocket.OnMessage; 31 | import javax.websocket.server.PathParam; 32 | import javax.websocket.server.ServerEndpoint; 33 | 34 | /** 35 | * WebSocket endpoint for heartbeats. 36 | * 37 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 38 | */ 39 | @ServerEndpoint("/snoopeestatus/{clientId}") 40 | @Stateless 41 | public class SnoopEEStatusEndpoint { 42 | 43 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 44 | 45 | @EJB 46 | private SnoopEEClientRegistry clients; 47 | 48 | /** 49 | * Heartbeat endpoint. 50 | * Registers that the client is still there and updates configuration 51 | * if changed. 52 | * 53 | * @param clientId The client id 54 | * @param applicationConfig The updated configuration 55 | */ 56 | @OnMessage 57 | public void onMessage(@PathParam("clientId") String clientId, String applicationConfig) { 58 | 59 | LOGGER.config(() -> "Client: " + clientId + ", status: " + applicationConfig); 60 | 61 | if (applicationConfig != null && !applicationConfig.isEmpty()) { 62 | clients.register(fromJSON(applicationConfig)); 63 | } else { 64 | clients.deRegister(clientId); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/api/ServicesResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.api; 25 | 26 | import eu.agilejava.snoopee.SnoopEEClientRegistry; 27 | import eu.agilejava.snoopee.SnoopEEConfig; 28 | import java.util.Collection; 29 | import javax.ejb.EJB; 30 | import javax.ws.rs.DELETE; 31 | import javax.ws.rs.GET; 32 | import javax.ws.rs.NotFoundException; 33 | import javax.ws.rs.POST; 34 | import javax.ws.rs.PUT; 35 | import javax.ws.rs.Path; 36 | import javax.ws.rs.PathParam; 37 | import javax.ws.rs.Produces; 38 | import javax.ws.rs.core.Context; 39 | import javax.ws.rs.core.GenericEntity; 40 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 41 | import javax.ws.rs.core.Response; 42 | import javax.ws.rs.core.UriInfo; 43 | 44 | /** 45 | * 46 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 47 | */ 48 | @Path("services") 49 | public class ServicesResource { 50 | 51 | @Context 52 | private UriInfo uriInfo; 53 | 54 | @EJB 55 | private SnoopEEClientRegistry snoopeeClientRegistry; 56 | 57 | @GET 58 | @Produces(APPLICATION_JSON) 59 | public Response all() { 60 | 61 | final Collection serviceConfigs = snoopeeClientRegistry.getServiceConfigs(); 62 | 63 | return Response.ok(new GenericEntity>(serviceConfigs) { 64 | }) 65 | .header("Access-Control-Allow-Origin", "*").build(); 66 | } 67 | 68 | @GET 69 | @Produces(APPLICATION_JSON) 70 | @Path("{serviceId}") 71 | public Response lookup(@PathParam("serviceId") String serviceId) { 72 | 73 | return Response.ok(snoopeeClientRegistry.getClientConfig(serviceId) 74 | .orElseThrow(NotFoundException::new)).build(); 75 | } 76 | 77 | @POST 78 | public Response register(final SnoopEEConfig serviceConfig) { 79 | snoopeeClientRegistry.register(serviceConfig); 80 | return Response.created(uriInfo.getAbsolutePathBuilder().segment(serviceConfig.getServiceName()).build()).build(); 81 | } 82 | 83 | @PUT 84 | @Path("{serviceName}") 85 | public Response updateStatus(@PathParam("serviceName") String serviceName, final SnoopEEConfig serviceConfig) { 86 | if (serviceConfig != null) { 87 | snoopeeClientRegistry.register(serviceConfig); 88 | } else { 89 | snoopeeClientRegistry.deRegister(serviceName); 90 | } 91 | return Response.ok().build(); 92 | } 93 | 94 | @DELETE 95 | @Path("{serviceName}") 96 | public Response deRegister(@PathParam("serviceName") String serviceName) { 97 | snoopeeClientRegistry.deRegister(serviceName); 98 | return Response.accepted().build(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/config/ApplicatonConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.config; 25 | 26 | import eu.agilejava.snoopee.api.ServicesResource; 27 | import java.util.HashSet; 28 | import java.util.Set; 29 | import javax.ws.rs.ApplicationPath; 30 | import javax.ws.rs.core.Application; 31 | 32 | /** 33 | * 34 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 35 | */ 36 | @ApplicationPath("api") 37 | public class ApplicatonConfig extends Application { 38 | 39 | @Override 40 | public Set> getClasses() { 41 | 42 | Set> classes = new HashSet<>(); 43 | classes.add(ServicesResource.class); 44 | 45 | return classes; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/java/eu/agilejava/snoopee/ui/SnoopController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.ui; 25 | 26 | import eu.agilejava.snoopee.SnoopEEClientRegistry; 27 | import eu.agilejava.snoopee.SnoopEEConfig; 28 | import java.util.Collection; 29 | import java.util.Set; 30 | import java.util.logging.Logger; 31 | import javax.ejb.EJB; 32 | import javax.enterprise.context.RequestScoped; 33 | import javax.inject.Named; 34 | 35 | /** 36 | * Controller for the SnoopEE service UI. 37 | * 38 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 39 | */ 40 | @Named 41 | @RequestScoped 42 | public class SnoopController { 43 | 44 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 45 | 46 | @EJB 47 | private SnoopEEClientRegistry clients; 48 | 49 | public Set getClients() { 50 | return clients.getClients(); 51 | } 52 | 53 | public Collection getClientConfigurations() { 54 | return clients.getServiceConfigs(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/WEB-INF/glassfish-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | snoopee-service 5 | 6 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | /snoopee-service 4 | 5 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/WEB-INF/template.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | SnoopEE Discovery Service 15 | 16 | 17 | 18 | 19 |
20 | 21 |

Welcome to SnoopEE Discovery Service

22 |
23 |
24 | 25 |
26 | Content 27 |
28 | 29 |
30 | 31 | @ivar_grimstad
32 | Licensed under the MIT License. 33 |
34 |
35 | 36 | 37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | javax.faces.PROJECT_STAGE 6 | Production 7 | 8 | 9 | 10 | javax.faces.DEFAULT_SUFFIX 11 | .xhtml 12 | 13 | 14 | 15 | Faces Servlet 16 | javax.faces.webapp.FacesServlet 17 | 1 18 | 19 | 20 | 21 | Faces Servlet 22 | /faces/* 23 | *.jsf 24 | 25 | 26 | 27 | 28 | 30 29 | 30 | 31 | 32 | 33 | services.jsf 34 | 35 | 36 | 37 | Restrict access to XHTML files 38 | 39 | XHTML files 40 | *.xhtml 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/resources/css/cssLayout.css: -------------------------------------------------------------------------------- 1 | 2 | #top { 3 | position: relative; 4 | background-color: #036fab; 5 | color: white; 6 | padding: 5px; 7 | margin: 0px 0px 10px 0px; 8 | } 9 | 10 | #bottom { 11 | position: relative; 12 | background-color: #c2dfef; 13 | padding: 5px; 14 | margin: 10px 0px 0px 0px; 15 | } 16 | 17 | #left { 18 | float: left; 19 | background-color: #ece3a5; 20 | padding: 5px; 21 | width: 150px; 22 | } 23 | 24 | #right { 25 | float: right; 26 | background-color: #ece3a5; 27 | padding: 5px; 28 | width: 150px; 29 | } 30 | 31 | .center_content { 32 | position: relative; 33 | background-color: #dddddd; 34 | padding: 5px; 35 | } 36 | 37 | .left_content { 38 | background-color: #dddddd; 39 | padding: 5px; 40 | margin-left: 170px; 41 | } 42 | 43 | .right_content { 44 | background-color: #dddddd; 45 | padding: 5px; 46 | margin: 0px 170px 0px 170px; 47 | } 48 | 49 | #top a:link, #top a:visited { 50 | color: white; 51 | font-weight : bold; 52 | text-decoration: none; 53 | } 54 | 55 | #top a:link:hover, #top a:visited:hover { 56 | color: black; 57 | font-weight : bold; 58 | text-decoration : underline; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/resources/css/default.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #ffffff; 3 | font-size: 12px; 4 | font-family: Verdana, "Verdana CE", Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; 5 | color: #000000; 6 | margin: 10px; 7 | } 8 | 9 | h1 { 10 | font-family: Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; 11 | font-size: 16px; 12 | font-weight: bold; 13 | margin: 0px; 14 | padding: 0px; 15 | color: #FFFFFF; 16 | } 17 | 18 | a:link, a:visited { 19 | color: #045491; 20 | font-weight : bold; 21 | text-decoration: none; 22 | } 23 | 24 | a:link:hover, a:visited:hover { 25 | color: #045491; 26 | font-weight : bold; 27 | text-decoration : underline; 28 | } 29 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/resources/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivargrimstad/snoopee/da1086ce0634d76a302b5b9e74cd76b7e4dc1fcc/snoopee-discovery/snoopee-service/src/main/webapp/resources/images/favicon.ico -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/webapp/services.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

Registered Services

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | #{client.serviceHome}#{client.serviceRoot} 30 | 31 | 32 | 33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee-service/src/main/wildfly/standalone-snoopee.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 133 | h2 134 | 135 | sa 136 | sa 137 | 138 | 139 | 140 | 141 | org.h2.jdbcx.JdbcDataSource 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | false 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | ${jboss.bind.address:127.0.0.1} 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | eu.agilejava 6 | snoopee 7 | 2.0.0-SNAPSHOT 8 | jar 9 | 10 | SnoopEE 11 | SnoopEE Registration Client 12 | 13 | 14 | eu.agilejava 15 | snoopee-discovery 16 | 2.0.0-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | eu.agilejava 23 | snoopee-client 24 | 2.0.0-SNAPSHOT 25 | 26 | 27 | 28 | javax 29 | javaee-web-api 30 | provided 31 | 32 | 33 | com.fasterxml.jackson.dataformat 34 | jackson-dataformat-yaml 35 | 2.5.1 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/annotation/EnableSnoopEEClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | import javax.enterprise.util.Nonbinding; 35 | 36 | /** 37 | * Annotation for enabling application as SnoopEE client. Use this annotation to register the application (service) with 38 | * SnoopEE. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Stereotype 43 | @Retention(RUNTIME) 44 | @Documented 45 | @ApplicationScoped 46 | @Target(TYPE) 47 | public @interface EnableSnoopEEClient { 48 | 49 | /** 50 | * The service name. This is the unique identifier for this service when it is registered with SnoopEE. 51 | * 52 | * @return The name of the service 53 | */ 54 | @Nonbinding 55 | String serviceName(); 56 | } 57 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/annotation/SnoopEEClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | import javax.enterprise.util.Nonbinding; 35 | 36 | /** 37 | * Annotation for enabling application as SnoopEE client. Use this annotation to register the application (service) with 38 | * SnoopEE. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Stereotype 43 | @Retention(RUNTIME) 44 | @Documented 45 | @ApplicationScoped 46 | @Target(TYPE) 47 | public @interface SnoopEEClient { 48 | } 49 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.annotation; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/scan/SnoopEERegistrationClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | 26 | import eu.agilejava.snoopee.SnoopEEExtensionHelper; 27 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; 28 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException; 29 | import eu.agilejava.snoopee.SnoopEEConfigurationException; 30 | import eu.agilejava.snoopee.client.SnoopEEConfig; 31 | import java.io.IOException; 32 | import java.net.URI; 33 | import java.util.Calendar; 34 | import java.util.Collections; 35 | import java.util.Map; 36 | import java.util.Optional; 37 | import java.util.logging.Logger; 38 | import javax.annotation.PostConstruct; 39 | import javax.annotation.PreDestroy; 40 | import javax.annotation.Resource; 41 | import javax.ejb.ScheduleExpression; 42 | import javax.ejb.Singleton; 43 | import javax.ejb.Startup; 44 | import javax.ejb.Timeout; 45 | import javax.ejb.Timer; 46 | import javax.ejb.TimerConfig; 47 | import javax.ejb.TimerService; 48 | import javax.websocket.ClientEndpoint; 49 | import javax.websocket.ContainerProvider; 50 | import javax.websocket.DeploymentException; 51 | import javax.websocket.OnMessage; 52 | import javax.websocket.Session; 53 | import javax.websocket.WebSocketContainer; 54 | 55 | /** 56 | * Registers with SnoopEE and gives heartbeats every 10 second. 57 | * 58 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 59 | */ 60 | @ClientEndpoint 61 | @Singleton 62 | @Startup 63 | public class SnoopEERegistrationClient { 64 | 65 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 66 | private static final String REGISTER_ENDPOINT = "snoopee"; 67 | private static final String STATUS_ENDPOINT = "snoopeestatus/"; 68 | 69 | private String serviceUrl; 70 | private final SnoopEEConfig applicationConfig = new SnoopEEConfig(); 71 | 72 | @Resource 73 | private TimerService timerService; 74 | 75 | @PostConstruct 76 | private void init() { 77 | LOGGER.config("Checking if SnoopEE is enabled"); 78 | 79 | if (SnoopEEExtensionHelper.isSnoopEnabled()) { 80 | 81 | try { 82 | readConfiguration(); 83 | 84 | LOGGER.config(() -> "Registering " + applicationConfig.getServiceName()); 85 | register(applicationConfig.getServiceName()); 86 | 87 | } catch (SnoopEEConfigurationException e) { 88 | LOGGER.severe(() -> "SnoopEE is enabled but not configured properly: " + e.getMessage()); 89 | } 90 | 91 | } else { 92 | LOGGER.config("SnoopEE is not enabled. Use @EnableSnoopEEClient!"); 93 | } 94 | } 95 | 96 | public void register(final String clientId) { 97 | 98 | sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON()); 99 | 100 | ScheduleExpression schedule = new ScheduleExpression(); 101 | schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); 102 | 103 | TimerConfig config = new TimerConfig(); 104 | config.setPersistent(false); 105 | 106 | Timer timer = timerService.createCalendarTimer(schedule, config); 107 | 108 | LOGGER.config(() -> timer.getSchedule().toString()); 109 | } 110 | 111 | /** 112 | * Handles incoming message. 113 | * 114 | * @param session The WebSocket session 115 | * @param message The message 116 | */ 117 | @OnMessage 118 | public void onMessage(Session session, String message) { 119 | LOGGER.config(() -> "Message: " + message); 120 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), applicationConfig.toJSON()); 121 | } 122 | 123 | @Timeout 124 | public void health(Timer timer) { 125 | LOGGER.config(() -> "health update: " + Calendar.getInstance().getTime()); 126 | LOGGER.config(() -> "Next: " + timer.getNextTimeout()); 127 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), applicationConfig.toJSON()); 128 | } 129 | 130 | /** 131 | * Sends message to the WebSocket server. 132 | * 133 | * @param endpoint The server endpoint 134 | * @param msg The message 135 | * @return a return message 136 | */ 137 | private String sendMessage(String endpoint, String msg) { 138 | 139 | LOGGER.config(() -> "Sending message: " + msg); 140 | 141 | String returnValue = "-1"; 142 | try { 143 | WebSocketContainer container = ContainerProvider.getWebSocketContainer(); 144 | String uri = serviceUrl + endpoint; 145 | Session session = container.connectToServer(this, URI.create(uri)); 146 | session.getBasicRemote().sendText(msg != null ? msg : ""); 147 | returnValue = session.getId(); 148 | 149 | session.close(); 150 | 151 | } catch (DeploymentException | IOException ex) { 152 | LOGGER.warning(ex.getMessage()); 153 | } 154 | 155 | return returnValue; 156 | } 157 | 158 | @PreDestroy 159 | private void deregister() { 160 | 161 | LOGGER.config(() -> "Deregistering " + applicationConfig.getServiceName()); 162 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), null); 163 | } 164 | 165 | private void readConfiguration() throws SnoopEEConfigurationException { 166 | 167 | Map snoopConfig = Collections.EMPTY_MAP; 168 | try { 169 | Yaml yaml = new Yaml(); 170 | Map props = (Map) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoopee.yml")); 171 | snoopConfig = (Map) props.get("snoopee"); 172 | 173 | } catch (YAMLException e) { 174 | LOGGER.config(() -> "No configuration file. Using env properties."); 175 | } 176 | 177 | applicationConfig.setServiceName(SnoopEEExtensionHelper.getServiceName()); 178 | final String host = readProperty("host", snoopConfig); 179 | final String port = readProperty("port", snoopConfig); 180 | applicationConfig.setServiceHome(host + ":" + port + "/"); 181 | applicationConfig.setServiceRoot(readProperty("serviceRoot", snoopConfig)); 182 | 183 | LOGGER.config(() -> "application config: " + applicationConfig.toJSON()); 184 | 185 | serviceUrl = "ws://" + readProperty("snoopeeService", snoopConfig); 186 | } 187 | 188 | private String readProperty(final String key, Map snoopConfig) { 189 | 190 | String property = Optional.ofNullable(System.getProperty(key)) 191 | .orElseGet(() -> { 192 | String envProp = Optional.ofNullable(System.getenv(applicationConfig.getServiceName() + "." + key)) 193 | .orElseGet(() -> { 194 | String confProp = Optional.ofNullable(snoopConfig.get(key)) 195 | .orElseThrow(() -> { 196 | return new SnoopEEConfigurationException(key + " must be configured either in snoopee.yml or as env parameter"); 197 | }) 198 | .toString(); 199 | return confProp; 200 | }); 201 | return envProp; 202 | }); 203 | return property; 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/scan/SnoopEEScannerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | 26 | import eu.agilejava.snoopee.SnoopEEExtensionHelper; 27 | import java.util.logging.Logger; 28 | import javax.enterprise.event.Observes; 29 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 30 | import javax.enterprise.inject.spi.BeanManager; 31 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 32 | import javax.enterprise.inject.spi.Extension; 33 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 34 | import javax.enterprise.inject.spi.WithAnnotations; 35 | import eu.agilejava.snoopee.annotation.EnableSnoopEEClient; 36 | 37 | /** 38 | * CDI Extension that scans for @EnableSnoopEEClient annotations. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | public class SnoopEEScannerExtension implements Extension { 43 | 44 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoopee"); 45 | 46 | private String serviceName; 47 | private boolean snoopEnabled; 48 | 49 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 50 | LOGGER.config("Scanning for SnoopEE clients"); 51 | } 52 | 53 | void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) { 54 | 55 | LOGGER.config("Discovering SnoopEE clients"); 56 | SnoopEEExtensionHelper.setServiceName(serviceName); 57 | SnoopEEExtensionHelper.setSnoopEnabled(snoopEnabled); 58 | LOGGER.config("Finished scanning for SnoopEE clients"); 59 | 60 | 61 | LOGGER.config("Finished scanning for SnoopEE clients"); 62 | } 63 | 64 | void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopEEClient.class) ProcessAnnotatedType pat) { 65 | 66 | // workaround for WELD bug revealed by JDK8u60 67 | final ProcessAnnotatedType snoopAnnotated = pat; 68 | 69 | LOGGER.config(() -> "Found @EnableSnoopEEClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName()); 70 | snoopEnabled = true; 71 | serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopEEClient.class).serviceName(); 72 | LOGGER.config(() -> "SnoopEE Service name is: " + serviceName); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/java/eu/agilejava/snoopee/scan/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoopee.scan; 25 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /snoopee-discovery/snoopee/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | eu.agilejava.snoopee.scan.SnoopEEScannerExtension --------------------------------------------------------------------------------