Loading properties file while running camel blueprint test - apache-camel

I am using property-placeholder tag to load a properties as follows:
<cm:property-placeholder id="myblueprint.test" persistent-id="camel.blueprint"/>
While deploying my project on JBOSS Fuse, it will load camel.blueprint.cfg from /etc/ directory of FUSE, and when I deploy project on a fabric profile, it will read from properties file created in profile.
But, when I run camel blueprint test, how can I configure it to load properties file from a particular location?

After browsing the documentation for property-placeholder, I got the solution. We can set the location for properties file in test case file as follows:
#Override
protected String[] loadConfigAdminConfigurationFile() {
// String[0] = tell Camel the path of the .cfg file to use for OSGi ConfigAdmin in the blueprint XML file
// String[1] = tell Camel the persistence-id of the cm:property-placeholder in the blueprint XML file
return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"};
}
Please ensure that, property file is having extension .cfg. otherwise it will be ignored.

Related

How to add a version number to war file in web application development?

I am a beginar of m2e application development by using eclipse(kepler) and my server is jboss 7.1.1 final.I have two war files,one is for client and second is for server .I have an url pattern such as "myproject.com".Now my question is I want to access the data which is present in server war file even I made a changes i.e added the version number to war file for example "Server.war" to "Server0.0.1-SNAPSHOT.war" by using pom.xml file of my project.Would you please explain me what are the changes I need to do in my pom.xml file.
Thanks in advance,
Prasad
I am assuming that you want to keep the same web context despite the war file's name or whatever... In Jboss AS7 you can set the war's context root using the jboss-web.xml deployment descriptor. Just create the file into your_war/WEB-INF folder with this content,
<jboss-web>
<context-root>Server.war</context-root>
</jboss-web>
With maven you can package/install the war using a custom name and concat the version number if you want.
Set a custom name using <finalName> tag inside the build section, for example:
<finalName>ServerAnotherName-${project.version}</finalName>
Removing the tag, the default name will be ${project.artifactId}-${project.version}

package/packagescan tag in Apache camel

Trying to load the routes from .xml file.Instead of using import resource,or "route context ref".
So i wrote a Routebuilder class with following code
InputStream is = getClass().getResourceAsStream("barRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
and loaded the routes at the time of camelcontext loading.
using
com.***.Loadroutes
I am able to load routes from xml file in standalone.
But when i deploy the bundle to fuse container,routes are not loading from xml file.
How to use package/packagescan in blurprint/spring to run inside fuse
note :made project as osgi specific bundle and normal bundle(mvn camel:run).

In which folder to store text files in Google App Engine project and how to retrive them?

I want to store text on google app engine. In which folder do I need to store them, and how to get the path of the file ?
I have tried storing them in WEB-INF folder and I have tried following path to retrive file:
FILE_PATH="/RESTful Jersey App/war/WEB-INF/abc.txt"
If you want to access this file anywhere, you put it in the /war folder or any subfolder within it. To retrieve it:
FILE_PATH="abc.txt"
If you want to access this file internally in your server code, you put it in the WEB-INF folder. Then you use:
FILE_PATH="/WEB-INF/abc.txt"
As stated above you can place it anywhere inside your war folder if you wish to make it publicly accessible, if you need that file to be accessible only to your app (eg a PK12 secret file) you need to place it within the WEB-INF folder.
I order to actually retrieve it you need to get the real path from your current ServletContext eg:
ServletContext context =//your servlet context (either injected into and endpoint or gotten in an actual Servlet.
String path = context.getRealPath("<path starting form the base WAR dir>");
try {
FileInputStream input = new FileInputStream(path);
template = CharStreams.toString(new InputStreamReader(input, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}

How can I configure the JAX-RS base path in TomEE+?

I have a WAR with some JAX-RS services, deployed into TomEE Plus. Given a service annotated with #Path("myservice"), TomEE+ publishes it to localhost:8080/mywebapp/myservice.
However, that also makes accessing a JSP at localhost:8080/mywebapp/index.jsp impossible - JAXRSInInterceptor complains that No root resource matching request path has been found, Relative Path: /index.jsp.
So I would like to configure a path prefix api to all services, which changes the myservice URL to localhost:8080/mywebapp/api/myservice. Doing so would be trivial if I had configured CXF on my own (with or without Spring), because I could simply change the URL pattern of the CXF Servlet - but I am relying on the default settings where I don't configure anything besides the annotations. So how do I do that in this case?
Note that I don't want to alter the #Path annotations to include the prefix, because that does not fix the issue with the JSP.
Create an extension of javax.ws.rs.core.Application and annotate it with #ApplicationPath where value would be api in your case:
#ApplicationPath("/api")
public class MyApplication extends Application {
#Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register root resource
classes.add(MyServiceResource.class);
return classes;
}
}
This way a Servlet 3 container would find your application and map your resource to /mywebapp/api/myservice while making your web resources (.jsp) available at /mywebapp.
TomEE trunk supports these configurations: cxf.jaxrs.staticSubresourceResolution & cxf.jaxrs.static-resources-list
but the #ApplicationPath is the more relevant solution IMO
Using -Dopenejb.webservice.old-deployment=true can help too in some cases

Retrieve file relative to play application path

I created a Play! app and deployed it under TomCat. This works well. The only problem is the management of a properties file, currently in the conf folder right next to application.conf. But as soons as the client replaces the war file the custom properties are overwritten with the default values, resulting in errors.
Now I want to introduce a seperate properties file placed inside the webapps folder. This way I will be sure my clients will not overwrite the file 'accidentally'.
So the structure would be:
TomCat webapps:
myPlayApp
PlayConfig <-- here I want to place the config file
So I would like to retrieve the properties file by something like:
getFile("../PlayConfig/app.properties");
This obvious does not work, but I do not know how to achieve this?
I thought retrieving it by tomcat http url but the portnumber my vary, so this would also not work, I guess...
UPDATE 2012-01-25:
Actually when using the following code:
Play.applicationPath.getPath();
I get the absolute path when running the project outside tomcat (so not inside war file!)
When I deploy the same project in a TomCat server I get the following output:
W:\tomcat-5.5\webapps\MyTestProject\WEB-INF\application.
From this point on I can indeed use a relative path.
I think that when deployed in a Servlet container, play uses the /WEB-INF/application as base directory.
Try changing the path relative to this folder.

Resources