How to remotely view html files using OSGI - java

I am very new to enterprise technologies and web development and my current project has me stuck in a tough spot. I am using OSGI and trying to use HelpGUI my previous OSGI question and I cannot get a 3rd party library to display my html files from Java. Instead can I use OSGI or some other library to host those html files locally? I could then use Java to pop open a browser that points to the index.html on localhost right?
Let me know if my train of thought is sound. I googled for tutorials, but they take me down paths which I believe are overly complicated or do not get my html files available to the browser. Can someone start me in the right direction?

There is a simple way of doing this.
You need to host the html files inside OSGi and publish them over HTTP.
Hosting
One option (probably the simplest one) is to package them inside the jar of your bundle.
Publish over HTTP
The OSGi spec includes a small embedded web server and an API for publishing content in it.
The related service you need to use is called HttpService. Check the OSGi specification or the javadoc of the HTTPService to see how to use it.
You can publish servlets or plain resources - for your case the latter is enough.
You have to provide a short HttpContext class, which knows how to find your html files - e.g. by using
public URL getResource(String name) {
return (getClass().getResource(name));
}
You can check the HTTP Demo available in ProSyst's mBedded Server - it does exactly what you need.
Note that in some OSGi frameworks the HTTP Service maybe won't be installed by default - check what additional bundles are available in the installation and whether you have to install smth additional to make it available in the OSGi registry.

Related

CMS external upload of files

I am looking for a java based CMS that exposes an API for external file upload.
So for instance I have a Tomcat server with a running CMS. I also have a (standalone) client that needs to add content to the CMS automatically (without user interference).
I already looked into Liferay (using Jackrabbit) but there is no way to upload documents/files from a client.
Does anyone know of a java CMS where this is possible ?
Thanks!
Coenos
If you are ready to take time in coding then you could make use of Liferay webservices to create a client yourself. Liferay exposes its core api as web service, using which you can do most of the things. To see the list of services that Liferay exposes check this url
http://localhost:8080/tunnel-web/axis
Replace localhost:8080 with yours.
To know more about this check out this wiki link
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Web+services+-+Manage+Users,+Organizations,+User+Groups,+and+Roles+via+SOAP

OSGI creating modular web application

I have been looking for a solution to create a modular web application, which is modular in the sense that user can provide its own plugin in form of a simple jar which will then provide its own data to my web application and my webapp will be responsible for displaying it.
Now the catch is i want my web app to be as generic as possible without relying on the j2ee web container to support anything . i.e. i cant rely on my web container to provide osgi support and deploy web application as an osgi bundle itself ( which truly makes things very simple for eg. glassfish and WAS).
I am planning to use equinox and only solution i see currently is the servlet bridge they provide on their official site, but to me it is really a pain to delegate everything to a servlet which will in turn interpret the request and find an apropriate bundle Class and then again communicate back somehow only the data to the web application.
To me it would be wonderful if my web app was also a bundle.
Is there anything close to this ideal solution which i can try for? Or any other communication method between the two relams of osgi and web appliction (container)?
The OSGi spec details the WAB (Web Archive Bundle) format.
And Pax Web offers great support for WAB/WAR webapps (PAX Web runs fine on Equinox, Felix, etc)
Using pax web you get the BundleContext via the ServletContext, eg:
BundleContext bundleContext = (BundleContext) getServletContext().getAttribute("osgi-bundlecontext");
For the user driven pluggability you mention, I'd suggested you provide some service interfaces for the plugin bundles to implement and in your webapp use a ServiceTracker to listen for their registration (unless you're using Declarative Services). You also easily be able to install bundles from an upload servlet.
I'm guessing users uploading plugins would have to be logged in and authorized, so security issues will have been met at this point.
EDIT: replying to comment here as not enough space in comment field
Apologies, think I misinterpreted you question - you have an existing webapp container(s) and you want to deploy a WAR with OSGi functionality? If that's the case then either use the ServletBridge as others have mentioned or embed an OSGi framework into your WAR (this is relatively easy, see this for example).
You could even make this optional by attempting to get the BundleContext from the ServletContext and if this returns null then launch your own embedded framework. That way it'll run in a native OSGi container (e.g. Glassfish) or in a Java EE app server.
Otherwise, PaxWeb is an implementation of the HttpService and WebApp OSGi specs, but with lots of extensions to make life easier - but you deploy this to an OSGi container.
You might want to look into Apache Sling. It is a web framework that has an embedded OSGi container. The OSGi container is called Apache Felix and is pretty good.
ServletBridge is for embedding an OSGI contianer within a web container. The other option is to embed a web container (as a bundle) in an OSGI container. The following article has some details on how to achieve this.
http://java.dzone.com/articles/osgi-and-embedded-jetty
You may want to try ChonCMS - http://www.choncms.com
Its architecture is based exactly on what you are asking, it comes with few plugins to enable base CMS functionality, it is modular platform with minor web app container using felix and plugins can be added/removed at run time as well.
Disadvantage might be that it has lack of documentation, but you may ask, it is open source, I'm sure they will be happy to answer questions, and even better you can contribute - it is still in incubation phase.

Converting a war file into an executable file

My company has developed a web application (J2EE environment/Tomcat server) and wants to sell it as a product. Customers can avail this product as basic edition or premium edition. In the premium edition the customers have some extra functionalities (may be some extra links). This distinction is made based on the serial key.
I was just a listener when the above thing was discussed.
Is doing the above problem possible? How do we convert a war file into an exe file and embed logic to distinguish premium or basic version.
How do we convert a war file into an exe file and embed logic to distinguish premium or basic version.
These are 2 distinct requirements which have nothing to do with each other.
If you have a web application you can either enter the serial key using a web page (like Jira does for instance), or you could perhaps let the key (or the filename of the keyfile) be written in Context.xml, and let a servlet read that context parameter. Based on the key the application could then allow or not allow some functionality.
As for converting to an executable, there are multiple interpretations to the word executable. I for one think "war" file is executable enough - dump it in a tomcat and it runs.
If you want it standalone you could provide a tomcat distribution with your app predeployed (again, like Jira does), or use a Jetty embedded container. Although that may not be appropriate for heavy workloads.
You could even try to convert jetty + your web app to a native exe using gjc (Gnu Java Compiler) though I doubt it will work as well as the normally deployed version.
I'd advise you to either inject the key via context parameters, or create an admin page n which you can enter the key.
A WAR is a web application archive. It's supposed to be executed on a webserver with a servlet container. An executabele JAR requires a class with a main() method, but a web application normally doesn't have any since that's the responsibility of the servlet container, not the web application. Normally, a WAR is to be distributed as-is, it's the serveradmin's responsibility to deploy it to a servlet container. You can if necessary include some documentation which describes how to do it for various containers.
If you really intend to sell a web application as a desktop application for some unobvious reason, then your best bet is really to include an embeddable servlet container like Jetty and ship a class with a main() method along it which creates an instance of the embedded servlet container, deploys the WAR file to it and runs the servlet container. This can in turn be wrapped in an executabele JAR.
Alternatively, you can also host it somewhere on the internet and provide a specific login.

How to create the build using Eclipse 3.6

I am developing an web app using java/j2ee as middle ware and Mysql 5.1 as database. I have to deploy it on AWS-EC2 server.
My questions are:
How do I create the build
How do I deploy on ec2 server?
I am using Apache Tomcat-6. Should I use any other server like Apache2 as web-server?
Use WTP to create a Dynamic Web Module project.
Use AWS Toolkit for Eclipse
That's pretty terse, but you'll need so many more details that it's pointless to list them here. Read the docs, then come back with specific questions :)
Whether you need Apache2 in front of Tomcat depends on your requirements. If you need it you'll know it :) Things that you might want to punt off on Apache2:
SSL
Static content
URL rewriting
If you are just planning to do every thing manually. You should read this manual http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/
Basically,
You need to create an AMI instance of platform of your choice. (Win/Unix-based).
Configure it with the software that you need. In your case, Tomcat-6 and MySQL-5.1. Configure them. Set Schema etc.
Upload your WAR file to the instance and deploy to Tomcat-6.
Make sure Tomcat port (8080 or whatever you've configured) is open. You can configure this from AWS console's Security Group setting.
Use the instance's Public DNS to access your app. Public DNS can be found from AWS console.
There are many freely available, pre-configured AMI available. Since your setting is one of the most common one. I am sure you will get one and skip Step#2.

Servlet Filters and the OSGi HttpService

I'm working on an OSGi-based application that uses org.osgi.service.http.HttpService which does not support the use of Servlet Filters.
Before I realised that I wouldn't be able to use Servlet Filters I was planning to apply a couple of existing Filters. These Filters set the appropriate HTTP headers to:
prevent caching of responses
control rendering in IE8 with the X-UA-Compatible header
What are my options here? I don't want to use meta elements to control caching since that technique is unreliable. Using a meta element to set the X-UA-Compatible header is probably acceptable, but I'd still be interested in alternative approaches.
You can use dm Server to deploy WAR files directly into an OSGi environment. WARs that run in dm Server are fully WARs and fully bundles.
There is work underway to standardize what it means to be a WAR on OSGi. This spec is called the OSGi Web Container. Work is progressing very nicely and I'm a good way along with the reference implementation for it. I'll be making the alpha code of the RI available in 4-5 days along with a blog entry detailing the usage. Keep an eye on the SpringSource blog at blog.springsource.com.
I unfortunately can't link to dm Server because I'm a new user :(
This issue for adding servlet filter support offers some potential workarounds.
Also:
Pax Web [extends] OSGi Http Service
with better servlet support, filters,
listeners, error pages and JSPs and
some others in order to meet the
latest versions of Servlet specs.
Since Eclipse 3.5 you can define filters using the org.eclipse.equinox.http.registry.filters extension point.
Regarding Pax Web:
Examples on the paxweb/Examples page don't work.
For example, I enter this command:
pax-run scan-file:jar:mvn:org.ops4j.pax.web.samples/provision!/sample-helloworld-wc.bundles
than point my browser to:
http://localhost:8080/helloworld/wc
result:
Error 404 NOT_FOUND
Also, it is not clear for me from the documentation, if Pax Web would work inside of non-OSGI servlet engine, e.g. WebLogic, WebSphere.
Pax web will not yet work inside a non-OSGI servlet engine (bridged mode). Apache Felix has a good solution for this at http://felix.apache.org.

Categories