Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
fix WebResourceFactory support for sub resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoghisi authored and alex-shpak committed Feb 11, 2019
1 parent d97ae75 commit 6e42500
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg

if (httpMethod == null) {
// the method is a subresource locator
return WebResourceFactory.newResource(responseType, newTarget, true, headers, cookies, form, null);
return WebResourceFactory.newResource(responseType, newTarget, true, headers, cookies, form, invoker);
}

// accepted media types
Expand Down
26 changes: 26 additions & 0 deletions rxjava2-client/src/test/java/RxJerseyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,32 @@ public String empty() {
public String error() {
throw new BadRequestException();
}

@Path("subresource/{id}")
public ServerSubResource subResource(@PathParam("id") String id) {
return new ServerSubResource(id);
}
}

public static class ServerSubResource {

private final String id;

public ServerSubResource(String id) {
this.id = id;
}

@GET
public String getId() {
return id;
}

@GET
@Path("attribute")
public String attribute() {
return "attribute";
}

}

public static class Entity {
Expand Down
46 changes: 46 additions & 0 deletions rxjava2-client/src/test/java/SubResourceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import static org.junit.Assert.assertEquals;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import org.junit.Test;

import io.reactivex.Single;

public class SubResourceTest extends RxJerseyTest {

@Test
public void shouldReturnContentFromSubResourceWithoutPath() {
SingleResource resource = resource(SingleResource.class);
String subResourceId = resource.getSubResource("someId").getId().blockingGet();

assertEquals("someId", subResourceId);
}

@Test
public void shouldReturnContentFromSubResourcePath() {
SingleResource resource = resource(SingleResource.class);
String attribute = resource.getSubResource("someId").getAttribute().blockingGet();

assertEquals("attribute", attribute);
}

@Path("/endpoint")
public interface SingleResource {

@Path("subresource/{id}")
SingleSubResource getSubResource(@PathParam("id") String id);
}

public interface SingleSubResource {

@GET
Single<String> getId();

@GET
@Path("attribute")
Single<String> getAttribute();

}
}

0 comments on commit 6e42500

Please sign in to comment.