So most of the time you are probably aware of method references that either reference instance of static methods directly, and they are useful but not necessarily that interesting.
Integer example = 1;
// We can bind the instance variables, in this case just the return type is bound but there couple be method parameters also
Supplier<String> s = example::toString;
// We can bind to static method, here the generic parameter are the method parameter (more...)
When doing test automation it is often the case you need to know the name of the current machine in order to prompt another machine to connect to it, particularly if you are running your tests in parallel. This week I was trying to get the server under test to connect back to a WireMock server running on the slave test machine.
The standard response on stack overflow is to use the following pattern to (more...)
Somedays you come across some code and think that's pretty, why didn't I think of that? So my long time colleague Mark Warner has a nice twist on the standard name/value store pattern using method references to deal with converting from a String.
int size = store.getProperty("cache.limit", 500, Integer::parseInt);
boolean enabled = store.getProperty("cache.enabled", true, Boolean::getBoolean);
I took his example and refactored it slightly to return Optional, and I ended up with (more...)
So I got frustrated with two limitations of the Optional interface in JDK 8. The first problem is that there is no obvious way to perform an else operation in a block as there is only a
method unless you are using an old school if statement. The second problem is of course the old chestnut that even if you could do that the methods would not be able to throw a checked exception. (more...)
A really quick post today, I was writing a unit test that needed to put up a temporary JAX-RS resource in order to test something very specific with out the need of a large testing framework. Unfortunately the code I was using didn't know about replacing zero with a random allocated port so I had to do something different. The nice tidy code that does this looks like the following:
try(ServerSocket ss = new ServerSocket(0)) (more...)
So I was refactoring some code to use non-locking collection classes and I noticed the this significant different between ConcurrentMap.computeIfAbsent
. They key different is that for the former default implementing the mapping function can be called many times for a particular key where as for the concrete implementation it will be called only once.
Right okay so armed with that you know that any collection that implements just ConcurrentMap will inherit (more...)
So I was presented with a large suite that I need to distribute amongst an arbitrary number of Hudson slaves. Now my first guess would be to hand balance this into N sub suites; but that would require on-going work and would need to change depending on the number of nodes. (We have a target of 30 minutes to run all tests in parallel which is going to take some machines)
Weblogic server comes with a shared library so you can deploy JAX-RS 2.0 applications; but is limited to Jersey version 2.5.1 and the instructions for changing this are not entirely obvious or straightforward
. I have recently joined a new team at Oracle and one of the first things I did was to look at upgrading the dependent libraries. Now I have talked to the Jersey team and they don't support this combination; (more...)
I was looking at a bit of code was leaking class loaders when deployed to tomcat - so I wanted to quick rule out that a background Thread was holding onto the loader. Pain by eye, it is quite easy with a few unix commands to process the stack trace, filter for the lines that contain the thread name, filter for just the thread names and sort:
sudo -u tomcat jstack 1853 | grep " (more...)
Now that we can know how much activity I did yesterday
, we can look at whether I am getting enough sleep.
A quick look at the Apple documentation
lets us see that
is the right measure to be using. This is a subtype of
so we can use the querySampleType function.
First of all here is the same boilerplate code, with the minor modification to allow for access to the sleep data (more...)
which is most cases will be null and if not null will not likely work in a multithreaded server environment. (This is because in the background the default Jersey client will use URL.openConnection)
Now you can work around this by using (more...)
As people who know me might know I have been playing around with various wearables for some years now, starting with a Nike Fuel Band, and also trying out products from Misfit and UP along the way. I have mostly just watched with interest as my exercise levels, and indeed sleep now we have a little one in the house, has gone up and down over time.
More recently with the arrival of HealthKit there (more...)
Every now and then you look at some code and think that it cannot be possibly be wrong. Once you have ruled out a simple programmer screw up / enemy action in code (Make sure you read Java Puzzlers or similar) or a concurrency issue (Read Java Concurrency or go on Dr Heniz excellent course
) you should sit back and take a few days and then starting thinking about whether the JDK is indeed (more...)
A long while ago a optimisation was added to the JVM
so that if the same exception is thrown again and again and again a single instance of the Exception is created without the stack trace filled in in order to increase performance. This is an excellent idea unless you are trying to diagnose a problem and you have missed the original error.
If you forgot about this optimisation you send the afternoon looking at (more...)
JAX-RS contains a rather nice handy representation of the a Link
that can be serialised with and adapter into XML and JSON, unfortunately there is a bug in the JAX-RS spec that means that the standard adapter provided is missing the setters required
to deserialise the Link later on.
This isn't a problem if you are using the JAX-B RI as it appears to be more relaxed than the standard; but it will be a (more...)
A couple of weeks ago
A couple of months ago I was looking how I was going to engineers new REST API for an Oracle Cloud project. Once of the things I had planned to do was to use the declarative link injection created in Jersey 1.x by Marc Hadley. Sadly this hadn't been forwarded ported yet, so a quick chat to the project lead and I took on the
medium sized job (more...)
So I am working on a new REST API for an upcoming Oracle cloud service these days so one of the things I needed was the ability to automatically generate a JSON Schema for the bean in my model. I am using MOXy to generate the JSON from POJO and as of version 2.5.1 of EclipseLink
it now has the ability to generate a JSON Schema from the bean model.
There will be (more...)
The PATCH method
is one the the less well loved HTTP methods simple because until recently there really wasn't a standard PATCH format. This has been standardized for JSON for a while
now so there are quite a few libraries that will do the heavy lifting for you. For the purposes of this blog I am going to use json-patch
although it would be easy to adapt this particular implementation to the patch library of (more...)
Just an incremental release
with a cluster of bug fixes:
- Upgrade to jsonschema2pojo 0.4.0
- Fixed bugs where generation would fail due to duplicated class names caused by similar resource names
- Upgrade Jersey 2-ALPHA deps to 2.5.1 some small changes in the APIs
- Fix for XSL for correct return on onClick hander, allows better integration with IDE's
- Interface of MethodNode.getSupportedOutput to support latest WADL model
- Method parameter were not being shown (more...)