简体   繁体   中英

is there a way to invoke HTTP PATCH on a REST service from client using Jersey Clinet

I am trying to figure out how to invoke/call PATCH method provided by a service from the client through Java program using Jesrey Client.

I have tried a lot of ways and read many things online. But, it seems like this is not supported in jersey yet. Any help will be greatly appreciated.

One of the Sample Code that i tried.

    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);       
    clientConfig.getClasses().add(ProtobufMessageBodyReaderWriter.class);       
    CLIENT = Client.create(clientConfig);
           CLIENT.resource(BASE_URL);
    webResource = CLIENT.resource(BASE_URL);    
    T response = null;
    ClientResponse cResponse = null;
    cResponse = webResource.type(MediaType.APPLICATION_JSON).method("PATCH",ClientResponse.class, requestObject);

This gives "java.net.ProtocolException: HTTP method PATCH doesn't support output" . Can anyone suggest me on how to get this done the above way or any other way

From quickly reading on Jersey's forum, there seems to be a bug.

Can you use an HTTP client instead of webResource.type(...).method("PATCH") ? Use Apache HTTP Commons for instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM