spring cloud config client does not load config files. Think the problem may be profile settins - spring-cloud-config

I have looked at past stack traces and I have all the correct settings. I think this is more a problem of the profile.
I am not using git as a data source but instead using S3 but it works, On my local when I run
http://localhost:8086/application/default
it returns
{
"name": "application",
"profiles": [
"default"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "s3:application",
"source": {
"environment.profile": "local",
on my pom I have set for spring boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath />
</parent>
Spring cloud is
<properties>
<java.version>16</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
Spring cloud is set
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Set starter config
<!-- config -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
in the application yml for the client I have set
spring:
profiles:
active: #activatedProperties#
application:
name: #artifactId#
config:
import: "configserver:"
cloud:
config:
enabled: true
uri: http://localhost:8086
#activatedProperties# is either local, dev, qa, or prod.
Is the problem the fact that profile in this case is local and the config server is expecting default.

Ok I fixed the problem. Looking at my settings
spring:
profiles:
active: #activatedProperties#
application:
name: #artifactId#
config:
import: "configserver:"
cloud:
config:
enabled: true
uri: http://localhost:8086
Config server will process it as follows
http://localhost:8086/my-client/local
my-client being the name of the application local being the profile. It needs to map to a yml file with all the config data on'
The yml file for this will be called my-client-local.yml. I will also have have
my-client-qa.yml, my-client-dev.yml, my-client-prod.yml so it picks up the right profile

Related

Flink-Kubernetes Azure Blob-storage and S3 FileSystem Implementation not found

I have Kubernetes hosted on Azure and I am trying to store Flink Streaming data to AWS S3 and Azure Blob-Storage.
I am using Flink Session cluster, created as below, for this task.
./bin/kubernetes-session.sh -Dkubernetes.cluster-id=<cluster_name>
To support "wasbs://" (zure Blob-store FS URI) and "s3://" (AWS S3 FS URI), I followed following steps as mentioned here.
Step 1: Login to Job Manager and under "plugins" directory, create plugin directory:
For S3
mkdir s3-fs-hadoop
mkdir s3-fs-presto
Step 2:
Copy the respective .jar files under the folder:
s3-fs-presto/flink-s3-fs-presto-1.13.0.jar
s3-fs-hadoop/flink-s3-fs-hadoop-1.13.0.jar
Step 3:
run the application.
PROBLEM:
Even after doing the above steps I am getting following exception every time:
Caused by: org.apache.flink.core.fs.UnsupportedFileSystemSchemeException: Could not find a file system implementation for scheme 's3'. The scheme is directly supported byFlink through the following plugins: flink-s3-fs-hadoop, flink-s3-fs-presto. Please ensure that each plugin resides within its own subfolder within the plugins directory.See https://ci.apache.org/projects/flink/flink-docs-stable/ops/plugins.html for more information. If you want to use a Hadoop file system for that scheme, please add the scheme to the configuration fs.allowed-fallback-filesystems. For a full list of supported file systems, please see https://ci.apache.org/projects/flink/flink-docs-stable/ops/filesystems/.
at org.apache.flink.core.fs.FileSystem.getUnguardedFileSystem(FileSystem.java:513)
at org.apache.flink.core.fs.FileSystem.get(FileSystem.java:407)
at org.apache.flink.streaming.api.functions.source.ContinuousFileMonitoringFunction.run(ContinuousFileMonitoringFunction.java:214)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:66)
at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:269)
TRIED:
I even enabled the plugins in my job manager YAML:
...
env:
- name: _POD_IP_ADDRESS
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: ENABLE_BUILT_IN_PLUGINS
value: flink-s3-fs-presto-1.13.0.jar;flink-s3-fs-hadoop-1.13.0.jar
Here I have added jars for only S3, but placed flink-azure-fs-hadoop-1.13.0.jar for Blob-storage and recieved the same exception, except that it shows the issue with "wasbs://" FileSystem.
Caused by: org.apache.flink.core.fs.UnsupportedFileSystemSchemeException: Could not find a file system implementation for scheme 'wasb'/'wasbs'
I even added the Azure Storage Account key in YAML for access.
YAML for S3:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"flink-jobmanager","namespace":"default"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"flink","component":"jobmanager"}},"template":{"metadata":{"labels":{"app":"flink","component":"jobmanager"}},"spec":{"containers":[{"args":["jobmanager","$(POD_IP)"],"env":[{"name":"POD_IP","valueFrom":{"fieldRef":{"apiVersion":"v1","fieldPath":"status.podIP"}}}],"image":"apache/flink:1.13.0-scala_2.12","livenessProbe":{"initialDelaySeconds":30,"periodSeconds":60,"tcpSocket":{"port":6123}},"name":"jobmanager","ports":[{"containerPort":6123,"name":"rpc"},{"containerPort":6124,"name":"blob-server"},{"containerPort":8081,"name":"webui"}],"securityContext":{"runAsUser":9999},"volumeMounts":[{"mountPath":"/opt/flink/conf","name":"flink-config-volume"}]}],"serviceAccountName":"default","volumes":[{"configMap":{"items":[{"key":"flink-conf.yaml","path":"flink-conf.yaml"},{"key":"log4j-console.properties","path":"log4j-console.properties"}],"name":"flink-config"},"name":"flink-config-volume"}]}}}}
creationTimestamp: "2021-07-22T09:34:02Z"
generation: 1
name: flink-jobmanager
namespace: default
resourceVersion: "4634197"
uid: bc8d7b32-6384-4ce2-ac87-e9f752d1fc17
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: flink
component: jobmanager
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: flink
component: jobmanager
spec:
containers:
- args:
- jobmanager
- $(POD_IP)
env:
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
image: apache/flink:1.13.0-scala_2.12
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 60
successThreshold: 1
tcpSocket:
port: 6123
timeoutSeconds: 1
name: jobmanager
ports:
- containerPort: 6123
name: rpc
protocol: TCP
- containerPort: 6124
name: blob-server
protocol: TCP
- containerPort: 8081
name: webui
protocol: TCP
resources: {}
securityContext:
runAsUser: 9999
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/flink/conf
name: flink-config-volume
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
items:
- key: flink-conf.yaml
path: flink-conf.yaml
- key: log4j-console.properties
path: log4j-console.properties
name: flink-config
name: flink-config-volume
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2021-07-22T09:34:38Z"
lastUpdateTime: "2021-07-22T09:34:38Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2021-07-22T09:34:02Z"
lastUpdateTime: "2021-07-22T09:34:38Z"
message: ReplicaSet "flink-jobmanager-678bdbd99c" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
Pom.xml of the flink code:
project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>FlinkScala</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Flink Quickstart Job</name>
<repositories>
<repository>
<id>apache.snapshots</id>
<name>Apache Development Snapshot Repository</name>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<flink.version>1.13.0</flink.version>
<target.java.version>1.8</target.java.version>
<scala.binary.version>2.12</scala.binary.version>
<scala.version>2.12.11</scala.version>
<log4j.version>2.12.1</log4j.version>
<mongodb.hadoop.version>1.3.0</mongodb.hadoop.version>
<!-- <hadoop.version>2.4.0</hadoop.version>-->
</properties>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-rabbitmq_2.11</artifactId>
<version>1.13.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<!-- <scope>compile</scope>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.apache.flink</groupId>-->
<!-- <artifactId>flink-core</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<!-- <scope>compile</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<!-- <scope>compile</scope>-->
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-connector-redis -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-redis_2.11</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>1.13.0</version>
<!-- <scope>test</scope>-->
</dependency>
<!-- Scala Library, provided by Flink as well. -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.flink:force-shading</exclude>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.apache.logging.log4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.FlinkS3</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- Java Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${target.java.version}</source>
<target>${target.java.version}</target>
</configuration>
</plugin>
<!-- Scala Compiler -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-nobootcp</arg>
<arg>-target:jvm-${target.java.version}</arg>
</args>
</configuration>
</plugin>
<!-- Eclipse Scala Integration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<!-- Add src/main/scala to eclipse build path -->
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<!-- Add src/test/scala to eclipse build path -->
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is that an issue with Flink API or am I missing something here?

hibernate-ogm apache ignite does not work

I am still trying to get my head around the whole OGM/Apache Ignite thing, I couldn't find an example on the net that worked.
So I tried this
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<h2.version>1.4.195</h2.version>
<ignite.version>2.4.0</ignite.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-ignite</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.jta</groupId>
<artifactId>narayana-jta</artifactId>
<version>5.4.0.Final</version>
</dependency>
</dependencies>
Ignite version 2.6.0 didn't work with hibernate-ogm 5.3.1 Final
TestOGM
package com.example;
import au.com.bueno.issue.issue.model.Breed;
import au.com.bueno.issue.issue.model.Dog;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.Ignition;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.*;
public class TestOgm {
public static void main(String[] args) throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
// Connect to the cluster.
Ignite ignite = Ignition.start();
ignite.cluster().active(true);
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"ogm-jpa-tutorial");
tm.begin();
EntityManager em = emf.createEntityManager();
Breed collie = new Breed();
collie.setName("Collie");
em.persist(collie);
Dog dina = new Dog();
dina.setName("Dina");
dina.setBreed(collie);
em.persist(dina);
Long dinaId = dina.getId();
System.out.println("dina " + dinaId);
System.out.println("em = " + em.find(Dog.class, 1L));
em.flush();
em.close();
tm.commit();
}
}
persistence.xml
<?xml version="1.0"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="com.arjuna.ats.jta.jtaTMImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImpl"/>
<property name="com.arjuna.ats.jta.jtaUTImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImpl"/>
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.ignite.impl.IgniteDatastoreProvider"/>
<property name="hibernate.ogm.ignite.configuration_class_name" value="com.example.configuration.ConfigurationBuilder"/>
</properties>
</persistence-unit>
I got this exception when I ran it
class org.apache.ignite.IgniteCheckedException: Failed to deserialize object with given class loader: sun.misc.Launcher$AppClassLoader#18b4aac2
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:147)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9847)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$SocketReader.body(ServerImpl.java:5913)
at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.hibernate.boot.registry.internal.StandardServiceRegistryImp
However, it kept going and I could see the output produced as below
21:25:39.828 [main] DEBUG
org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: 1, using strategy: org.hibernate.ogm.id.impl.OgmTableGenerator
dina 1
em = Dog{id=1, name='Dina', breed=Breed{id='5fc25a4d-c03c-4f2b-b5f9-9812a5c3dedb', name='Collie'}}
I can't seem to find the table Breed or Dog anywhere in the database. I tried to enable persistence storage to true, but I didn't know how to do it, the api for version 2.4.0 is not same as what's on the web site right now.
e.g I tried
Ignite ignite = Ignition.start();
ignite.cluster().active(true);
it didn't help.
How would I start bin/ignite.sh and activate cluster for it by using bin/control.sh --activate and then make my example above write to it?
Thanks & regards
Tin

Apache OpenWebBeans(CDI) + Servlet, injection not working

I am trying to get CDI working in tomcat 9.x. I followed the following links but still openwebbeans container did not inject the resource into the servlet
https://devlearnings.wordpress.com/2011/05/15/apache-openwebbeans-cdi-from-standalone-to-webapp/
https://dzone.com/articles/using-apache-openwebbeans
http://openwebbeans.apache.org/owbsetup_ee.html
Below is my servlet
package com.openwebbeans;
import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SampleController extends HttpServlet{
private static final long serialVersionUID = 1L;
#Inject
private SampleService service;
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
response.getWriter().print(service);
}
}
Below is the web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>OpenWebBeans</display-name>
<listener>
<listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>com.openwebbeans.SampleController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/sample</url-pattern>
</servlet-mapping>
</web-app>
Added the below line in server.xml
<Listener className="org.apache.webbeans.web.tomcat7.ContextLifecycleListener" />
Below is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openwebbeans</groupId>
<artifactId>openwebbeans-beginner</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>openwebbeans-beginner</name>
<url>http://maven.apache.org</url>
<properties>
<owb.version>2.0.0</owb.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_2.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.3_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-tomcat7</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.21.0-GA</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>openwebbeans-beginner</finalName>
</build>
</project>
Added the below jars under tomcat lib
geronimo-annotation_1.3_spec-1.0
geronimo-atinject_1.0_spec-1.0
geronimo-interceptor_1.2_spec-1.0
geronimo-jcdi_2.0_spec-1.0
openwebbeans-el22-2.0.0
openwebbeans-impl-2.0.0
openwebbeans-spi-2.0.0
openwebbeans-tomcat7-2.0.0
openwebbeans-web-2.0.0
xbean-asm5-shaded-4.5
xbean-finder-shaded-4.5
javassist-3.21.0-GA
Below are the server logs after deploying my war. It is clear from the logs that open web beans container has started
20-Jul-2017 10:06:08.315 INFO [http-nio-8080-exec-5]
org.apache.catalina.startup.HostConfig.deployWAR Deploying web
application archive
[D:\krishna\apache-tomcat-9.0.0.M22\webapps\openwebbeans-beginner.war]
20-Jul-2017 10:06:08.904 INFO [http-nio-8080-exec-5]
org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication
OpenWebBeans Container is starting... 20-Jul-2017 10:06:09.229 INFO
[http-nio-8080-exec-5]
org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication
OpenWebBeans Container has started, it took [325] ms. 20-Jul-2017
10:06:09.235 INFO [http-nio-8080-exec-5]
org.apache.catalina.startup.HostConfig.deployWAR Deployment of web
application archive
[D:\krishna\apache-tomcat-9.0.0.M22\webapps\openwebbeans-beginner.war]
has finished in [920] ms
Additionally i created openwebbeans.properties under META-INF/openwebbeans and added org.apache.webbeans.spi.ContainerLifecycle=org.apache.webbeans.lifecycle.StandaloneLifeCycle to it. But it still does not work
I also tried with org.apache.webbeans.spi.ContainerLifecycle=org.apache.webbeans.web.lifecycle.WebContainerLifecycle but nothing seems to work.
Can anyone please help me get this working?
If you need injection in servlets then you need a deeper integration than just the servlet listener. We provide this with the openwebbeans-tomcat7 plugin.
The easiest way is to use our installer as explained in our announce mail
https://lists.apache.org/thread.html/15b8cbcdbcc24942dae6d277d75363103a9d45d59047fda0e6abcbbe#%3Cannounce.apache.org%3E
In that case just remove the whole WebBeansConfigurationListener from your web.xml. This is intended if you like to integrate in 'unpimped' servlet containers or if you run in GAE, etc. In which case you can work around with using CDI.current() to get your CDI bean in a Servlet.
You also don't need any javassist dependency anymore. That got removed in OWB-1.2.x a long time ago.
Feel free to ping us on our mailing lists or irc at #openwebbeans on freenode.net!
Oh and another tip: you could try out our Apache Meecrowave container, which is OWB + Tomcat9 + CXF + Johnzon - all in 9MB. It includes a maven-plugin, an Arquillian container, etc.

Arquillian, tomee-embedded and JAX-RS

I am using Arquillian with a tomee-embedded container in order to test my JAX-RS web service. In my test case, I am running a jersey test client accessing the provided resource. However, the test always results in a 404 NOT FOUND status when accessing the resource.
When deploying the same project on my tomee-jaxrs instance, the resource is provided properly.
These are the maven dependencies that I've included in my test project:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<scope>test</scope>
<type>pom</type>
</dependency>
My test case looks as follows:
#RunWith(Arquillian.class)
public class DemoTest {
#Deployment
public static WebArchive createDeployment() throws Exception {
return ShrinkWrap.create(WebArchive.class).addPackage(Controller.class.getPackage()).setWebXML("ch/codenation/test/regression/resources/container/WEB-INF/web.xml");
}
#ArquillianResource
private URL url;
#Test
public void testGetData() throws Exception {
final IApplicationLayer applicationLayer = new JaxRsApplicationLayer(url.toURI());
final Callable<String> dataProvider = new DataProvider(applicationLayer);
Assert.assertEquals("asdf", dateProvider.call());
}
}
As well as my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>codenation-service</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
The JAX-RS resource is indeed unavailable, for when I put a breakpoint in the test method and try to access the resource in the browser, I receive a 404 message. Doing the same thing when deplyoing the archive to a tomee-jaxrs server works fine, however. Are there any additional maven dependencies or arquillian configuration settings I need to add here in order to make this work?
Thanks for any feedback and best regards
Pascal
Just include this in your pom.xml
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>tomee-jaxrs</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
and you can work with the embedded TomEE.
There seems to be no way to switch the tomee-embedded adapter to a plus configuration. I therefore switched over to the tomee-remote adapter.

how to test an REST app (built with apache-cxf) with jersey-test-framework

I would like to know how I can test an REST application, which is developed using Apache CXF and Spring, with the Jersey Test Framework (JTF).
The application is made of several Maven modules, of which "app-rest" is the one that integrates them and exposes the REST interface to be tested.
I've made a separate Maven module that contains the tests, which has the "app-rest" as dependency, but I'm receiving an exception like this :
BeanDefinitionStoreException: IOException parsing XML document from class path resource
when running the tests.
I think that's because the app-rest is not properly deployed in the embedded container.
I've tried to put the tests into the "app-rest" module, but I get this instead :
RuntimeException: The scope of the component class org.apache.cxf.jaxrs.provider.AtomFeedProvider must be a singleton
I'm running the test with this command line:
mvn test -Dtest=JerseyRestTest -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory
These is my pom.xml file for the tests module:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>project-group-id</groupId>
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>project-group-id</groupId>
<artifactId>integration-tests</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Integration Tests of REST interface</name>
<!-- build -->
<build>
<finalName>${project.artifactId}</finalName>
</build>
<!-- additional repositories -->
<repositories>
<repository>
<id>java.net.m2</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>project-group-id</groupId>
<artifactId>app-rest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>war</type>
<scope>test</scope>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Jersey stuff -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The simple test is:
public class JerseyRestTest extends JerseyTest {
public JerseyRestTest() {
super(new WebAppDescriptor.Builder("projectname.resource")
.servletClass(SpringServlet.class)
.contextParam("contextConfigLocation", "classpath:META-INF/spring/context-rest.xml")
.contextListenerClass(org.springframework.web.context.ContextLoaderListener.class)
.contextPath("app-rest")
.build());
}
#Test
public void testSomeResource() {
String response = resource().path("/rest/resources").get(String.class);
Assert.assertNotNull("No text returned!", response);
assertResponseContains(response, "<html>");
assertResponseContains(response, "</html>");
}
protected void assertResponseContains(String response, String text) {
Assert.assertTrue("Response should contain " + text + " but was: " + response, response.contains(text));
}
}
Thank you very much!