Spring without XML on Karaf - spring

I have WAR that need to be deployed on karaf. The war uses spring also it is written in servlet3 standards, using annotations both for servlets and spring(viz. no web.xml and other xmls).
When I Deploy the the web application, the web bundle starts without any erros. But the problem is I cannot access the application from Webbrowser(Was able to access when I deployed in tomcat 7).
I Installed the following features
spring(3.2.11.RELEASE_1)
spring-web
war
http
spring-dm(dont know whether its required actually)
pax-war.
This is the bundle plugin configuration
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>1.0.0</Bundle-Version>
<Export-Package>com.welflex.notes,com.welflex.notes.rest.*, com.welflex.notes.spring.security</Export-Package>
<Import-Package>*</Import-Package>
<Web-ContextPath>/osgiwar</Web-ContextPath>
<_wab>src/main/webapp</_wab>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>3.0.3</version>
<extensions>true</extensions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>feature</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
<aggregateFeatures>true</aggregateFeatures>
<includeTransitiveDependency>true</includeTransitiveDependency>
</configuration>
</plugin>
This is the result of the commands that i issued in karaf.
karaf#root(feature)> web:list
ID | State | Web-State | Level | Web-ContextPath | Name
--------------------------------------------------------------------------------
271 | Active | Deployed | 80 | /osgiwar | Notes-webapp (1.0.0)
karaf#root(feature)> http:list
ID | Servlet | Servlet-Name | State | Alias | Url
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
254 | Proxy162313f6_071f_4c85_800e_359cd95ed681 | ServletModel-10 | Deployed | /features | [/features/*]
271 | JspServletWrapper | jsp | Deployed | | [*.jsp, *.jspx, *.jspf, *.xsp, *.JSP, *.JSPX, *.JSPF, *.XSP]
271 | ResourceServlet | default | Deployed | / | [/]
252 | ResourceServlet | /res | Deployed | /system/console/res | [/system/console/res/*]
252 | KarafOsgiManager | ServletModel-2 | Undeployed | /system/console | [/system/console/*]
255 | Proxy5832af65_c1ab_4f7a_b858_6b151c28af79 | ServletModel-12 | Deployed | /gogo | [/gogo/*]
121 | CXFNonSpringServlet | ServletModel-14 | Deployed | /cxf | [/cxf/*]
252 | KarafOsgiManager | ServletModel-5 | Deployed | /system/console | [/system/console/*]
253 | Proxy0096643a_4c37_499e_a368_e90dd315172f | ServletModel-8 | Deployed | /instance | [/instance/*]
Is it possible deploy this spring webapplication on the Karaf.??? ... Can somebody point out what I am doing wrong here..
Thanks,
NA

Related

Is it possible to deploy a maven multimodule project as a single artifact on Nexus?

I have a maven multi-module project similar to this:
- myService-parent
| - myService
| - myService-openApiDocs
| - miService-eventsDefinition
That I would like to deploy on Nexus as a single artifact, like this:
Maven-repo
|- myService
| | - <version>
| | - maven-metadata.xml
| | - <my service artifact>
| | - myService.pom
| | - myService.jar
| | - myService-openApiDocs.zip
| | - myService-eventsDefinition.json
With the maven-metadata.xml similar to this:
<metadata modelVersion="1.1.0">
<groupId>com.myCompany</groupId>
<artifactId>myService</artifactId>
<version>...</version>
<versioning>
<snapshot>
<timestamp>...</timestamp>
<buildNumber>...</buildNumber>
</snapshot>
<lastUpdated>...</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<classifier>open-api-docs</classifier>
<extension>zip</extension>
<value>...</value>
<updated>...<updated>
</snapshotVersion>
<snapshotVersion>
<extension>jar</extension>
<value>...</value>
<updated>...</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>...</value>
<updated>...</updated>
</snapshotVersion>
<snapshotVersion>
<classifier>event-definitions</classifier>
<extension>json</extension>
<value>...</value>
<updated>...</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
But actually what I obtain on Nexus is the creation of one different artifact for each module, like this:
Maven-repo
|- myService-parent
| | - <version>
| | - maven-metadata.xml
| | - <my service-parent artifact>
| | - myService-parent.pom
|- myService
| | - <version>
| | - maven-metadata.xml
| | - <my service artifact>
| | - myService.pom
| | - myService.jar
|- myService-openApiDocs
| | - <version>
| | - maven-metadata.xml
| | - <my service-openApiDocs artifact>
| | - myService-openApiDocs.pom
| | - myService-openApiDocs.zip
|- myService-eventsDefinition
| | - <version>
| | - maven-metadata.xml
| | - <my service-eventsDefinition artifact>
| | - myService-eventsDefinition.pom
| | - myService-eventsDefinition.json
How can I define in maven the structure that the multi-module project has on nexus?
No, there is no sensible way of doing this.
If you want one artifact in Nexus, then refactor the project to a single-module project that generates two attached side artifacts.

How to share Hazelcast cache over multi-war Tomcats

We have multiple Tomcats, each with multiple .war files (= Spring Boot app) deployed in it.
We now need some distributed caching between app1 on tomcat1 and app1 on tomcat2. It´s essential that app2 on tomcat1 (and app2 on tomcat2) cannot see the Hazelcast cache of the other deployed apps.
The following image shows this situation:
Tomcat 1 Tomcat 2
+-----------------------------------+ +-----------------------------------+
| | | |
| app1.war app2.war | | app1.war app2.war |
| +----------+ +----------+ | | +----------+ +----------+ |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| +----+-----+ +----+-----+ | | +----+-----+ +-----+----+ |
| | | | | ^ ^ |
+-----------------------------------+ +-----------------------------------+
| | | |
| | | |
| | | |
| | | |
+--------------------------------------+ |
Shared cache via Hazelcast | |
| |
+---------------------------------------+
Shared cache via Hazelcast
Is this possible with Hazelcast? And if so, how?
Right now I only find solution talking about shared web sessions via Hazelcast. But this doesn´t seem to be a solution for me here, or am I wrong?
If your applications must be strictly isolated, then you probably need to use different cluster groups. Cluster groups make it possible for different clusters to coexist on the same network, while being completely unreachable to one another (assuming correct configuration).
If, however, you just need application data to be separate, then you can just make sure that app1 instances use caches with names that do not clash with app2 cache names. This is the simplest implementation.
If you are deploying a sort of multitenant environment where you have security boundaries between the two groups of applications, then going for the cluster group option is better as you can protect clusters with passwords, and applications will be using distinct ports to talk to one another in those groups.
Yes, this is possible.
You can configure the cache name.
Application app1 uses a cache named app1. Application app2 uses a cache named app2.
If you configure it correctly then they won't see each's others data.
If by "essential" that they can't you mean that you have a stronger requirement than preventing accidental mis-configuration, then you need to use role-based security.

How to run flyway:migrate on a cloned database

We have a production database and we maintain it by using flyway. Recently we cloned our production database to create a UAT database. The UAT database has the same schema and data as that in production. Now we try to run "mvn flyway:migrate" on the UAT database to test new flyway script. However, we got
+---------+-----------------------+---------------------+---------+
| Version | Description | Installed on | State |
+---------+-----------------------+---------------------+---------+
| 0.0.1 | script.1 | | <Baseln |
| 0.0.2 | script.2 | | <Baseln |
| 0.0.3 | script.3 | | <Baseln |
| 0.1.1 | script.4 | | <Baseln |
| 0.1.2 | script.5 | | <Baseln |
| 0.2.0 | script.6 | | <Baseln |
| 0.5.1 | script.7 | | <Baseln |
| 0.5.2 | script.8 | | <Baseln |
| 0.6.0 | script.9 | | <Baseln |
| 0.7.0 | script.10 | | <Baseln |
| 0.8.0 | script.11 | | <Baseln |
| 0.9.0 | script.12 | | <Baseln |
| 0.10.0 | script.13 | | <Baseln |
| 0.11.1 | script.14 | | <Baseln |
| 0.12.0 | script.15 | | <Baseln |
| 0.13.0 | script.16 | | <Baseln |
| 0.14.0 | script.17 | | <Baseln |
| 0.15.0 | script.18 | | <Baseln |
| 0.16.0 | script.19 | | <Baseln |
| 0.16.1 | script.20 | | <Baseln |
| 0.17.0 | script.21 | | <Baseln |
| 0.17.1 | script.22 | | <Baseln |
| 0.18.0 | script.23 | | <Baseln |
| 1 | << Flyway Baseline >> | 2016-11-07 08:11:33 | Baselin |
| 1.16.0 | script.19 | 2017-02-15 10:03:18 | Future |
| 1.16.1 | script.20 | 2017-02-15 10:03:18 | Future |
+---------+-----------------------+---------------------+---------+
The script.23 is a new script. We expect the state is pending.
However, the state of all scripts became Baseln. I searched the relating topics for a day but could not find scenarios closed to my case. Is there any configuration on flyway (maven) I can use to run migrate command on a cloned database? Please help. (My database is SQL Server 2014, flyway version 4.0 ,maven version is 3.5, JDK version 1.7)
Thanks a lot.
Chi-Fu
I think that all versions lower than the baseline are not executed - they are supposed to belong to the baseline.
If script.23 is a new migration it should have a version greater than the last version, typically 1.18.0 (According to standard flyway config, V1_18_0__script.23.sql rather than V0_18_0__script.23.sql).
After having renamed this file, do a repair before trying to migrate again.

SonarQube 4.5 does not populate technical debt with mysql datasource

I mvn sonar:sonar a project and problems with our code is recorded in the technical debt in sonarqube when we use the default database - i.e. default install of version 4.5. It works, out of the box:
Blocker 0
Critical 0
Major 88
Minor 70
Info 12
I change the datasource to mysql and
Blocker 0
Critical 0
Major 0
Minor 0
Info 0
is recorded. No errors presented by mvn or sonar. I can see all drivers load during mvn run.
In .m2/settings.xml I have
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>
jdbc:mysql://sonar.company.io:3306/sonar?useUnicode=true&characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>pass</sonar.jdbc.password>
<sonar.host.url>
http://sonar.company.io:9000
</sonar.host.url>
<sonar.verbose>true</sonar.verbose>
</properties>
</profile>
I can am able to connect via the hostname using mysql -usonar -ppass -h sonar.company.io and there is content in the database.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| sonar |
mysql> show table status;
+---------------------------+--------+---------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+---------------------------+--------+---------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------+----------+----------------+---------+
| action_plans | InnoDB | 10 | Compact | 0 | 0 | 16384 | 0 | 16384 | 4194304 | 1 | 2014-09-30 14:30:17 | NULL | NULL | utf8_bin | NULL | | |
| active_dashboards | InnoDB | 10 | Compact | 5 | 3276 | 16384 | 0 | 32768 | 4194304 | 6 | 2014-09-30 14:30:10 | NULL | NULL | utf8_bin | NULL | | |
| active_rule_parameters | InnoDB | 10 | Compact | 42 | 390 | 16384 | 0 | 0 | 4194304 | 43 | 2014-09-30 14:30:16 | NULL | NULL | utf8_bin | NULL | | |
| active_rules | InnoDB | 10 | Compact | 1099 | 74 | 81920 | 0 | 49152 | 4194304 | 992 | 2014-09-30 14:30:18 | NULL | NULL | utf8_bin | NULL | | |
What could be the reason?

I get 404 Not found | Install war project in Karaf 3 from userguide

I can install a war but not to test it , why ????
From Karaf tuto I have done :
karaf#root()> bundle:install -s "webbundle:http://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Web-ContextPath=/sample"
Bundle ID: 150
karaf#root()> list |grep tom
150 | Active | 80 | 0 | tomcat-sample
karaf#root()> web:list
ID | State | Web-State | Level | Web-ContextPath | Name
123 | Active | Deployed | 80 | /sample | tomcat-sample (0)
When I go to [http://loxcalhost:8181/sample] it's not working , why ???
The sample war doesn't contain a welcome section in it's web.xml and therefore nothing happens if you call localhost:8181/sample you have to go for localhost:8181/sample/hello as that's the registered servlet for this web-application.
If you issue a http:list command you'll get the following listing:
karaf#root()> http:list
ID | Servlet | Servlet-Name | State | Alias | Url
---------------------------------------------------------------------------------------------------------------------------
103 | JspServletWrapper | jsp | Deployed | | [*.jsp, *.jspx, *.jspf, *.xsp, *.JSP, *.JSPX, *.JSPF, *.XSP]
103 | ResourceServlet | default | Deployed | / | [/]
103 | | HelloServlet | Deployed | | [/hello]

Resources