In the client you can do:
Response r = Restfulie.at(uri).get();
System.out.println(r.getCode());
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
try {
Response response = Restfulie.at(uri).throwError().get();
} catch (BadRequestException ex) // when statuscode 400 {
// do something
Should we support:
Restfulie.at(uri).with(throwError()).get()?
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
I was working on something like that, for when someone create an
custom feature. He would have to implement the interface and load it
to the stack as:
Restfulie.at().withFeatures(MyCustom.feature).get(); // with() is much
better then withFeatures();
We could use it for our built-in features too, as you said, so that
we won't have to change our fluent interface every time a new feature
appear. The only 'problem' that comes to my mind, is the fact that
every method would have to be static.
Doni.
On Tue, Feb 8, 2011 at 11:57 AM, Guilherme Silveira
Just the loookup method, no problem bringing functional aspects to
Java to be able to create a DSL.
public Request with(Feature) {
load into stack
return itself
}
BTW, throwing exceptions is not considered that Restful... the return
code should always be verified in order to do something. Its more
clever to add callbacks in specific situations (i.e. 503, try again
later) than just throwing an exception.
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
Doni.
On Tue, Feb 8, 2011 at 12:31 PM, Guilherme Silveira
There is probably something more interested that can be built around
Restfulie, such as automatically asking the user for permission if its
a desktop app, or redirecting to the oauth provider if its an oauth
based app... but those can be left for later, under someone's request
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
On Tue, Feb 8, 2011 at 12:50 PM, Jose Donizetti
On Tue, Feb 8, 2011 at 1:46 PM, Guilherme Silveira
The exception message (or error message) should be serialized in the
body, in xml, json,text/plain or html, as you wish, like in:
400 Bad Request
Content-type: application/json
{ 'error' : 'message' }
Can you do that?
The reason is, according to the specs this is an example of a http response:
400 Bad Request
In this case, the status line *must* contain the correct message for
400, which is Bad Request, not any other string.
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
I am not sure, those might be two different issues.... if an error
occurs do you want to serialize data + error or just the error?
Can you show the entire method code so we can find a solution?
Regards
Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/
Firstly, the method public void badRequest(java.lang.String message)
in DefaultStatus.java is needed?
Secondly, In my opinion, serialize just the error would be better.I
don't have a specific method because I'm justing making some POC's.
But, for example:
public Produto salvar(Produto produto)
{
return tenant.save(produto);
}
public void badRequest(List<?> errors) {
result.use(representation()).from(errors, "errors").serialize();
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
> On Wed, Feb 9, 2011 at 12:56 PM, RafaelViana <rfl.vi...@gmail.com> wrote:That's my doubt. What is the utility if i can't catch it? (or there
> > Firstly, the method public void badRequest(java.lang.String message)
> > in DefaultStatus.java is needed?
>
> yes. One should be able to specify any message explaining the error.
>
are other cases that can catch it?)
I'll try it.
> > Secondly, In my opinion, serialize just the error would be better.I
> > don't have a specific method because I'm justing making some POC's.
> > But, for example:
>
> > public Produto salvar(Produto produto)
> > {
> > return tenant.save(produto);
> > }
>
> you should avoid the exceptions with validations. E.g if you're using
> hibernate validation:
>
> public Produto salvar(Produto produto) {
> validator.validate(produto);
> validator.onErrorSendBadRequest();
> return tenant.save(produto);
>
> }
>
> this way all errors are serialized with the method:
>
But, for example, If happens an exception in the save method as
ConstraintViolationException or other? How can I send a specific
message to the client explaining it?