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:

import javax.ws.rs.client.*;
import org.apache.cxf.transport.http.*;


Client client = ClientBuilder....

// set property "use.httpurlconnection.method.reflection"
client.property(URLConnectionHTTPConduit.HTTPURL_CONNECTION_METHOD_REFLECTION, Boolean.TRUE.toString());

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:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>3.1.13</version>
    <scope>provided</scope>
</dependency>

Note: the property can also be set globally using System.setProperty() method or with command line parameter -Duse.httpurlconnection.method.reflection=true.