Launching JNLP from a dotnet web application - java

Oracle recommends using the JnlpDownloadServlet to launch JNLP from Java web applications - https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/downloadservletguide.html
However, I need to launch a JNLP application with a dynamically generated JNLP file from a dotnet application.
What would I need to do to enable this?
set content type as application/x-java-jnlp-file
output the JNLP file as a download.
Is there anything else?

The JNLP file is just an XML file that happens to be an executable file as long as you have Java Web Start installed on your machine. This is usually installed on a machine.
From a .NET Web Application point of view, you'd need to ensure the following:
Correct content-type (application/x-java-jnlp). You might need to add configuration to your .NET server to enable this mime type.
The file needs to be accessible via a URL (kind of obvious, but worth mentioning for completeness)
The file needs to be downloadable. Conceptually it is the same as returning any other file.
For seamlessness, the browser needs to be setup to automatically execute jnlp files. Sometimes company/default browser settings do not do this and you'd end up needing an extra click. Not a big deal, but just something to be aware of
In terms of "configuring"/implementing the actual serving of the JNLP file from a .NET Application:
Your end goal is that whatever JNLP file you return is executable with Java Web Start. This gives you a nice repeatable test while you're working on this.
You need to ensure that your .NET Application is able to serve the jar files needed by the JNLP application. Typically the codebase attribute and the resources element needs to reference your .NET application. The JNLP File Structure Page should help with this.

If you look at the JNLP servlet source code you will see that all it does is use the .jnlp file as a template and substitute place holders for specific values. There is nothing special about it that couldn't be duplicated in a .Net MVC or API controller.

Related

How to upload jar files in webswing?

I want to convert my Swing application to web application. Getting help from How to deploy swing application on web browser?
Please have a look to second step of first answer ("Install this [AjaxSwing] application in your system"). Where can I upload jar file and how?
You don't actually upload a jar file, I think the related answer is misleading. Webswing is a software you download and install on-premise. It starts a web server which serves your application on a web page. All you need to do is create a configuration where you specify the path to your jar file. As Gilbert pointed out, you can get the idea when you read the Webswing documentation https://www.webswing.org/docs/20.1/start/quickstart.html

How can I externalize a PDF from a Java EE application?

I have a Java EE application, running under WebLogic 10.3.5 and Java 6.
I used to have a pdf help file, embedded in my war file, but I need to extract it from there and put it in an external directory (it can be in my same WebLogic domain directory).
I tried to put it in my WebLogic domain and then to < a href > it, but it seems that browsers have limitation and for security reason will not allow to download local file with a href or javascript.
This used to work only on a static HTML file saved on my computer but one the HTML page is deployed on the server, it seems not be possible.
Any idea how I can externalize my help.pdf file from my war file?
#limc is right
you should put this static file outside of Weblogic altogether as a file on an Apache web server
However, in Weblogic there is a feature of virtual directory mapping which allows you to declare a folder outside of the weblogic domain as a content store for any static stuff.
http://docs.oracle.com/cd/E11035_01/wls100/webapp/weblogic_xml.html#wp1039396
This entry goes in WEB-INF/weblogic.xml
<virtual-directory-mapping>
<local-path>c:/usr/mypdfs</local-path>
<url-pattern>/pdf/*</url-pattern>
</virtual-directory-mapping>
Although some application servers allow a Java EE app to reference a file outside the web container, in reality, your web app shouldn't have any knowledge about anything outside the web container, and as you have mentioned, it is indeed a huge security concern.
Depending on what you are trying to accomplish with this PDF file, if you merely want to expose this file on the web, do what #duffmo said and it will work fine. If you want the flexibility to modify this PDF file frequently without recreating the war file again and again, you may want to consider hosting this PDF file in some HTTP web server (Apache2, IIS, etc) and now you reference that link from your web app.
You need to put it at the root of your web context, in exactly the same place as HTML pages. Your web server will be able to find it there.

how do you get jsp page dedicated to launching a JNLP file create a browser popup?

if the top of your JSP reads
<%# page contentType="application/x-java-jnlp-file"%>
<?xml version="1.0" encoding="UTF-8"?>
How do you add html to this page?
Equally, How would you get the web browser to create a popup for instructions?
How do you add html to this page?
If you do, it won't be a JNLP file. It will be a mess that is pretending (poorly) to be a JNLP. Most JWS clients would reject it, pointing out that it is not JNLP, the rest would fail with other (less obvious) errors.
Equally, How would you get the web browser to create a popup for instructions?
Aaaargh, the dreaded pop-ups. My browser would kill them automatically.
Put instructions on the page that links to the JSP that launches the app.
Why not write a regular servlet for it? JNLP files are not html and i dont even know how that would work with JSP.
And if you send a JNLP most web browsers will know what to do with it, you can also distribute this file through email(or other means) and start it directly on the users computer.
I used to have several WebStart apps a few years ago and i wrote a servlet that would just serve the JNLP file from the local file system. I later changed it to generate the JNLP file on the fly and include default libraries i used in all my projects. I also used that to serve the jars from the file system so they didnt need to be bundled with the servlet WAR.
I put some of my code here http://ideone.com/36sjB as a start. Most of it was used in an experimental in house app, so this should not be used in production code ;).
Sending the JNLP is just like sending the jar with a different content type. I also have code about generating the JNLP from scratch through the servlet if you are interested.

Uploading files in Spring+Wicket

What are the steps required for enabling a Java web application (Developed using Spring + Wicket) to accept client file uploads to a specific directory on the server.
While Googling for answers to this question I see suggestions that /WEB-INF/some-directory should be used as the upload location?
Is the reason for this best practice?
Is this location writable by the web application?
What happens to this location when a new version of the web application is deployed?
Can/Should any other directory be used?
Thanks
Two possible reasons for the use of a subdirectory of WEB-INF:
it is not visible through HTTP
your application typically has write access to it
I would rather recommend using a configurable, external directory (e.g configured in a context parameter or en application config file); this way you have fine grained control over the permissions of the directory.
AFAIK, file upload in Wicket is provided by the FileUploadField component, which gives you a FileUpload object that you can writeTo a file on your server.
You might also want to configure/check the maximum size for the files you want to accept. In Tomcat, this is done through the maxPostSize attribute of a Connector (see The HTTP Connector)

Dynamically load additional jar files using Web Start / JNLP

The Web Start Developers Guide states
All application resources must be retrieved from the JAR files specified
in the resources section of the JNLP file, or retrieved explicitly
using an HTTP request to the Web server.
Storing resources in JAR files is recommended, since they will be cached
on the local machine by Java Web Start.
Now, I have some resources I want to dynamically load after my application has been started (for example OSGi bundles). I can do this using plain HTTP, but I would like to make use of Web Start's support for local caching and versioned/architecture-specific resources.
Is there a way to download additional jar files from the original code base (as specified in the application's jnlp file) using the Web Start infrastructure?
Or alternatively: is there already an established way to integrate OSGi and Web Start that would relieve me of the task to install bundles from the Web Start server?
If you make your application in itself an Equinox-based OSGI application, you can web-start it with all the addition bundles you need.
This article "WebStarting Equinox OSGi Apps" can give you a good introduction on the required settings.
All bundles have to be deployed as signed JAR files
You need a feature that contains all the necessary bundles
When exporting the feature, make sure that PDE creates a JNLP (Java Network Lauching Protocol) file (a checkbox in the export wizard) for this feature
Provide a root JNLP file for you application
Deploy your application to a web server and make sure that the web server is aware of the application/x-java-jnlp-file mime type
He also has an OSGI demo.
I haven't tried it but look at the javax.jnlp.DownloadService API

Categories