by Bozho | Dec 16, 2013 | Aggregated, Developer tips
WebSocket is a cool new(ish) technology that allows real-time, two-way communication between the browser and the server, with almost no overhead. What I want to do here, is to provide a very succinct, but sufficient overview of how to start using the technology. So, a few things to start with: a tcp socket connection is opened between the browser and the server, and each party can send messages to the other (i.e. the server can push data whenever it has it available – no need for polling, long polling, iframes, etc.) not all browsers support it – IE 10 is the first IE version to support it, Android still has issues. Fortunately, there’s SockJS, which falls back to other push-emulations, if WebSocket is not supported. not all proxy servers support it / allow it, so again fallback might be needed suitable for games, trading applications, and in fact anything that requires the server to push data to the browser Java has a standard API (JSR-356), which you can use on the server to handle WebSocket connections. Spring provides an API ontop of the Java API. The good thing about the spring support is that it has server-side support for SockJS and you can use dependency injection effortlessly. Spring also provides STOMP support for a message-driven architecture. Both spring articles include links to GitHub sample projects, which I recommend. for a long time the Atmosphere framework has been a solution for server push. Here is the getting started guide for WebSocket. Cometd also provides WebSocket support. Before proceeding to some sample code, here is the socket lifecycle, including client and...
by Bozho | Dec 9, 2013 | Aggregated, Opinions
My development machine has Windows. I have used Ubuntu at some point, but it was a disaster, so I switched back. And there are always people asking me how I manage to be productive on Windows, and if I don’t miss the shell. Developers use the shell and the tons of available cool utility programs in Linux to achieve some supporting, auxiliary tasks. Doing mass-replace, automating some code-generation process, etc., etc. So don’t I miss the shell and bash programming in order to achieve tasks that are auxiliary to the actual development? Well, I don’t. I don’t even use PowerShell. If my IDE doesn’t provide the functionality I need (or I don’t know it does), then I use a tool class with a main method. Java has a lot of powerful libraries that allow me to ditch the need of doing stuff in the shell or using bash scripts. And the good thing is – it’s Java, it can be versioned if needed, and it’s easy to use, with no additional learning curve, no man pages, etc. My development machine has Windows. I have used Ubuntu at some point, but it was a disaster, so I switched back. And there are always people asking me how I manage to be productive on Windows, and if I don’t miss the shell. Developers use the shell and the tons of available cool utility programs in Linux to achieve some supporting, auxiliary tasks. Doing mass-replace, automating some code-generation process, etc., etc. So don’t I miss the shell and bash programming in order to achieve tasks that are auxiliary to the actual development?...
by Bozho | Nov 13, 2013 | Aggregated, Developer tips
How do you configure your machine in order to have save-and-refresh for Java web projects? When you ask this question to developers, the answer starts with “oh, well…”, and continues with a description of something that sort-of works. And everyone has his own way. First – why do you need this? Because doing copying and restarting the server is a productivity killer – wastes a lot of your time. Without the productivity boost of syncing your project with the container, even for simple fixes, you may need a full build-and-deploy cycle before you can test it. And that may take a lot of time, depending on the size of the project. I’ll write down a few, to complement my StackOverflow answer: IDE integration – IDEs have an option to add a local server and deploy projects to it. That requires additional plugins, configuring what workspace files go where in the servlet container, and doesn’t always work. And when there is Maven in the picture, it either doesn’t work, or requires yet another plugin (as described in this answer of mine) You use some tools for synchronizing directory structures. In Eclipse there’s the FileSync plugin, which let’s you configure which workspace files go where in the servlet container. Other tools may exist for doing the same thing (e.g. unison) , or you may have written some script or plugin to do it. Running the servlet container from maven (if using maven) – either the tomcat plugin or the jetty plugin let you do that. The downside is that in order to run in debug mode, you need to attach external...
by Bozho | Nov 10, 2013 | Aggregated, Developer tips
It is a very rare usecase, but sometimes you need it. How to embed Maven in your application, so that you can programatically run goals? Short answer is: it’s tricky. I dabbled into the matter for my java webapp automatic syncing project, and at some point I decided not to embed it. Ultimately, I used a library that does what I needed, but anyway, here are the steps and tools that might be helpful. What you usually need the embedded maven for, is to execute some goals on a maven project. There are two scenarios. The first one is, if you are running inside the maven container, i.e. you are writing a mojo/plugin. Then it’s fairly easy, because you have everything managed by the already-initialized plexus container. In that case you can use the mojo-executor. Easy to use, but expects a “project”, “pluginManager” and “session”, which you can’t easily obtain. The second scenario is completely embedded maven. There is a library that does what I needed it to do (thanks to MariuszS for pointing it out) – it’s Maven Embedder. Its usage is described in this SO question. Use both the first and the second answer. Before finding that library, I tried two more libraries: the jenkins maven embedded and the Maven Invoker. The problem in both libraries is: they need a maven home. That is, the path to where a maven installation resides. Which is kind of contrary to the idea of “embedded” maven. If the Maven Embedder suits you, you can stop reading. However, there might be cases where the Maven Embedder might not be what you...
by Bozho | Oct 24, 2013 | Aggregated, Developer tips
This is going to be a short post. It may look like stating the obvious, but I was again reminded the other day that there are still frameworks and tools that do not have their default encoding set to UTF-8. So, two requests: To framework authors and contributors: use UTF-8 by default, everywhere. To developers: if you see a non-UTF-8 default, report a bug / request improvement. I mostly look at the web side of the story, but same goes for desktop software. The site UTF8Everywhere is also an advocate for this, you can take a look at the manifesto. If using only English, why not stick to ISO-8859-1? If you only use latin script, you don’t lose anything from UTF-8 – it’s a variable length encoding and the initial symbols (corresponding to the ASCII ones) take the same amount of space. Why you should use UTF-8? Because otherwise you will get tons of nasty encoding-related problems. To conclude: Use UTF-8 by default This is going to be a short post. It may look like stating the obvious, but I was again reminded the other day that there are still frameworks and tools that do not have their default encoding set to UTF-8. So, two requests: To framework authors and contributors: use UTF-8 by default, everywhere. To developers: if you see a non-UTF-8 default, report a bug / request improvement. I mostly look at the web side of the story, but same goes for desktop software. The site UTF8Everywhere is also an advocate for this, you can take a look at the manifesto. If using only English, why not...
Recent Comments