ServiceStack.Java Accessing the Route annotation at runtime

Hi,

I need to access the Route annotation at runtime, can you add @Retention(RetentionPolicy.RUNTIME) on the Route annotation so that it becomes available at runtime?

Here’s what I want to do to give you more context: I want to create a “sendRequest” method that takes a request as parameter and using reflection I want to inspect the Route annotation’s VERB and use correct method (get, post, put) to send the request to the server.

Thanks

I’ve added the @Retnention() attribute on all built-in Attributes in this commit as requested.

The next Java plugin release will be within 1-3 days, we’re still doing some integration testing with it.

FYI this sounds like exactly what we’re doing in the StripeGateway by using IGet, IPost marker interfaces which allows use to send any Stripe DTO with:

gateway.Send(request); 

And it will chose the appropriate verb based on with IGet marker interface the Request DTO has. I’m exploring how to add this to Native Types as well.

There’s now support for using the IGet, IPost, IPut, IDelete and IPatch interface markers on Request DTO’s, e.g:

public class SendGet : IReturn<SendVerbResponse>, IGet
{
    public int Id { get; set; }
}

public class SendPut : IReturn<SendVerbResponse>, IPut
{
    public int Id { get; set; }
}

Which are now used internally in the existing Send and SendAsync API’s on all Service Clients to determine which HTTP Method to use so now you can send all DTO’s using the same API’s and it will choose the appropriate HTTP method, e.g:

var response = client.Send(new SendGet { Id = 1 }); // sends with GET

var response = await client.SendAsync(new SendPut { Id = 1 }); // sends with PUT

More examples are available in the ServiceClientTests.

Java Client

The equivalent API’s are also available in the Java JsonServiceClient where the interfaces are now emitted in the generated Java DTO’s e.g

public static class SendGet implements IReturn<SendVerbResponse>, IGet { ... }

public static class SendPut implements IReturn<SendVerbResponse>, IPut { ... }

and works the same way as the C# client, e.g the equivalent API’s above in Java look like:

SendVerbResponse response = client.send(new SendGet().setId(1));

client.putAsync(request, new AsyncResult<HelloAllTypesResponse>() {
    public void success(HelloAllTypesResponse response) { ... }
});

More examples are in the Java Sync and Async ServiceClient Tests.

This will be available in the next release of the Java plugins in a couple of days.