Java
Blog posts for the tag #Java
16-Dec-2020
Uninstalling Java on macOSI've recently had my Mac scanned for a corporate compliance test and the older Java 8 JDK has come up as a failure point. Even though I had newer JDKs installed, it meant that I had to go in and uninstall the one that was making me fail this test. There is good documentation online on how to uninstall a java version on macOS, but I thought that I would walk through the process here anyway...
19-Oct-2020
How to run code from a JAR file inside a JMeter projectI've been using Apache JMeter quite a lot more lately and have been finding it a very useful tool for automating some repetitive tasks that we have to perform around system maintenance on one of my projects. However, not everything can be done with what's available in JMeter out of the box and sometimes you just need to run some external Java code from a JAR file.
11-May-2020
Java Mission Control 5.5 freezes during startup on macOSRecently I've had a need to use Java Mission Control (JMC) to look at some Java Flight Recorder (JFR) files for a piece of code I've been analysing for performance issues. The piece of code didn't require being run in production so I decided to do the analysis on my Mac instead of one of the dev servers. This is where I ran into issues...whenever JMC was launched, it would freeze.
30-Mar-2020
JAXWS and Object reference not set to an instance of an object error in SvcutilStrange things can happen when mixing frameworks, operating systems and programming languages. However, web services are meant to be portable and language agnostic, yet things don't always work out as intended. I've been seeing an issue where a C# .Net client has been failing to generate web service proxies for a JAXWS service running in WebLogic, but after a considerable time debugging the issue was able to resolve it.
02-Dec-2019
Unable to read manifest file (line too long) during Java JAR packaging with MavenOne of the tools that I maintain has recently been updated with new functionality and as a result we had to update its MANIFEST.MF file to reference additional jar files in its classpath. Unfortunately the number of referenced jar files went over a limit and during Maven build the following error started to crop up...
16-Sep-2019
Controlling the wsa:MessageId that the JAX-WS RI AddressingFeature setsSo you've created a JAX-WS client for a web service you want to call and you added the AddressingFeature to support WS-A. You can see wsa:MessageIDs being generated and sent to the target web service, but instead of having random IDs, you want to be able to create your own. Unfortunately, AddressingFeature doesn't provide this level of customisation.
24-Jun-2019
Curious PLS-00302 component DBMS_PICKLER must be declared error from JDBC driverI was emailed an interesting error recently at work that I've not seen previously. It was to do with the DBMS_PICKLER package being missing when using JDBC drivers from a WebLogic application. In this case we were upgrading from an earlier version of WebLogic to the latest (12.2) and that's where we started to see these errors.
12-May-2019
How to get the full command line used to start a Java process in LinuxGetting the command line of a running process in Linux is usually easy, just run the "ps -ef" command, but what if the command line used to start a process is very long? It gets a little more difficult. This is the problem I ran into recently when trying to get all the arguments used to start a WebLogic managed server. The ps command was only displaying the first 4096 characters of the command line.
24-Mar-2019
A handy Java utility class to capture Oracle DBMS_OUTPUTSome of the work I've been doing not so long ago has been deeply rooted in PL/SQL which was invoked from a Java client. The PL/SQL made heavy use of DBMS_OUTPUT to generate text data that could be parsed by the Java client, which in turn then generated graphs (as images). I needed an easy way of capturing this output and unfortunately when I looked around all I could find were outdated approaches that didn't make use of Java features like AutoCloseable resources, and then there were some examples that plain didn't work.
24-Feb-2019
Provider com.ctc.wstx.stax.WstxInputFactory not a subtype in WebLogic deploymentWhile migrating both JAX-RS and JAX-WS web services from WebLogic 12.1 to 12.2 I've come across an issue during deployment. The error "java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider com.ctc.wstx.stax.WstxInputFactory not a subtype" kept on coming up. The particular service in question wasn't using StAX but we've played around with changing various providers during this upgrade so I thought that was the root cause. It wasn't.
06-Dec-2018
Setting JAX-WS webservice client timeout values correctly within a WebLogic 12c containerConnect and read timeout settings for webservice clients are not standardised across different versions of the JDK, nor the application containers like WebLogic, JBoss, Glassfish, etc. So when it comes to setting these values correctly for your specific environment, you can get stuck in a cycle of trying all known properties until one works. This is what I had to do recently.
29-Nov-2018
Various errors encountered while playing with WS-AtomicTransaction webservicesDuring the last couple of weeks I wrote about building a WS-AtomicTransaction participant webservice and then consequently how to invoke it with a JAX-WS proxy. This article takes a look at the errors that can be encountered when developing WS-AtomicTransaction enabled services with WebLogic. This of course isn't a complete list and I'll add more here as I encounter them.
22-Nov-2018
Invoke a WS-AtomicTransaction participant service with a JAXWS proxy in WebLogicLast week I wrote about Building a WS-AtomicTransaction participant webservice with WebLogic 12c and Maven. When talking about WS-AtomicTransaction that covered only half of the story however. The second half is about creating a transaction and calling the participant service. That's what we'll cover in this article.
18-Nov-2018
How to get the JDBC custom connection URL from SQL Developer connectionsI've written about SQL Developer on quite a few occasions, it's a tool that I use on an almost daily basis. It's improved tremendously over the years that I've been using it and apart from a few minor docking issues I can't find much fault with it...but I really wish it had an easier way to get the custom JDBC connect URL from a database connection. So if you're reading, Jeff Smith - here's a challenge for you - add a new feature that will generate a snippet of Java code from a SQL Developer database connection that will, using JDBC, connect to that database. Meanwhile, for the rest of us lets see how we can get to the JDBC URL as it stands now...
15-Nov-2018
Building a WS-AtomicTransaction participant webservice with WebLogic 12c and MavenNo matter how good official documentation is, sometimes it simply isn't enough to cover certain cases when multiple technologies overlap, and sometimes small mistakes creep in too. So some time ago while I was working on a WS-AtomicTransaction enabled webservice, I ran into issues that were to do with WebLogic dependencies and compilation. At the time I got past the issues with what were essentially hacks, where I used deeply nested dependencies in Maven, but now I wanted to revisit this approach and to see what was required to build a WS-AT enabled webservice from scratch by using only documented approaches.
08-Nov-2018
A handy Java utility class to collect DMBS_OUTPUT using JDBCRecently I've been working with a PL/SQL package that used DBMS_OUTPUT to generate a report. This report was then copy/pasted into a small Java utility I wrote, which parsed it and generated a visual representation of the report data. Because this didn't need to be automated, I was calling the package manually using SQL Developer. Now that work is over, I started thinking if the Java utility could have been enhanced to capture the report itself.
29-Oct-2018
Resolving AutoDiscoveryMethodFactory exceptions in SoapUI 5.3 while using Test RunnerSoapUI is a great tool for testing web services and works especially well with its automation features. I've been using this tool since as long as I can remember working in the IT industry, only recently moving some of the work over to newer tools like Postman. So even to this day SoapUI remains my primary testing tool. Unfortunately some time during the 5.2 release of SoapUI a number of plugins were installed that were meant for its Pro features, and now some of these plugins are incompatible with later versions of SoapUI and cause a number of exceptions to be logged while using the Test Runner.
23-Aug-2018
How to suppress unused method inspection in IntelliJ for a specific methodIf you use IntelliJ's inspection features to highlight unused methods and you work with web services you will probably find yourself in this bind. The @WebMethod annotated methods in your service endpoint interface (SEI) class will be flagged as never used. This is because typically you would't be writing test cases for this class as it shouldn't contain any business logic and should delegate to other classes (if you have logic in your SEI, you should be re-writing it!)
02-Aug-2018
Reducing web service build times by skipping Maven WebLogic plugin wsgen goalI've been a fan of using the Oracle WebLogic Maven Plugin to build web services from JWS files for a long time now. Even though the plugin has its quirks, it does a great job and simplifies the whole web service build process. So...it was with shock and horror that I've recently discovered just how slow using this plugin can get.
26-Jul-2018
Testing out new JaCoCo filtering options that help to improve code coverageI've recently had a chance to compare test coverage reports between JaCoCo version 0.7.8 and version 0.8.1 and I must say that I'm impressed. Since JaCoCo 0.8.0, new filtering options have been available and enabled that skip some code blocks that really do not need to be tested and do not need to be reported on in test coverage reports.
19-Jul-2018
Velocity template processing performance - utility vs directive classesAh Apache Velocity is something that I've always liked and we tend to make moderate use of it on a project I'm working on. So it was an off-chance that I happened to be looking at some code that was dealing with Velocity configuration that I noticed that custom directives are used all over the place instead of simple utility (or tool) classes. This wasn't a part of the code base that I was familiar with so thought there must be a reason for this choice.
31-May-2018
Java ThreadPoolExecutor with automatic task cancellation after timeoutI make heavy use of ThreadPoolExecutor for a number of web services that I look after on my current project. This has been working great without much customisation for years but now we decided to tighten some of the service behaviour. With the old implementation it was possible to get a read timeout up the product stack waiting for a response from a service while the service happily continued executing tasks in the background. To stop this background execution, it was decided to implement forced timeouts at the thread pool level for each service.
28-Dec-2017
Resolving the Cannot reference X before supertype constructor is called compiler error in JavaSometimes when implementing a constructor on an object that requires calling another constructor there's a need to call a helper method that does some work. This is done either for convenience or because some work needs to be done on input parameters before calling the super/this constructor. In these situations you're likely to come across an error like this - "Cannot reference 'X' before supertype constructor is called".
21-Dec-2017
How to quickly migrate your Google AppEngine app from Java7 to Java8 runtimeGoogle has deprecated the Java7 runtime in favour of Java8 as of the 13th of December 2017 and it's advisable to migrate your apps to the new runtime. The apps do not need to be migrated immediately since the Java7 runtime will be available until January 16 2019, so you have some time still.
04-Dec-2017
jPhotoFrame new layout engine explained with examplesNot too long ago I announced that jPhotoFrame 0.4 has been released. The biggest feature of this release has got to be the all new layout engine. I didn't go into too much depth in the release article about how this layout engine can be configured, and that's what I intend to cover now.
13-Nov-2017
jPhotoFrame version 0.4 released with a whole new layout engineI've been working on a brand new layout engine for jPhotoFrame over the past few weeks and it's finally complete. This engine replaces the old clunky, hard to configure engine with a widget based layout that can be layered and bound to various parts of the run-time data model. What does that mean? Well, now configuration is easy (though more verbose) and you have greater control of how the interface looks and what it displays.
09-Nov-2017
A custom exception mapper and writer for a RESTful JAX-RS Jersey serviceI've written quite a few articles about Jersey already ranging from filter and interceptor execution order to a custom message body reader implementation. This article delves deeper into Jersey and looks at how to gracefully handle exceptions by using an exception mapper and entity writer to convert a caught exception to output from your service.
26-Oct-2017
Writing a custom MessageBodyReader to process POST body data with JerseyJersey makes it really easy to customise how your RESTful service accepts input and how it produces output. I've written previously about how, with a few lines of code it's possible to use Jackson to convert your POJOs to JSON when returning data from your service. This article looks at the other end of the lifecycle - the input, specifically how a JAX-RS service can process a POST message body and create a POJO as input to a Resource method parameter. In other words - how do you implement a custom message body reader?
28-Sep-2017
Troubleshooting high CPU usage for JVM threadsWhile diagnosing an issue with high CPU usage on WebLogic I had to work out which threads were at fault. This was a relatively straight forward exercise but required a couple of tools and a bit of decimal to hexadecimal conversion. The server had 2-cores and WebLogic seemed to be using 100% of CPU time on one of the cores at all times.
06-Sep-2017
Why you should never use Java enums as keys with Oracle Coherence cachesI thought I was being smart by declaring a bunch of enums in my code so that I could cut down on the clutter of managing several constants that I was going to use for my Coherence cache key names. At first this seemed to work OK but when it came to testing whether the cache was in fact distributed and accessible from multiple services - all hell broke loose.
22-Aug-2017
Writing accurate fail scenario unit tests with JUnit rules and exception matchingWith JUnit 4 you can write tests that expect exceptions being thrown from the code you're testing. This is done by passing a value to the expected property for the @Test annotation. Though this is a huge step up from JUnit 3.x behaviour, it is not very flexible and doesn't let you do very accurate fail case testing.
21-Aug-2017
Filtering exception stack trace logging with Log4J and a custom ThrowableRendererLast week I wrote about enabling full stack trace in Maven's Surefire plugin and that got me thinking that much of the stack trace is actually not relevant. When it comes to logging, it's a waste of resources to write huge stack traces to disk that give no additional relevant information. So I thought lets see what can be done to address this.
31-Jul-2017
Why JUnit @Test(expected=xxxx) annotated test cases are still reporting failures on ExceptionIn a big code porting project recently I had to move a number of unit tests from one class over to another. I didn't give it a second thought beyond that until it came to running the build. Compilation was successful, however JUnit execution failed on the tests I moved. Odd. At first I thought maybe I accidentally changed some code, but no, all the code was the same. Then I realised what the problem was.
23-Jul-2017
A hack to create an uber jar with the Maven Shade Plugin using local jar filesThe general consensus is when you are having to fight Maven, you're doing something wrong. However, sometimes you get backed into a corner and do have to put up a fight to move forward. I've come across a situation where in order to connect to and use an API hosted as EJBs in WebLogic I needed to have a number of client jar files, 16 in total. I didn't particularly want to have 16 separate dependencies in my own Maven projects and I also wanted to make it as easy as possible for others on the project to access this API. My solution was to look into the creation of an UBER JAR file to hold all the required classes.
03-Jul-2017
Code Odium: Using method parameters as local scope variablesThis is an instalment of my Code Odium series of articles talking about bad programming practices with focus on Java. In this article I will talk about the practice of declaring variables in a method parameter list only to use them as local variables.
25-Jun-2017
Fix Java applications slow start and net connection times on macOS sierraI've been finding that since I got my new MacBook Pro and installed Java 8 on it, all of the Java Applications that I've been running have been taking an extremely long time to start or to establish network connections. This didn't seem to affect Java Applications that didn't use the network however. Turns out that the problem is to do with the local machine's hostname resolution and is easily fixed.
10-May-2017
Postman reporting Unexpected 'N' error in response bodyI've been using Postman to test some RESTful services and came across a strange error in the body of the response from a service - "Unexpected 'N'". I knew for a fact that the service was not returning this error so something else must have been going haywire.
26-Mar-2017
WebLogic package-name element classpath generator scriptI wrote a post a few days ago about using Jersey 2.x as a shared library with WebLogic 12.1.2. In that post I suggested the following: In weblogic.xml the prefer-application-packages element needs to have entries added for ALL OF THE PACKAGES in the Jersey 2.x shared library JAR files. That means you need to go through every jar file in WEB-INF/lib for the shared library that was created with Maven and make sure the packages it defines are included in this element.
15-Mar-2017
Unmarshalling an XML fragment representing a JAXB object without XmlRootElementI've recently had a requirement to unmarshal an XML fragment that was passed into one of my services. This in itself is typically not and issue and I've written code that does that plenty a time, however in this case I was having to unmarshal a fragment for a complex type, not for an element. That's where it got a little bit more complicated.
14-Mar-2017
Injecting a ContainerRequestContext into a Jersey entity provider classI was implementing a custom entity provider in a Jersey REST service when I came across an error during deployment: "java.lang.IllegalStateException: Not inside a request scope." That struck me as a little odd since I was trying to inject a ContainerRequestContext into a MessageBodyWriter, which should have been within request scope. After some research and this Jersey issue I found a solution.
08-Mar-2017
Compiling the FHIR schema with XJCI've written previously about fixing HL7 CDA schema compilation with XJC, now that I've been looking at FHIR it seems that there are name collisions in that schema too. The actual problem arises out of the W3C XHTML 1.0 Schema and not the FHIR schema per se.
03-Mar-2017
Generate JAXB jar from a Maven dependency that has multiple referenced schemasI've been trying to get the maven-jaxb2-plugin to generate a JAXB jar out of XSDs that are stored inside a dependency that I have no control of. This was quite doable for a simple, single XSD Maven dependency that didn't import any other schemas, but when dealing with a more complex schema that did import multiple other XSDs from the same dependency jar, it didn't "just" work. After trying many approaches I found a solution however.
21-Feb-2017
Older versions of JD-GUI crashing on macOS SierraI've noticed today that my version of JD-GUI started crashing whenever I tried to open a jar file to decompile. I was on macOS Sierra and had version 0.3.3 of JD-GUI installed. This was the kind of error and crash report I was getting...
01-Jan-2017
A simple OpenWeatherMap example in JavaI've had my JPhotoFrame project using the OpenWeatherMap API for some time now, at least since Yahoo messed up its own weather service. I thought it would be useful to share a bit of code on how to use the OWM API, so here it is.
16-Aug-2016
jPhotoFrame version 0.3 released with a bunch of cool updatesI've released jPhotoFrame version 0.3 today. It has more customisation options for weather forecast positioning, adds pause functionality and fixes a bunch of small bugs like out of memory error and spiky text. In this release I've migrated over to the 2.5 version of the OpenWeatherMap API too.
15-Aug-2016
OpenWeatherMap 2.1 version API is now officially deadNot long ago I've written that OpenWeatherMap crippled its 2.1 version API by returning data for the same city no matter what the request was. Now it looks that OWM has completely killed off the 2.1 API endpoints in favour of its (paid) 2.5 version of the API.
27-Jul-2016
Code Odium: Unnecessary String concatenation and splittingI've decided that I'm going to start a new line of posts on my blog that deals with especially bad examples of code that I come across. These are meant to demonstrate how NOT to write code, specifically in Java. I will do an analysis of the bad code and will also provide my solution to fix the bad coding practice shown.
11-Jul-2016
Waiting on multiple Future workers on a ThreadPoolExecutorI've been using the Java Future interface extensively. It's simple to implement and all you need is a ThreadPoolExecutor to run your code in a Thread. There is no messy thread handling, it's all taken care of for you. So what happens if you are running multiple Future tasks and have to wait for all of them to complete before you continue processing their results? Read on to see my approach.
06-Jul-2016
OpenWeatherMap cripples its 2.1 version APII've noticed that for the past few weeks my Photo Frame has been reporting odd weather. Instead of Brisbane, Australia it was giving me weather for Whitby, GB. I didn't pay much attention to it at first but then it got to me, I checked the configuration and that hasn't changed so I figured there must be something odd going on with OpenWeatherMap and turns out I was right.
24-May-2016
Using Mockito and JUnit to test a SOAPHandler implementationWhile adding JUnit unit tests to one of the projects I've contributed to I've come across a SOAPHandler implementation that was completely untested. I couldn't let that be so decided that at least some test coverage was required. Unfortunately testing a SOAPHandler is not so easy, but with a bit of Mockito magic is very doable.
10-May-2016
Java Mission Control requires GTK but which version?I've recently had one of the DBAs on a project ask me what GTK version is required to run Java Mission Control with JDK 7. I thought easy, the documentation should tell me this, but after searching for several hours I've come up with nothing, apart from 'GTK Libraries Required' as stated in the Oracle Java Mission Control 5.3 Certified System Configurations.
28-Apr-2016
Latest JodaTime and WebLogic incompatibility, missing methodsJoda-Time is a great library if you can't use Java 8 in your project. If you happen to be using version above 1.2.1.2 with your web service and deploying to WebLogic 12c (12.1) you will likely get java.lang.NoSuchMethodError exceptions. This is how to fix it.
21-Apr-2016
Conserving the Log4J MDC context when using a thread poolI've been updating logging in the web services I look after so that the WS-A MessageID can be logged for each request and for all of the messages written to the log during that request. On the most part putting this value it into the MDC and configuring the appender to write it out to the log is all that's required. However, when you start using thread pools e.g. with ThreadPoolExecutor the MDC goes haywire and that's because and I quote..."The MDC is managed on a per thread basis."
20-Mar-2016
Returning compressed MTOM data with JAX-WS DataHandlerA while back I've shown an example MTOM/XOP enabled web service using DataHandler. Although MTOM is great for optimising the output of a web service, sometimes it's just better to compress these results before sending them.
09-Feb-2016
Missing 30 minutes when parsing Java 7 ISO 8601 time zone formatI've been doing quite a bit of work with time conversion recently and started to use the new 'X' pattern in Java's SimpleDateFormat class to parse ISO 8601 time zones. Initially I treated this exactly the same way as the old 'Z' pattern for RFC 822 time zones. That ended up giving me 30 minute rounding errors in some cases. Upon reading the JavaDoc closer, I found this sentece hidden among all the verboseness...
07-Dec-2015
Maven WebLogic Plugin and the Java 5 source code bug plus how to fix itI've noted previously that the JWSC Ant Task fails to build Java sources above 1.5 source version due to a hardcoded "1.5" value in one of the Jar files. That was happening for the 12.1.2 version of the Ant task, it also appears to be a problem in the 12.1.2 Maven plugin as well as the 12.1.3 Maven plugin.
19-Oct-2015
Java code hanging in JDeveloper while establishing a T3 connection over VPN with ProxyIt's not often that I work on my company's VPN but on this occasion I did. One of the things that I've forgotten about was how proxies are automatically configured when the Cisco AnyConnect VPN Client establishes the VPN connection. The reason I need to be on the VPN was to access some internal servers and run some of my code that connects via the T3 protocol to a weblogic server and executed some remote methods. Every time I executed my code it just sat there as if frozen.
08-Oct-2015
A tip to bypass the Java unreachable statement compile error when debuggingMany a time when I'm debugging I feel quite lazy and often want to stop execution of code within a method before that method actually ends. The naive solution is to put in a return statement or throw an exception at the point where you want to stop running your code. Of course this doesn't work if you have lines of code after your return/throw clause.
28-Sep-2015
Take a heap dump with the HotSpotDiagnosticMXBean using JConsoleThis is a nice trick I learned over the past week while doing JVM heap analysis. You can use JConsole to take a heap dump of your JVM. Open the MBeans tab and navigate to com.sun.management, then HotSpotDiagnosticMXBean. This will display all the methods that can be invoked on this bean. We're interested in the dumpHeap method.
15-Sep-2015
Addressing the weblogic.application.ModuleException: Context path '/my_shared_lib' is already in use errorI've experienced a strange error coming out of the Weblogic wldeploy tool recently. It was reporting that a context path used by my shared library is already in use when I was trying to deploy a new web service. This seemed confusing to me - I had two web services that were both referencing the same shared library, the first service would deploy without any issues while the second would fail deployment with the context root error. Shared libraries by their nature are meant to be shared so what was the issue?
14-Sep-2015
How to get the WebLogic 12c JAX-WS runtime version numberI needed to know the version of the JAX-WS runtime that my installation of WebLogic (12.1.2) was using. This information was nowhere to be found in the documentation, so I decided to do some digging around to see what I can find.
01-Sep-2015
Hacking together a new digital photo frame with RaspberryPi, Minibian and JavaI've received my new Raspberry Pi Model A+ last week to use to replace the old Model A inside my photo frame, so I spent some time on the weekend setting that up. Last time that I've set this photo frame up, I went with out-of-the-box software, which did the job but did feel quite clunky. This time around I decided to do it better and write some software for the photo frame instead.
31-Aug-2015
HashMap keys and values passed as null with JAX-WS and WebLogic 12cI've noticed something curious while testing some web services recently. The keys and values in the HashMap object that's passed as an IN parameter to the web service were all being turned into nulls. If I passed one key/value pair, I'd get one key/value pair of nulls, if I passed two key/value pairs, I'd get a pair of null/null, and so on. I did eventually track down the problem and fixed it, but it has been an interesting issue to come across.
20-Aug-2015
Java StringWriter vs CharArrayWriter which one to choose for performanceI've been writing some code recently that manipulates lots of strings, specifically it does appends on them via a Writer. In Java there are two choices when it comes to a Writer that's oriented around Strings - CharArrayWriter and StringWriter. I got curious about which one would be best in terms of performance, these are my findings.
10-Aug-2015
JWSC does not play nice with Java 8, works fine with Java 7The more I work with JWSC, the more issues I seem to find. This new one is related to JavaCompiler and has the same smell as the other JWSC problem I've found. I've not had time to investigate this one in detail, but did find a workaround still.
27-Jul-2015
How to package your Java code as a native app on OSX into a DMG fileI've come across a nice tool in the Java 8 SDK (Java 7 has it too, but it has a different name) that lets you package your Java application as a native app for a range of platforms. This tool is called javapackager and it makes distribution of you Java apps so much easier than previously and best of all, it's part of the JDK itself.
22-Jul-2015
How to fix the JWSC WsBuildException: Wrong number of class filesSo I've continued moving my web services over from wsimport way of building them to JWSC and in my quest I keep hitting issues to do with JWSC compilation. This latest problem came in the form of 'Wrong number of class files' error message. This stumbled me for a while, it was an hour before my vacation was about to start, I just wanted to throw the laptop off the balcony at this point, but I managed to find a fix for this error.
17-Jul-2015
Java validation regex pattern for the OID root UID valueI've been focusing on making sure that the input to my web services at work is correct. One of these inputs happens to be the root part of a HL7 OID, which is a dot-separated UID. The values look like this '1.2.3', '9.5.6.3.7774.1', etc. It's very similar to an IP address, but can have more than 4 parts.
15-Jul-2015
JWSC from WebLogic 12.1.2 fails to build Java sources above 1.5I've written a post previously showing an example build system that uses JWSC to build your JWS based web service and then the wldeploy task to deploy it to WebLogic. Recently I've been expanding on the use of JWSC at work and have come up against a serious obstacle. JWSC would not build any Java sources that were above the 1.5 language level.
02-Jul-2015
JNativeHook 2.0.2 example code with logging and System.out disabledI've been playing around a little with JNativeHook Java library. "JNativeHook is a library to provide global keyboard and mouse listeners for Java. This will allow you to listen for global shortcuts or mouse motion that would otherwise be impossible using pure Java." What I really didn't like is it printed its licence details every time my code ran. I've dug into the JNI code and saw that it makes a callout to System.out to print this information. My solution was pretty simple, just disable the system output stream during initialisation.
30-Jun-2015
How to determine the JAXB runtime versionI've had to confirm which JAXB version I've been using for my runtime. In my search through various forums I've come across some code that more or less worked, but it wasn't very robust and wasn't explained well. I've put this together to answer the question properly.
22-Jun-2015
Performance difference between JAXB and Velocity generating XML fragmentsOne of the peculiarities we've noticed during our recent bout of performance testing at work was how much JVM heap space was being used and immediately garbage collected by one of our web services. The figures were quite staggering, with a peak use of 3Gb to generate the response message in some cases. This was not impacting the performance of the system overall, but still needed investigating as it gives lots of room for improvements.
12-May-2015
Are guard statements like isDebugEnabled() necessary when using Log4J ?I've been going through a fair amount of code that makes excessive use of log4j guard statements like isDebugEnabled() and began mercilessly removing their use. In my mind, these statements make the code messy and are really not necessary in most situations. In terms of performance, a guard statement does not necessarily give you any kind of boost, except in some odd edge cases. To prove my point however, I wrote some code and collected data to graph, here are the results.
05-May-2015
Change the JRE used for SoapUI on OSXI use SoapUI on a regular basis and today I wanted to change the JDK that it uses. I've noticed that by default the OS X installation of SoapUI 5.1.2 is using JRE 1.7. On my system, I've had the 1.8 JDK set as the default for quite some time, my ~/.profile file pointed to the 1.8 JDK bin directory for the PATH and the JAVA_HOME was set correctly, so it was puzzling to me why 1.7 was being picked up by SoapUI. I dug a little deeper and found the answer.
12-Apr-2015
WebLogic 12.1.2 not respecting @PostConstruct annotated method exceptionsI've been working on moving our web services at work to WebLogic 12.1.2 and noticed a curious issue. When I first moved one of the web services across, I knew for a fact that the method that's annotated with @PostConstruct would fail (due to changed data source names). However, when I deployed the service it was successful. Looking at the managed server logs, the service did indeed fail during initialisation, so subsequent calls to this service were failing for me. This seemed like a problem so I went out to verify it with a simple example.
31-Mar-2015
Tricking the Java compiler into allowing unreachable statements in codeI've been doing some tricky debugging recently where I had to provide one of my web services that required the environment it ran in configured a very particular way. The developer I was working with did not have such an environment and there was no time to set one up properly. This was a bit of a dilemma, however the issue we were trying to debug didn't require my service to fully execute, it was sufficient to get to a particular point in the execution and exit, this could be done on a vanilla system.
18-Feb-2015
Workaround for JDeveloper 12c Refactor Rename bugI use JDeveloper on an almost daily basis and when something as basic and fundamental to the product as the rename functionality breaks, it makes you want to tear your hair out. I'm talking about the Refactor Rename feature that has been broken since the 12c release. Luckily there is a workaround.
16-Dec-2014
A quick way to visually detect unused variables in code, and exterminate themMaking changes and fixes to other people's code is never fun. It is especially not fun when naming conventions and basic programming principles like using getter/setter methods are not used. It gets worse when part of a naming convention was used to specify variable scope only to have someone come along and change this variable's scope and not update its name to match the convention. Then there is the issue of unused variables. Unfortunately the former set of issues is a little harder to deal with, but unused variables can be removed at zero cost and so are a quick win in terms of cleaning up bad code. The trick is configuring your IDE to let you do this easily.
04-Nov-2014
Fix the javax.net.ssl.SSLException: Received fatal alert: illegal_parameter in SOAP UII've started receiving the 'javax.net.ssl.SSLException: Received fatal alert: illegal_parameter' exception when sending requests to some web services. These services were all working fine previously and continue to work when invoked from other applications e.g. OSB. This could only mean that the issue was local. Turns out that the problem started occurring due to a JDK upgrade.
23-Jul-2014
NetBeans 7.1.2 does not work with JDK 8I've recently installed the JDK 8 on my rMBP and all of a sudden NetBeans stopped working for me. I've dug into this a little further and tried several things, none of which worked, in the end I ended up forcing NetBeans to use JDK 7 and everything was working again.
14-Apr-2014
JDeveloper 11g and 12c do not support new Java 7 Syntax: Try With ResourcesNow that Java 8 has been released, you would think that the IDE that comes from the makers of Java would support all of the language syntax that dates back to the Java 7 days, but alas it does not. I tried both JDeveloper 11g (11.1.2.0.0) and 12c (12.1.2.0.0) and neither appear to support the try-with-resources syntax that was introduced as a part of JDK 7. However, compiling the code has no problems, both IDEs are able to compile source code that is using this new syntax.
04-Mar-2014
OS X Mavericks breaks the Java Dock Name functionalityI've been updating a Swing app recently and discovered that under OS X Mavericks the dock name setting does not work as expected. Previously it was possible to set this programatically, now it seems that the dock name can only be set via a java startup option.
06-Oct-2013
Implementing Thingiverse OAuth2 with Google App EngineI've been working on the next version of Extrudifier that will have integration to Thingiverse for direct uploads and Thing creations right from the Extrudifier app. This needed a bit of work to get the OAuth2 workflow set up, this is what I describe in this post. I chose to go with Google App Engine and Servlets because this was the easy and free and could be up and running quite quickly. All that's needed to implement this integration is a bit of JavaScript, a Java Servlet and some App Engine magic.
04-Sep-2013
How to get a null return from a Java constructorI was looking at some Java code recently that got me stuck for quite some time. It seemed to be doing the impossible, getting a null reference when creating a new object. I was starting to think that maybe there is something wrong with the JDK, then I've created a new object of a similar type that worked ok, but the original object was still being created as a null reference. This was very confusing, but the answer to why this was happening was a very simple mistake in the code.
28-Aug-2013
JVisualVM 64 and 32 bit incompatibility and seg faultsI've been trying to set up JVisualVM to monitor a number of JVMs that are running as a part of an application server install. These JVMs are on JDK5, which can be monitored with JVisualVM, but for some reason every time I started it up, it crashed with a seg fault.
13-Aug-2013
XJCTask task failing on OSX with JDK 6 when using 3rd party extension for JAX-WSI've recently had to use a different JAX-WS library for some development work on a project, which worked great by placing all the jar files into the Java Extensions directory, however when I went back to trying to compile another project I had, everything started to break, I was getting exceptions I have never seen before. After a bit of investigation, it turned out that the NetBeans JAXB libraries do no like being mixed with the JAX-WS libraries. The fix is simple, remove the 3rd party libraries from the Extensions directory.
04-Jun-2013
Stand alone CSF (Credential Store Framework) exampleI've been trying to figure out the Oracle CSF 11g documentation over the last couple of days without getting very far. The documentation is a bit incomplete and has errors in it (referencing classes that do not exist for example). So since I had to implement this for the project I am on, I had no choice by to figure it out myself.
11-Apr-2013
Playing with varargsVarargs in Java are very handy and I've been using this feature quite a bit lately, but I did find some shortfalls that unfortunately mean I have to write some ugly code to get around the limitations.
09-Apr-2013
Simplifying code with Exception throwingAs I've been working on the server code for my game, I've been noticing that the complexity of it is increasing but also duplicating unnecessarily. After thinking about it for some time and seeing why my code was exhibiting these traits I concluded that it was due to how I was handling errors.
25-Mar-2013
JSON-RPC and Java collections do not play niceI've been using the JSON-RPC library for some time now to write the server for my game, thus far I've only had a need to transport simple objects back to the client, but recently I've had a need send a collection of objects back. This is where I found that JSON-RPC falls short if you try to use the standard Java collections.
13-Mar-2013
JDO, you're dumped, App Engine and bi-directional relationshipsAfter searching high and low to find out how to add a child object to a parent in JDO efficiently and getting ever more frustrated with the lack of good documentation, I've decided to just write some of my own tests to see what's possible and how well it works.
12-Mar-2013
Storing sparse 2D map coordinates, proximity and data store indexesWhile working on my game, one of the things that I've been trying to work out is how to best store the map coordinate data for the buildings I place on the map and to tell if a map cell is occupied already. In a typical scenario where buildings are of homogenous dimensions all I would need is the coordinate of the building and it's dimensions, this would give me a bounding box of map cells that the building occupies. However, in my game the buildings cannot be described by simple bounding boxes.
11-Mar-2013
Getting 100% JUnit Test Coverage for JDO objects in App EngineOnce I started writing unit tests for the objects I was persisting into the HRD in App Engine via JDO, I've noticed that the coverage for all of my classes was below 100%. This didn't seem right to me because I was certain that I was testing everything.
10-Mar-2013
Parents, Children and Ancestor queries in Google App Engine with JDOFetching a child object by the ID of the parent using JDO had me stuck for a while. According to this article "reads, writes, and ancestor queries will always reflect the results of the commit" in the Google App Engine data store (HRD). After trying various things and reading lots of documentation and forum posts it all came down to how I modelled my objects. Now when I persist a parent object with an attached child, then immediately perform a query to fetch that child, the data returns as expected.
06-Mar-2013
A simple JSON-RPC server with Google AppEngineI've started exploring the use of Google AppEngine for a project I'm working on. JSON was one of the technologies that was going to be used and JSON-RPC looked like an attractive way of exposing functionality without writing your own server network code.
15-Feb-2013
Using Java HIDAPI on OS X to read temperature from the TEMPer1 sensorThe TEMPer1 USB Thermometer finally arrived a few days ago, so I started to play around with it. It comes with a CD with software on it, which I promptly disregarded. After searching around the net, I could not find anyone that's written Java code to interface with the device, but I did find other useful information like javahidapi and this blog post: Controlling your TEMPer on Mac OS X. Now my Objective-C is quite bad, but I was able to follow the code to extract the required information to read the temperature from the TEMPer1.
05-Feb-2013
Changing Java Swing Nimbus L&F default coloursOne of the projects I've been working on recently had quite an extensive UI written (by me) using Swing. The Nimbus L&F was used throughout to make it look a bit more modern. Nimbus is a nice looking UI L&F, however the choice of some colours within its theme is a little odd.