Category Coding tips

Java: How to save / download a file available at a particular URL location in Internet?


Related articles Creating OSGi projects using Eclipse IDE and Maven (singztechmusings.wordpress.com) Working with OSGi and Maven in Eclipse IDE (singztechmusings.wordpress.com) Java download file from URL with unknown filename (stackoverflow.com) OSGi adoption by Large Scale Java-based Enterprise Software Platforms – LinkedIn Case Study (singztechmusings.wordpress.com) How to create/generate OSGi bundles from existing third-party jars? (singztechmusings.wordpress.com)

Linux/Unix: How to manipulate or change the last modified/accessed time of a file using touch command?


Assume there’s a file @ /home/user/testmsg.txt If you want to change the file timestamp to 09/20/2011 08:30 using touch command, here’s how you can do it: From Wikipedia, touch is a standard Unix program used to change a file‘s access and modification timestamps. It is also used to create a new empty file. Related articles […]

Apache CXF: How to add custom HTTP headers to a web service request?


HTTP header fields are components of the message header of requests and responses in the Hypertext Transfer Protocol (HTTP). They define the operating parameters of an HTTP transaction, carry information about the client browser, the requested page, the server and more. Here’s how the HTTP headers can be added to your web service calls made […]

Apache CXF-based Java Web Services: How to log/print the payload XML of incoming SOAP request using LoggingInInterceptor?


I’ve had a requirement to print the exact SOAP XML of incoming requests to one of our web services written using Apache CXF Framework and here’s what I did. For doing this quickly, I’m taking the code from https://singztechmusings.wordpress.com/2010/12/10/java-web-services-soap-over-ssl-cxf-framework/ for CalculationServerIfc that basically does addition/subtraction based on web service requests. Here’s it: and I’m assuming […]

Getting started with Velocity templating engine: Constructing HTML content in a Spring-based Java application


1. Create a velocity template file – say, helloworld.vm, and add this to classpath. Add some html content. 2. If I want to make ‘Hello World’ part dynamic, here’s what you need to do. 3. Now, to ask Velocity engine to replace the helloContent dynamically, i) construct a map and add a key ‘helloContent’ and […]

Loading configurable parameters from properties files into Spring bean context definitions using PropertyPlaceholderConfigurer – An example


Using Spring‘s PropertyPlaceholderConfigurer to load configurable parameters in properties files – An example Here’s a context definition for a bean in XML: JDBC properties, though made configurable in the above XML context definition, it’d be better if we dynamically get these values from a properties file kept centrally and shared by all the applications. Use […]

List all possible/different ways to create a Java object


The ways I know and have tried so far: 1. Using new keyword This is the most common way to create an object in java. Most of the time, Java objects are created in this way. MyTestObject obj = new MyTestObject(); 2. Using Class.forName() If we know the name of the class & if it […]

How to configure timeouts at client side for Apache CXF web services?


I’m extending the example at https://singztechmusings.wordpress.com/2010/12/10/java-web-services-soap-over-ssl-cxf-framework/ to show how to set connection/receive timeout duration for a CXF client. If you’d like to wait indefinitely for connecting to server, or receiving a response, either do not add marked lines in code, or set the timeouts to zero.

Java: Timezone Correction/Conversion with Daylight Savings Time settings


Have tried out a couple of code snippets to handle timezone corrections in Java code that’ll take into account Daylight Savings Time (DST) settings. None of them really suited our need; so I had to modify a particular code snippet which I found to be closer to what I was expecting. Here’s the modified code:. […]

Getting started with Java’s ProcessBuilder: A simple utility class to interact with Linux from Java program


JDK 5.0 adds a new way of executing a command in a separate process, through a class called ProcessBuilder. You can find ProcessBuilder in the java.lang package (like Runtime and Process). According to the docs, This class is used to create operating system processes.Each ProcessBuilder instance manages a collection of process attributes. The start() method […]