How to send HTTP requests with unsupported methods in Tomee JAX-RS
When working with REST services you can easily come across a service which utilizes other method than those specified in HTTP/1.1 RFC.
Usually it will be PATCH method which is specified in RFC 5789.
If you use CXF framework client in Tomee, you will probably get Invalid HTTP method
exception.
Problem is that CXF uses standard java.net HTTP client, which has fixed set of allowed methods. This list doesn’t even include above mentioned PATCH and it’s not going to be changed as is stated in bug report here.
Fortunately, CXF has quick and dirty fix to address this issue:
Internally, it’s implemented by directly changing method
field in java.net.HttpURLConnection
using Field.setAccessible()
.
You can check URLConnectionHTTPConduit source code.
This code is delivered as maven module:
Note: the property can also be set globally using System.setProperty()
method or with command line parameter -Duse.httpurlconnection.method.reflection=true
.