Karaf v4.0.8 : Multiple Blueprints cannot load configuration from same persistent-id - karaf

Update: It took a little time to realize for some reason but I see that configuration files are bundle PID specific and by trying to load the same cfg file in blueprint within two different bundles, I was creating a race condition. Make sure you use the cfg files in their target bundles only.
Note: The above applies only to blueprint bundles. If you do not depend on OSGI ConfigAdmin service to keep the bundles dynamically and want to use the cfg files from something like a Camel context, that should be fine.
I have 2 blueprints deployed through karaf 4.0.8 'deploy' folder. Both have the following common section:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint https://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder id="common" persistent-id="common" update-strategy="reload" placeholder-prefix="$(" placeholder-suffix=")"/>
<cm:property-placeholder id="sqlcfg" persistent-id="12345" update-strategy="reload" placeholder-prefix="$[" placeholder-suffix="]">
</cm:property-placeholder>
I would like to load configuration common to both from 'common'. However, when they share the same persistentId and properties file from the 'etc' folder, the blueprint to be deployed second keeps loading and unloading.
If I get them to load from different files - it all works.
Any ideas from the community why I have this behaviour?
Thanks in advance.

In my experience, you either set a different persistent-id or set update-strategy="none". This will stop the second module from going into that loading/unloading loop.
The downside is that you lose the auto refresh of the config file.

Related

Apache Camel reference property files with and without OSGI

I understand that if you deploy your Camel project to an OSGI environment like Karaf you can simply write:
<cm:property-placeholder id="INT001_********_Properties" persistent-id="INT001_SelfServiceMachine" />
<camelContext xmlns="http://camel.apache.org/schema/blueprint"
id="INT001_SelfServiceMachine" useMDCLogging="true">
<propertyPlaceholder id="properties" location="blueprint:INT001_*********_Properties"/>
And this works when the project is deployed to Karaf and the property file is located there in the etc folder.
But how can you configure it when Karaf is not available?
I used this bean before:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:some.properties"
/> </bean>
But is there a single way to refer to property files regardless of when you are in Karaf or when you are in your e.g. Eclipse environment and your property file is in your /src/resources folder and the bean above works? For instance, when you use Jenkins and and want to run tests and build the bundle, you may not have Karaf available.
Thanks for any input on this.
You can maybe implement your own PropertiesResolver which know how to resolve your properties according to the runtime environment. If OSGi is detected, then it can use ConfigurationAdmin, else it can use a static properties file.
Personally, I use something more simple thanks to Spring DM: my beans/configurations are dispatched in multiples files, and all the configuration related to OSGi is regrouped in one file. In Karaf, Spring DM load all XML in META-INF/spring. Outside of Karaf, I filter the XML to exclude the OSGi configuration.
There is a blueprint noosgi bundle around, that one can be used to have the blueprint capabilities outside of the osgi container. With this you're able to stick to your blueprint xml, though you need to change from configuration admin service for property lookup to native blueprint property replacement.

Error 404 Not Found Loading Bootstrap Glyphicons with Spring MVC

I'm building a maven web application using Spring 3.0.5 MVC, AngularJS 1.5 and Boostrap 3.3.6.
All front-end resources are under webapp/resources/[js,css,fonts].
I've add <mvc:resources mapping="/resources/**" location="/resources/" /> to my spring configuration file.
My issue is that i'm not able to get glyphicons-halflings-regular.xxx files. I got a 404 not found error. (exemple with http://localhost:8080/my-app/resources/fonts/glyphicons-halflings-regular.woff)
I run my app with maven jetty plugin.
any hints?
Thanks in advance
Check that your font files are being copied to the target folder you expect them to be copied to. In your case, you should end up with the *.woff files under ~target/my-app/resources/fonts.
If the files are not in the correct/expected target location, check that you have correctly defined the resources element in your pom, and you're including the *.woff files.
Based on what you've said, I would expect your files to be placed into ~/target/my-app/[js,css,fonts] rather than ~/target/my-app/resources/[js,css,fonts]. If you see them there, then you can either remove the /resources portion of the links, or move the resources under /src/main/resources/resources.
If there are no *.woff files in the target folder at all, check the <resource> element of your pom and make sure you're including all the file types you want. If you need more control, take a look at the copy-resources goal of the maven-resources-plugin here: https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
Edit
I just noticed that you put your resources under /src/main/webapp/resources. Since this isn't the standard resource source folder, you can either move the resources into /src/main/resources or add the directory /src/main/webapp/resources to your resource list in the pom.

Using blueprint as the Apache Camel DSL to describe routes in IBM Liberty

My goal is to get Camel running under IBM Liberty application server using OSGi and be able to describe the DSL (Domain Specific Language) routes in Blueprint. I am making progress and now have a Liberty environment with Camel installed and configured as OSGi bundles. When I write a Java DSL Camel app as an OSGi bundle, all works exactly as I might hope.
My last step is to be able to describe my camel routes in Blueprint. To that end I create a new OSGi bundle and defined a blueprint.xml that looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camelBlueprint="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint-2.14.1.xsd">
<camelBlueprint:camelContext>
<camelBlueprint:route>
<camelBlueprint:from uri="file:c:/temp/in"/>
<camelBlueprint:to uri="file:c:/temp/out"/>
</camelBlueprint:route>
</camelBlueprint:camelContext>
</blueprint>
When I attempt to deploy this OSGi bundle, the IBM Liberty OSGi framework fails to deploy the application with the following errors:
[3/2/15 0:42:38:796 CST] 00000035 com.ibm.ws.app.manager.esa.internal.DeploySubsystemAction
A CWWKZ0403E: A management exception was generated when trying to install the application Camel1 into an OSGi framework. The error text from the OSGi framework is:
Resource does not exist: org.apache.aries.subsystem.core.archive.SubsystemContentRequirement:
namespace=osgi.identity, attributes={}, directives={filter=(&(osgi.identity=OSGITest1)(type=osgi.bundle)(version>=1.0.0))}, resource=org.apache.aries.subsystem.core.internal.SubsystemResource#7bc2d3bc
Unfortunately this is where I am now stumped and stuck. I believe that IBM Liberty uses Equinox as the OSGi platform and not Karaf but reading the Camel Blueprint docs I seem to understand that Apache Aries is required (which Liberty supplies and uses) and that Karaf isn't a dependency.
My MANIFEST.MF for my test bundle is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OSGITest1
Bundle-SymbolicName: OSGITest1
Bundle-Version: 1.0.0.qualifier
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: kolban.osgitest
Import-Package: org.apache.camel;version="2.14.1",
org.apache.camel.blueprint;version="2.14.1"
this message can occur if the resolver can't see the bundle, or there's something wrong with the bundle (typically with the Blueprint). If the bundle resolves ok when you remove the blueprint, then you need to look at what might be wrong in the blueprint. If this is the case, I would suspect you don't have the Camel blueprint namespace handler enabled in the runtime.
I hope this helps.
Regards, Graham.

Can DropWizard serve assets from outside the jar file?

In looking at the documentation, it appears that DropWizard is only able to serve static content living in src/main/resources. I'd like to keep my static files in a separate directory outside the jar file. Is that possible? Or do most people use nginx/Apache for their static content?
yes, it can, using this plugin - https://github.com/bazaarvoice/dropwizard-configurable-assets-bundle
Working off of Marcello Nuccio's answer, it still took me the better part of my day to get it right, so here is what I did in a bit more detail.
Let's say I have this directory structure:
my-dropwizard-server.jar
staticdocs
assets
image.png
Then this is what you have to do to make it work:
1) In your dropwizard Application class, add a new AssetsBundle. If you want your assets to be served from a different URL, change the second parameter.
#Override
public void initialize(Bootstrap<AppConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/", "/assets/"));
}
2) Add the document root to your classpath by configuring the maven-jar-plugin like this. (Getting the "./staticdocs/" in the correct form took me a while. Classpaths are unforgiving.)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Class-Path>./staticdocs/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
3) This step is entirely optional. If you want to serve your Jersey REST Resources from a different root path (e.g. "app"), add the following to your configuration YML:
server:
rootPath: /app/*
Now you can access your static content like this, for example:
localhost:8080/assets/image.png
The user manual says:
use an extended AssetsBundle constructor to serve resources in the assets folder from the root path.
i.e. the files are loaded as resources from the classpath. Then you only need to properly set the classpath for the service.
With the default configuration, this means that you need to call the document root assets, and put the parent folder of the document root in the classpath. Then, for example, assets/foo.html will be available at
http://localhost:8080/assets/foo.html
There is a upto-date dropwizard-configurable-assets-bundle maintained at official dropwizard-bundles. You can find it at github https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle. Current version supports dropwizard 0.9.2
This can be used to serve static files from arbitrary file system path.
The vast majority of websites that serve static content do so through a dedicated webserver, or, at larger scale, a CDN.
Occasionally, you might want to deploy an application as a self-contained unit complete with all assets which is where Dropwizard comes in.
It is possible to get Dropwizard to serve up assets from outside the classpath, but the easiest way to do this is to write your own asset endpoint that reads from an externally configured file path.
To complement craddack's answer: Correct, you can use the regular AssetsBundle as long as you add the assets to your classpath.
If you use gradle and oneJar, you can add a directory to the classpath in the oneJar task:
task oneJar(type: OneJar) {
mainClass = '...'
additionalDir = file('...')
manifest {
attributes 'Class-Path': '.. here goes the directory ..'
}
}
see https://github.com/rholder/gradle-one-jar

Unable to download mp4 from sharepoint 2010 on mobile, but non-mobile works fine

We've got a SharePoint site with a custom application that is designed for both web and mobile that we are trying to upgrade from SP2007 to SP2010. The site contains playlists of mp4 files. We have asp.net session state active on the site for use within the custom application. We also rewrite urls to HTTPS.
The files are stored on disk and accessed through a virtual directory.
When the files are accessed through the SP2010 web site (non-mobile), the mp4 file plays just fine.
When the exact same url is accessed from a mobile browser, we receive the message:
Session state can only be used when enableSessionState is set to true, either in a
configuration file or in the Page directive. Please also make sure that
System.Web.SessionStateModule or a custom session state module is included in the
<configuration>\<system.web>\<httpModules> section in the application configuration.
We DO have the SessionStateModule declared in <configuration>\<system.webServer>\<modules> as follows:
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
We have also tried without the preCondition, and with preCondition="integratedMode".
An example of the url is https://example.com/Assets/Job63/8f9e85d5-d7f3-4536-a9b1-69537b7da9bf/Previews/0568145f-b314-4354-a081-d72019a42d11.mp4 (the domain has been changed to protect the innocent).
The virtual directory is /Assets and it points to a c:\Assets directory.
This behavior occurs even using FireFox and changing the user agent to simulate mobile, so it appears to be something intercepting mobile requests.
None of the other sessionstate answers on the site appear to cover this problem.
We also have the SessionStateModule declared in the IIS Module list for the website.
What may be causing this problem?
We were able to resolve the issue by putting a web.config file containing the following into the assets folder. It is apparently the aggressive mobile redirect that SharePoint does in SP2010 that causes the problem, as explained at the following url - http://blog.mastykarz.nl/inconvenient-sharepoint-2010-mobile-redirect/ .
web.config contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<browserCaps>
<result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<filter>isMobileDevice=false</filter>
</browserCaps>
</system.web>
</configuration>

Resources