Anoter option is to introduce a cxf-specific extension which would allow the same method be treated as either a resource method or a
subresource locator method. It won't interoperate between JAX-RS impls, but it would let users to save on creating a new method -
which might be not that easy on a more controlled environments - like this is the 3rd part interface we use and we can't change it
type of requirements. The choice will up to a user (enable this feature or not - disabled by default)
Cheers, Sergey
Hi Gabo
Will this work for you :
class AccountService() {
@GET
@Path("/Account/{uniqueId}")
public Account get(@PathParam("uniqueId") long uniqueId) {
return getAccount();
}
@Path("/Account/{uniqueId}")
public Account getAccountProperty(@PathParam("uniqueId") long uniqueId) {
return getAccount();
}
}
?
So GET /Account/1 will be delivered to get(), while /Account/1/accountId will
be handled by Account itself...
Prehaps you may need to add a trailing '/' to the subresource method, but I
think it should work just fine without it.
Cheers, Sergey
Hi Sergey,
I just noticed that in the user's guide. My apologies with that. Just a follow-up though, is it possible to be able to receive an
XML representation of Account in invoking AccountService.get(), while having that sub-resource locator feature? In removing the
@GET in AccountService.get(), I am no longer able to invoke the said method.
Again, my thanks!
Gabo
Sergey Beryozkin wrote:
Hi
you have @GET on AccountService.get() so it's not seen as a subresource locator
method.
if you push @GET down to the Account.getAccountID then it will work...
Cheers, Sergey
Hi All,
I have the following resources:
//the service class:
@ConsumeMime("text/xml")
@ProduceMime("text/xml")
public class AccountService{
@GET
@Path("/Account/{uniqueId}")
public Account get(
@PathParam("uniqueId")
long uniqueId
) {
//do something here and return the Account object
}
}
//the account class
@XmlType(name="Account")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name="Account")
public class Account {
private String accountID = ""
@Path("accountID")
public String getAccountID() {
return accountID;
}
public void setAccountID(String accountID) {
this.accountID = accountID;
}
}
beans.xml having the following configuration for the service instance:
<jaxrs:server id="accountRestService" address="/rest/Accounts">
<jaxrs:serviceBeans>
<ref bean="AccountService" />
</jaxrs:serviceBeans>
</jaxrs:server>
Now, accessing the method that returns an Account object works fine, i.e. access to
http://localhost:8080/rest/Accounts/Account/1 responds with the xml representation of the Account object.
However, I was hoping to take advantage of Sub-resource locators as mentioned in
http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html . When I try accessing
http://localhost:8080/rest/Accounts/Account/1/accountID , I end up getting a 'No operation matching request'. I'm thinking this
might be caused by the fact that the said method does not take any parameters? or that I have JAX-WS annotations at class level
for the Account class?
Gabo Manuel
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.175 / Virus Database:
270.8.2/1740 - Release Date: 10/22/2008 7:24 PM