Skip to content

Commit

Permalink
Add a PATCH extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Beryozkin committed Jul 26, 2015
1 parent d29745f commit 200b282
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
@@ -0,0 +1,39 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.cxf.jaxrs.ext;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.ws.rs.HttpMethod;

/**
* Indicates that the annotated method responds to HTTP PATCH requests.
*
* @see HttpMethod
*/
@Target({ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
public @interface PATCH {

}
Expand Up @@ -91,6 +91,7 @@
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.apache.cxf.jaxrs.ext.Nullable;
import org.apache.cxf.jaxrs.ext.Oneway;
import org.apache.cxf.jaxrs.ext.PATCH;
import org.apache.cxf.jaxrs.ext.StreamingResponse;
import org.apache.cxf.jaxrs.ext.search.QueryContext;
import org.apache.cxf.jaxrs.ext.search.SearchCondition;
Expand Down Expand Up @@ -286,6 +287,14 @@ public Book retrieveBook(Book book) {
return book;
}

@PATCH
@Path("/patch")
@Produces("application/xml")
@Consumes("application/xml")
public Response patchBook(Book book) {
return Response.ok(book).build();
}

@DELETE
@Path("/deletebody")
@Produces("application/xml")
Expand Down
Expand Up @@ -88,6 +88,17 @@ public void testRetrieveBookCustomMethodAsyncSync() throws Exception {
wc.close();
}

@Test
public void testPatchBook() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/patch";
WebClient wc = WebClient.create(address);
wc.type("application/xml");
WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
Book book = wc.invoke("PATCH", new Book("Patch", 123L), Book.class);
assertEquals("Patch", book.getName());
wc.close();
}

@Test
public void testDeleteWithBody() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/deletebody";
Expand Down

0 comments on commit 200b282

Please sign in to comment.