For my current project, I need to share Spring beans between my front-end web servlets and the Spring Batch jobs that I’ll launch from Spring Batch Admin (SBA). This sounds straightforward - configure the SBA servlet to listen on /batch/*, and you should be good to go. However, of course it’s not that easy.
URL Path Mismatch
The first problem you run into is bad links in the menus, form posts that go nowhere, and missing CSS files. This is because SBA expects to be deployed on /, not /batch, or /myapp/batch which is where it will go if you deploy it inside another app. You can survive in this mode for the most part by correcting menu URLs after you click them, or use FireBug to change form actions before you submit them - for example, from /batch/files to /myapp/batch/files, but who wants to live like an animal?
Spring Batch Admin 1.2.1 to the Rescue
Spring Batch Admin version 1.2.1 adds the ability to set the base servlet path for all links and forms by overriding the “resourceService” bean. I’m sure there are several ways to successfully accomplish this, but here’s what worked for me.
pom.xml
Add the following repository:
and the dependencies:
web.xml
Configure the Batch Admin Servlet - notice contextConfigLocation:
This is the context file that’s only used by SBA. Keep in mind that any beans defined in your root Spring context will also be available to the jobs that are launched by SBA.
One Last Gotcha - /myapp/batch
The main “Home” link in the SBA action bar navigates to /myapp/batch. This doesn’t work the way I’ve wired it up, because the SBA servlet is configured to listen to /myapp/batch/, but not /myapp/batch. I tried adding another servlet-mapping to /batch, but the servlet won’t answer requests to it.
I’m sure there’s a better way to do this via config only - please tell me if you wouldn’t mind, but I opted for the more manual way, just so I could move on.
I wired up a servlet in my main web app to listen to /batch, and then have it redirect to /batch/.
web.xml - configuration for a servlet in my main app
Pay attention to the last servlet-mapping. This gives /myapp/batch over to Spring MVC for URL mapping.
HomeController.java
Here’s where I redirect /batch to /batch/. Again, I’m sure there’s a better way to do this (let me know!). Of course, for this specific code to work, you’ll need some dependencies such as spring-webmvc. The bottom line is that I’m just manually listening on /batch and redirecting to /batch/.
Know a Better Way?
Ideally, I’d like to either get Spring Batch Admin to listen to /batch or /myapp/batch, but I’d settle on having a redirect configured in web.xml. Please tell me if you know of a good approach. I moved on with this good-enough solution.
Mac OS X comes with Apache Maven preinstalled. However, you’re still going to need to set some environment variables to get up and running.
Verify that maven installed in /usr/share/maven:
Add the following line to your ~/.profile
This won’t take effect until you either reboot or open a new terminal window. You can reload the file in the current terminal window with the following command:
It’s not unusual to stumble upon a PDF document while web surfing on your iPad, iPhone, or iPod Touch. You might be logged into your bank’s site to view a monthly statement, or have finally found that important tax document that took you 10 minutes of poking and prodding a confusing online submission form.
You can’t email it to yourself.
You don’t have time to read the document now, and it occurs to you that you should probably share this with your spouse while you’re at it, so you touch the “Share” button and look for “Email”. This is where you realize that your only option is to email a link, not the document itself. This doesn’t help you. You are not amused.
For me, that moment of disappointment came when I had opened up a bunch of tabs with interesting articles from an online version of a magazine that I subscribe to. Emailing myself links wouldn’t work, because these PDF documents require you to login first, and for whatever reason, you can’t just navigate to an article by their URL.
The solution is simple.
I solved this problem by developing the iOS App, PDF Emailer (no longer available).
While in Safari, touch the document once to bring up the options, and touch the “Open in…” button.
Touch the “PDF Emailer” button.
Enter the recipients and send the email.
PDF Emailer will keep your PDF document until you delete it. This allows you to read it while offline, or email it out again later.
It runs on the iPad, iPhone, and iPod Touch, and is available now on the App Store.