RE: Jackson extension performance question
Tim: Was trying to use your LocalJacksonConverter in a Restlet application that I have. But I wasn't sure how to go about doing that. I figured that I should start in my createInboundRoot with something like... ObjectMapper objectMapper = new ObjectMapper(); LocalJacksonConverter localJacksonConverter = new LocalJacksonConverter(objectMapper); But that was as far as I got (problem is my small brain, not your excellent code :) ). I haven't used the Restlet Guice extension and my experience with injection is very limited. Not counting vaccines :) :). Thanks for your help, RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3046480
RE: Jackson extension performance question
Tim: After some additional searching, I think I can get by with a simple singleton OBJECT_MAPPER for each of my ServerResources. It's probably not as good as one for all the ServerResources, but it is much simpler - and has already provided a fairly dramatic performance improvement. So please don't spend any time on my behalf (I am too deep in your debt already :) ). RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3046499
RE: Does the OAuth2 extension support client-side/user agent/implicit grant flow?
I am pretty sure the answer to this question is No. Looking at code in org.restlet.ext.oauth.Flow anything related to the userAgent flow has been commented out. Maybe it will be revived one day... wish I had the ability to do it :) RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3041902
Does the OAuth2 extension support client-side/user agent/implicit grant flow?
I have used the OAuth2 extension to build a Restlet-based and plain Java clients for my API (Restlet/GAE). These both use OAuth's authorization flow which is supported by the OAuth2 extension. Now I wanted to build a JavaScript client. JavaScript clients seem to require a different flow (variously named user agent or implicit grant or client side). My question is does the OAuth2 extension support this flow? Looking at the source I see that in addition to the authorization flow there is also a password flow and a none flow - but I can't tell if those are meant to work with JavaScript clients. Thanks in advance for any advice, RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=3041709
RE: OAuth2: How to resolve Unable to get the template authorize.html.
Thank you for the response. I was able to use setTemplateLoader to get my own code to point at a particular directory - but I didn't see how to change what AuthPageServerResource was doing (without of course changing that code and having my own version of it - which I didn't want to do). Did you find a way to change the behavior of AuthPageServerResource? Thanks again, RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/OAuth2-How-to-resolve-Unable-to-get-the-template-authorize-html-tp7575959p7578246.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2993078
Re: Handling exceptions/errors when using Restlet for Client and Server....
Tim: Thanks for the update to your code and for the explanation. While my code is a little different than yours, sending along a StringRepresentation of the error in the response's entity and then having the client look in the entity in case of an error worked just fine for me. Would be much cleaner to just be able to use status.getDescription() but I guess that will have to wait for the fixes to ClientInvocationHandler. Do you think that this problem has persisted this long due to the lack of clients built with Restlet (vs. the much larger number of servers built with Restlet)? Thanks again for providing the workaround!! RB On Wed, Jul 11, 2012 at 1:52 PM, Tim Peierls [via Restlet Discuss] ml-node+s1400322n757820...@n2.nabble.com wrote: I've updated the snippet in https://pastebin.com/3nzsjFi1 to demonstrate a potential workaround using a custom StatusService and special client-side handling. This example just deals with a StringRepresentation to pass a custom error status description, but the technique could be generalized to use an arbitrary custom error representation. The use of the client proxy mechanism is orthogonal to this workaround, but since this snippet was originally about how ResourceExceptions passed through this mechanism don't preserve full error information, I've kept it in. The heart of the problem, as I see it, is that the ClientInvocationHandler throws away important information when handling errors. Until that's changed, the best you can do is to explicitly manage the error entity, as in the workaround in the snippet. It's not pretty, but it works. --tim On Tue, Jul 10, 2012 at 8:36 PM, Richard Berger [hidden email]http://user/SendEmail.jtp?type=nodenode=7578202i=0 wrote: And one further note, wrapping the client resource does not seem to change the results. That is to say, going from: ClientResource commitsResource = new ClientResource(getContext(), commitsRef); commitsRep = commitsResource.get(); To: ClientResource clientResource = new ClientResource(commitsRef); CommitmentsResource commitsResource = clientResource.wrap(CommitmentsResource.class); Representation commitsRep = null; commitsRep = commitsResource.represent(); Changes nothing RB On Tue, Jul 10, 2012 at 4:22 PM, Richard Berger [hidden email]http://user/SendEmail.jtp?type=nodenode=7578193i=0 wrote: Yes, I only see this problem when I go through my Restlet client, not when using a browser. In order to make sure the API I am developing is usable by real client developers, I figured I should also build a client. I chose Restlet as the technology for that client - perhaps that wasn't the best possible choice (if no one else does that). Thanks for the response... RB On Tue, Jul 10, 2012 at 2:09 PM, Bjorn Roche [via Restlet Discuss] [hidden email] http://user/SendEmail.jtp?type=nodenode=7578193i=1 wrote: I can't help you directly, but I can say that I use restlet server (but not client) and I am pretty sure I DON'T have this problem. Is this a bug in the client that it can't access the http status message? That is what I'm gathering from the thread you linked as well. bjorn On Jul 10, 2012, at 1:18 PM, Richard Berger wrote: My question is similar to that raised at: http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 , but since that has not been answered and this seems like a really basic issue, I thought I would try posting again. The question is simply this - how to get the details of an error/exception that occurs on the Restlet server back to my Restlet client? I can see how to do this if my client were just a browser (I could construct an HTML page on the server and return it). I thought that it would be pretty simple - set the Status code and Status description. But as the discussion above points out, that doesn't work. I then thought that I could just set the Status code and send back a String Representation of the error message. But that doesn't work either. In particular, if I have: msg = error xyz occurred; this.setStatus(Status.SERVER_ERROR_INTERNAL, msg); StringRepresentation result = new StringRepresentation(msg, MediaType.TEXT_PLAIN); return result; The client side call: commitsRep = commitsResource.get(); Sets commitsRep == null (!). Note: it is only set to null when the status != 200. So, I could set the status to 200 and then return the StringRepresentation and then on the client, check to see if I have a StringRepresentation (which would be an error) or some other type (which would be a success). But surely there has got to be an easier way - what am I missing? (I have created my own StatusService
Re: Handling exceptions/errors when using Restlet for Client and Server....
Excellent points - I didn't quite realize that the Status was restlet specific and now it makes more sense to me that (as you put it) the illusion isn't extended all the way to Exceptions. Thanks for your ongoing assistance and information! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190p7578206.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2984253
Handling exceptions/errors when using Restlet for Client and Server....
My question is similar to that raised at: http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 , but since that has not been answered and this seems like a really basic issue, I thought I would try posting again. The question is simply this - how to get the details of an error/exception that occurs on the Restlet server back to my Restlet client? I can see how to do this if my client were just a browser (I could construct an HTML page on the server and return it). I thought that it would be pretty simple - set the Status code and Status description. But as the discussion above points out, that doesn't work. I then thought that I could just set the Status code and send back a String Representation of the error message. But that doesn't work either. In particular, if I have: msg = error xyz occurred; this.setStatus(Status.SERVER_ERROR_INTERNAL, msg); StringRepresentation result = new StringRepresentation(msg, MediaType.TEXT_PLAIN); return result; The client side call: commitsRep = commitsResource.get(); Sets commitsRep == null (!). Note: it is only set to null when the status != 200. So, I could set the status to 200 and then return the StringRepresentation and then on the client, check to see if I have a StringRepresentation (which would be an error) or some other type (which would be a success). But surely there has got to be an easier way - what am I missing? (I have created my own StatusService on the server, I have thrown my own exception, but no joy). Thanks in advance for any hep - and thanks to Tim P for collecting all the links in the thread above - but those weren't enough for me to work around the problem. RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982701
Re: Handling exceptions/errors when using Restlet for Client and Server....
Yes, I only see this problem when I go through my Restlet client, not when using a browser. In order to make sure the API I am developing is usable by real client developers, I figured I should also build a client. I chose Restlet as the technology for that client - perhaps that wasn't the best possible choice (if no one else does that). Thanks for the response... RB On Tue, Jul 10, 2012 at 2:09 PM, Bjorn Roche [via Restlet Discuss] ml-node+s1400322n7578191...@n2.nabble.com wrote: I can't help you directly, but I can say that I use restlet server (but not client) and I am pretty sure I DON'T have this problem. Is this a bug in the client that it can't access the http status message? That is what I'm gathering from the thread you linked as well. bjorn On Jul 10, 2012, at 1:18 PM, Richard Berger wrote: My question is similar to that raised at: http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 , but since that has not been answered and this seems like a really basic issue, I thought I would try posting again. The question is simply this - how to get the details of an error/exception that occurs on the Restlet server back to my Restlet client? I can see how to do this if my client were just a browser (I could construct an HTML page on the server and return it). I thought that it would be pretty simple - set the Status code and Status description. But as the discussion above points out, that doesn't work. I then thought that I could just set the Status code and send back a String Representation of the error message. But that doesn't work either. In particular, if I have: msg = error xyz occurred; this.setStatus(Status.SERVER_ERROR_INTERNAL, msg); StringRepresentation result = new StringRepresentation(msg, MediaType.TEXT_PLAIN); return result; The client side call: commitsRep = commitsResource.get(); Sets commitsRep == null (!). Note: it is only set to null when the status != 200. So, I could set the status to 200 and then return the StringRepresentation and then on the client, check to see if I have a StringRepresentation (which would be an error) or some other type (which would be a success). But surely there has got to be an easier way - what am I missing? (I have created my own StatusService on the server, I have thrown my own exception, but no joy). Thanks in advance for any hep - and thanks to Tim P for collecting all the links in the thread above - but those weren't enough for me to work around the problem. RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982701 - Bjorn Roche http://www.xonami.com Audio Collaboration http://blog.bjornroche.com -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982833 -- If you reply to this email, your message will be added to the discussion below: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190p7578191.html To unsubscribe from Handling exceptions/errors when using Restlet for Client and Server, click herehttp://restlet-discuss.1400322.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=7578190code=cmljaGFyZEBsYW5kaXNmYW1pbHkub3JnfDc1NzgxOTB8LTYxMDE0ODc2 . NAMLhttp://restlet-discuss.1400322.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190p7578192.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982862
Re: Handling exceptions/errors when using Restlet for Client and Server....
And one further note, wrapping the client resource does not seem to change the results. That is to say, going from: ClientResource commitsResource = new ClientResource(getContext(), commitsRef); commitsRep = commitsResource.get(); To: ClientResource clientResource = new ClientResource(commitsRef); CommitmentsResource commitsResource = clientResource.wrap(CommitmentsResource.class); Representation commitsRep = null; commitsRep = commitsResource.represent(); Changes nothing RB On Tue, Jul 10, 2012 at 4:22 PM, Richard Berger rich...@landisfamily.orgwrote: Yes, I only see this problem when I go through my Restlet client, not when using a browser. In order to make sure the API I am developing is usable by real client developers, I figured I should also build a client. I chose Restlet as the technology for that client - perhaps that wasn't the best possible choice (if no one else does that). Thanks for the response... RB On Tue, Jul 10, 2012 at 2:09 PM, Bjorn Roche [via Restlet Discuss] ml-node+s1400322n7578191...@n2.nabble.com wrote: I can't help you directly, but I can say that I use restlet server (but not client) and I am pretty sure I DON'T have this problem. Is this a bug in the client that it can't access the http status message? That is what I'm gathering from the thread you linked as well. bjorn On Jul 10, 2012, at 1:18 PM, Richard Berger wrote: My question is similar to that raised at: http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 http://restlet-discuss.1400322.n2.nabble.com/Sending-server-side-exceptions-error-codes-back-to-client-td7219795.html#a7229629 , but since that has not been answered and this seems like a really basic issue, I thought I would try posting again. The question is simply this - how to get the details of an error/exception that occurs on the Restlet server back to my Restlet client? I can see how to do this if my client were just a browser (I could construct an HTML page on the server and return it). I thought that it would be pretty simple - set the Status code and Status description. But as the discussion above points out, that doesn't work. I then thought that I could just set the Status code and send back a String Representation of the error message. But that doesn't work either. In particular, if I have: msg = error xyz occurred; this.setStatus(Status.SERVER_ERROR_INTERNAL, msg); StringRepresentation result = new StringRepresentation(msg, MediaType.TEXT_PLAIN); return result; The client side call: commitsRep = commitsResource.get(); Sets commitsRep == null (!). Note: it is only set to null when the status != 200. So, I could set the status to 200 and then return the StringRepresentation and then on the client, check to see if I have a StringRepresentation (which would be an error) or some other type (which would be a success). But surely there has got to be an easier way - what am I missing? (I have created my own StatusService on the server, I have thrown my own exception, but no joy). Thanks in advance for any hep - and thanks to Tim P for collecting all the links in the thread above - but those weren't enough for me to work around the problem. RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982701 - Bjorn Roche http://www.xonami.com Audio Collaboration http://blog.bjornroche.com -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2982833 -- If you reply to this email, your message will be added to the discussion below: http://restlet-discuss.1400322.n2.nabble.com/Handling-exceptions-errors-when-using-Restlet-for-Client-and-Server-tp7578190p7578191.html To unsubscribe from Handling exceptions/errors when using Restlet for Client and Server, click herehttp://restlet-discuss.1400322.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=7578190code=cmljaGFyZEBsYW5kaXNmYW1pbHkub3JnfDc1NzgxOTB8LTYxMDE0ODc2 . NAMLhttp://restlet-discuss.1400322.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://restlet-discuss
RE: Re: ServerResource getRequest() returns null
On my resource: public class UserActsServerResource extends ServerResource implements UserActsResource {... I am able to use: public final Representation represent() { ... User user = UserHelpers.getCurrentUser(this.getRequest(), this.getResponse()); and this.getRequest() returns a useful value. But I have no idea why this is not working for you. I am using the GAE Edition. Perhaps the problem is in some other location of your code/configuration?? RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2972100
RE: Restlet + GAE + OAuth - anyone get this to work?
Took a week, but I did get it to work. For anyone else who runs into this 1. I was following the Ericsson documentation at: https://labs.ericsson.com/apis/oauth2-framework/documentation#Web_Client_Flow that got me as far as getting things to work on my local Google-app-engine dev server. But when deploying to appspot and the real GAE world, it failed. 2. Problem seems to be that the in-memory storage of authTokens doesn't work in google's cloud - perhaps due to how the processing is distributed (??). 3. The fix was to replace the in-memory storage of authTokens with db storage of the tokens (for me that was Objectify and Google's BigTable) 4. This required changing the clientStore code from: ClientStore clientStore = ClientStoreFactory.getInstance(); clientStore.clientStore(123456789, secret1, yourCallbackURI); To: ClientStoreFactory.setClientStoreImpl(MyDBClientStore.class, params); ClientStoreMyDBTokenGenerator clientStore = (ClientStoreMyDBTokenGenerator) ClientStoreFactory.getInstance(); And we need the two new classes referenced above: MyDBClientStore - only difference here is that we extend ClientStoreMyDBTokenGenerator public class MyDBClientStore extends ClientStoreMyDBTokenGenerator and MyDBTokenGenerator - this is where the real work is as you have to save the AuthToken in the database and that AuthToken consists of a token name and an AuthenticatedUser. I had to change generateToken() (store to db) and findToken() (retrieve from db) to get the basics to work. And finally, I had to create classes MyAuthToken and MyAuthenticatedUser to store this information through Objectify. Now it works on the local dev server and on appspot. RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2972101
RE: Restlet + GAE + OAuth - anyone get this to work?
One more note... there is a more complete code sample at: http://fni.googlecode.com/svn/!svn/bc/622/trunk/fniCloud/src/fi/foyt/fni/cloud/ (it's much better than my code - although most of the Restlet relevant classes seem to no longer be available in the owner's current version - they may have given up on Restlet). -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2972102
Restlet + GAE + OAuth - anyone get this to work?
I thought I was close - I had things working on my dev server, but when I upload to appspot, I can no longer access my resources. If anyone has made this work please post back and I will provide additional details. Thanks!! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-GAE-OAuth-anyone-get-this-to-work-tp7578078.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2970748
Simple OpenId question re: multiple verifiers
Using the instructions at http://wiki.restlet.org/docs_2.1/13-restlet/28-restlet/404-restlet.html I am able to use OpenId4Java to provide Google based authentication. In particular, the line: OpenIdVerifier verifier = new OpenIdVerifier(OpenIdVerifier.PROVIDER_GOOGLE); Does much of the magic. There are other OpenIdVerifiers - such as OpenIdVerifier.PROVIDER_YAHOO and I can use that one also. But what if I wanted to give users a choice of several OpenId providers (a common site when I need to login somewhere on the interwebs). Is this possible? (I have this feeling I am missing something obvious). Thanks in advance! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Simple-OpenId-question-re-multiple-verifiers-tp7578042.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2968268
RE: Re: OAuth2: How to resolve Unable to get the template authorize.html._130102
Thanks so much! The /classes directory wasn't visible in Eclipse so I didn't think to try there. So I just copied the files using Windows and that worked perfectly! Thanks again, RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2965075
OAuth2: How to resolve Unable to get the template authorize.html.
I am working through the oAuth2 sample code and have hit a Restlet issue that has stymied me for a while. Following the sample code, I have: HttpOAuthHelper.setAuthPageTemplate(authorize.html, getContext()); However, when AuthPageServerResource.getPage() is called the following code is unable to find authorize.html: Configuration config = new Configuration(); ContextTemplateLoader ctl = new ContextTemplateLoader(getContext(), clap:///); config.setTemplateLoader(ctl); getLogger().fine(loading: + authPage); TemplateRepresentation result = new TemplateRepresentation(authPage, config, MediaType.TEXT_HTML); Specifically, result.template is null. The message that I see is: WARNING: Unable to get the template authorize.html. Error message: Template authorize.html not found. The first problem I fixed was adding the CLAP protocol. My web.xml file had: context-param param-nameorg.restlet.clients/param-name param-valueHTTP HTTPS CLAP /param-value /context-param but that didn't seem to be enough, so in MyOauthServer.createInboundRoot() method, I added: this.getConnectorService().getClientProtocols().add(Protocol.CLAP); // For Freemarker this.getContext().getClientDispatcher().getProtocols().add(Protocol.CLAP); // For Freemarker another attempt This fixed the error message FINE: The protocol used by this request is not declared in the application's connector service. Please update the list of client connectors used by your application and restart it. but did not solve the null template problem. It seems that the getPage() is trying to load a class of type html from the top-level directory of my war file. And that is where I have authorize.html. I also put it in the WEB-INF directory. In addition, since MyOauthServer is setup in my web.xml file as: servlet servlet-nameAuthServer/servlet-name servlet-classorg.restlet.ext.servlet.ServerServlet/servlet-class init-param param-nameorg.restlet.application/param-name param-valuecom.fourspires.oauth.server.MyOauthServer/param-value /init-param /servlet servlet-mapping servlet-nameAuthServer/servlet-name url-pattern/oauth/*/url-pattern /servlet-mapping I also put an authorize.html at war/oauth/authorize.html and war/web-inf/oauth/authorize.html. But alas, none of these work. Where do I have to place the authorize.html file so that it can be loaded by the ContextTemplateLoader? Note: I am running 2.2 GAE Edition. Thanks so much! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/OAuth2-How-to-resolve-Unable-to-get-the-template-authorize-html-tp7575959.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2964942
RE: GAEAuthenticator and Android - anyone make this work?
Some success - at least when accessing a local GAE server. #1. Replaced use of the Android Account Manager with at HttpClient call to http://10.0.2.2:/_ah/login to obtain the authentication information (dev_appserver_login=l:True:145185941422614610318; Path=/;) This was followed by creating a restlet cookie and putting it into the ClientResource (which I had already been doing before): org.restlet.data.Cookie securityCookie = new org.restlet.data.Cookie(0, authTokenName, authToken); commitsClient.getRequest().getCookies().clear(); commitsClient.getRequest().getCookies().add(securityCookie); #2. When looking at the error I had always been getting (Communication Error (1001) - The connector failed to complete communication with the server.), I found deeper in the log System.err(677): java.net.SocketException: Bad address family and I remembered reading the documentation sayig that it may be necessary to do: System.setProperty(java.net.preferIPv6Addresses, false); Then things started working locally. Next up is figuring out how to: a) Use the AccountManager (I need to turn the AuthToken for my account into the right cookie) b) Make this work with my real GAE account. Will post back with either a solution or a white flag of surrender. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2963883
RE: GAEAuthenticator and Android - anyone make this work?
Following Nick's excellent blog article at: http://blog.notdot.net/2010/05/Authenticating-against-App-Engine-from-an-Android-app and with the changes I had made previously, I am now able to use the Android AccountManager and Restlet's GaeAuthenticator to require authentication to access the API uris. Now time to throw it away and replace it with oAuth2 :). RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2964176
Re: [Restlet] Unsupported media type
I had a problem like this and resolved it by adding: Engine.getInstance().getRegisteredConverters().add(0, new JacksonConverter()); to my Android code before I constructed my client resource My code is just a little tweak on the documented version at: http://wiki.restlet.org/docs_2.0/13-restlet/275-restlet/266-restlet.html Good luck! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-Unsupported-media-type-tp7564930p7566612.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2963480
RE: Re: [Restlet] Unsupported media type
Do you get the same 415 error when you go to /connection in your browser? (If so, then the problem is in your ServiceConnection class, rather then in your Android code). Also, in my Android code, I don't wrap the resource, but do the call directly on the ClientResource class, as in: Engine.getInstance().getRegisteredConverters().add(0, new JacksonConverter()); ClientResource commitsClient = new ClientResource(BASE_URL + commitments/); commitsClient.setEntityBuffering(true); Representation rep = commitsClient.post(commitDTO); Good luck! RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2963592
RE: Re: [Restlet] Unsupported media type
From the code that you have posted, I am not able to see the problem Perhaps the type of your connect variable doesn't match the type defined in your Server file. But that is just a guess. Good luck! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-Unsupported-media-type-tp7564930p7567390.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2963649
RE: Is it possible to (easily) have authenticated/non-authenticated versions...
Thanks again for the update - I will continue to work on this, although right now I am in the midst of trying to get oAuth2 to work, so it may be a while before I have a real response. RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Is-it-possible-to-easily-have-authenticated-non-authenticated-versions-tp7557195p7561885.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2961136
Re: Is it possible to (easily) have authenticated/non-authenticated versions...
Thanks - that works perfectly for me. I had been returning the guard to fix an earlier problem - but obviously I fixed it in the wrong way. Thanks again for the detailed solution! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Is-it-possible-to-easily-have-authenticated-non-authenticated-versions-tp7557195p7562976.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2961233
RE: Is it possible to (easily) have authenticated/non-authenticated versions...
Thank you for the response... My simplified test code is now: public final Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach(/v1/, RootServerResource.class); router.attach(/v2/, RootServerResource.class); GaeAuthenticator guard = new GaeAuthenticator(getContext()); router.attach(/v1/, guard, Template.MODE_STARTS_WITH); guard.setNext(router); return guard; } But in the browser, both the paths /v1/ and /v2/ bring up the guard. I am not sure why that happens, but that is what seems to be the result. Thanks for the suggestion (it definitely met the easy part of the qualification)! RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2960926
Is it possible to (easily) have authenticated/non-authenticated versions...
As I am working on implementing authentication, I was wondering if I could configure createInboundRoute to attach the GAEAuthenticator guard only to uris of the form /v1/ (to implement authentication) and allow uris of the form /v0/... to pass through without authentication. My code currently is... public final Restlet createInboundRoot() { ... Router router = new Router(getContext()); router.attach(/v1/path, SomeServerResource.class); . router.attach(/v1/otherpath, SomeOtherServerResource.class); GaeAuthenticator guard = new GaeAuthenticator(getContext()); router.attach(VERSION_PATH, guard); guard.setNext(router); return guard; ... I am assuming that what I want is not easily done (that is fine), but I wanted to make sure before moving on (to trying to do hard things or just not doing it). Thanks in advance! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Is-it-possible-to-easily-have-authenticated-non-authenticated-versions-tp7557195.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2960556
RE: [Restlet Android] Object representation selection (application/x-java-serialized-object vs. application/json)
Engine.getInstance().getRegisteredConverters().add(0, new JacksonConverter()); Worked for me - putting the JacksonConverter first seemed to restore the automagic :) RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2952958
Re: Is there a way to get the response code from the annotated ClientResource?
Thanks so much - that was exactly what I needed! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Is-there-a-way-to-get-the-response-code-from-the-annotated-ClientResource-tp7397618p7398735.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2939468
How to generate/catch a 404 error correctly?
Designing some Junit tests and in one of those tests, a create a Commitment, then delete, then get it to make sure I get a 404. On the server side, the following code executes: public Representation get() { ... setStatus(Status.CLIENT_ERROR_NOT_FOUND, There is no record with id + commitmentIdAttribute); return null; } On the client side, I have: ... Representation representation = commitmentResource.get(); assertNull(representation); assertEquals(404, commitmentClient.getResponse().getStatus().getCode()); But as the .get() method is returning, JUnit generates an Error (not a Failure) of: Not Found (404) - Not Found at org.restlet.resource.ClientResource.doError(ClientResource.java:582) at org.restlet.engine.resource.ClientInvocationHandler.invoke(ClientInvocationHandler.java:269) at $Proxy19.get(Unknown Source) at com.fourspires.api.test.BasicCommitmentTests.testCommitmentLifeCycleJson(BasicCommitmentTests.java:69) (Line 69 is the .get() mentioned above). Anyone have any pointers to how to do this correctly? My google searches have not been fruitful. Thanks! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/How-to-generate-catch-a-404-error-correctly-tp7394494p7394494.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2938513
Re: How to generate/catch a 404 error correctly?
[Solved] public Representation get(MediaType mediaType) throws ResourceException So I need to catch the ResourceException and examine the status (and that works just fine). -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/How-to-generate-catch-a-404-error-correctly-tp7394494p7394543.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2938517
Re: Restlet client support (browser)
Felipe: I have used the Restlet-Javascript edition, although only in a test environment - and my use is probably pretty basic. Thierry has been very responsive in answering questions that I had (mostly my issues were about how representations were being negotiated). Good luck, RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Restlet-client-support-browser-tp7396004p7397086.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2939007
Is there a way to get the response code from the annotated ClientResource?
Given code like the following... ClientResource commentClient = new ClientResource(...); CommentsResource commentsResource = commentClient.wrap(CommentsResource.class); commentsResource.postCommentForm(form); is there a way to get the response code from the commentsResource? Currently I am using: commentClient.getResponse().getStatus().getCode() - but that requires me to always have access to both the wrapped ClientResource and the ClientResource. I tried casting commentsResource back to ClientResourc but that didn't work (and was probably a silly idea - but hey, I get pretty excited when my code compiles :) :) ). Thanks! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Is-there-a-way-to-get-the-response-code-from-the-annotated-ClientResource-tp7397618p7397618.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2939065
Re: Mystery of @Post...
Thank you for the clarification. I made the changes you suggested (totally dropping the postJava() method). I tested this with the Java client (it worked, no surprise). I then tested it using the Apigee console - and it still worked (a little surprise). Then tested it with a Javascript (using Restlet's JavaScript edition) and it still worked (even more surprise). My surprise was that I thought that the console client and the javascript client would need a postComment(String jsonString) method and wouldn't be able to use the postComment(Comment comment). But that expectation was incorrect. I guess both those clients must have Jackon and Jackson extension jars somewhere on the cp. (note: I wasn't expecting your advice to fail, I was expecting my expectations to be broken - although it may require some time in the lotus position to parse that phrase :) ). Thanks also for the getChild() suggestion, I am sure that will also come in handy. The code is now a little cleaner and if the Restlet folks want me to put back the postJava() method to help with testing the connection negotiations, I will be happy to do so. Thanks again, RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Mystery-of-Post-tp7338202p7376533.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2936230
Re: Mystery of @Post...
I downloaded the 3/14 snapshot of 2.2 and I don't see a change. Two points... 1. This may not be a bug - this may only be a conflict with my expectations 2. If this is a bug, is it possible that it is a Jackson problem and not a Restlet problem? Please let me know if I can provide additional information. Thanks! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Mystery-of-Post-tp7338202p7374095.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2935803
Re: Mystery of @Post...
Thank you for the suggestions (I especially liked having the annotations only in the interface). But no difference... After removing the annotations from the implementation, the output was: Mar 14, 2012 8:13:44 PM com.fourspires.api.server.CommentsServerResource postJson INFO: In postJson Mar 14, 2012 8:13:45 PM com.fourspires.api.server.DAO save INFO: saving comment Then after re-ordering the methods in both interface and server implementation, the output was: Mar 14, 2012 8:16:47 PM com.fourspires.api.server.CommentsServerResource postJson INFO: In postJson Mar 14, 2012 8:16:49 PM com.fourspires.api.server.DAO save INFO: saving comment Is it possible that when seeing the following code: (from my test case) Comment comment = new Comment(Hi there from Java, new Date()); Representation representation4 = commentsResource.postJava(comment); the fact that I am using Jackson somehow instructs the system to convert my Java object (comment) into Json and since it is now in Json, the postJson method is called. Yes, it is a bit of a long shot and does introduce the somehow (as if by magic) into the explanation :). Thanks for pondering this! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Mystery-of-Post-tp7338202p7374224.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2935907
Re: Mystery of @Post...
I am now only using the @Post(java) method to be able to use: ClientResource client4 = new ClientResource(someURL); CommentsResource commentsResource = client4.wrap(CommentsResource.class); Representation representation4 = commentsResource.postJava(comment); rather than the more generic: ClientResource client4 = new ClientResource(someURL); Representation representation4 = client4.post(commitment3); my postJava() method doesn't do anything, it exists only to allow the code to compile. And since this is just a test case, it was convenient to be able to make the call with a Java object (although I guess it would be just one line of code to create a Json string). In any case, it is working for me (in this somewhat roundabout way) - so no need to spend any more time in the lotus position. Unless of course, by lotus position, you mean in the driver's seat of a Lotus Elise :) Thanks again for your thoughts! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Mystery-of-Post-tp7338202p7374467.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2936004
Mystery of @Post...
First, the good news. My code is working. But I don't understand WHY it works. Using Restlet and the Annotated Interface approach, described at http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/328-restlet/285-restlet.html. I am also running Restlet GAE (if that matters). I am using Post to add a new Comment to a collection of Comments, so my CommentsResource interface has the following: @Post(json) public Representation postJson(String value); @Post(java) public Representation postJava(Comment comment); @Post(form) public Representation postForm(Form form); And my CommentsServerResource class that implements this interface has three corresponding implementations, each of which is annotated to match the methods in the interface. Now I write a test case in Java. The essence is: ClientResource client4 = new ClientResource(xxx/comments/); CommentsResource commentsResource = client4.wrap(CommentsResource.class); client4.setRequestEntityBuffering(true); // stackoverflow.com/questions/6462142 Comment comment = new Comment(Hi there from Java, new Date()); Representation representation4 = commentsResource.postJava(comment); And the big mystery is that the postJava() method is NOT called, but rather the postJson() method IS called. And somehow my Comment object was magically converted to a Json string. It's kinda cool that it works this way, but I am sure I am missing something (in addition to my lack of IQ points, which must be obvious by now :) :) ). RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Mystery-of-Post-tp7338202p7338202.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2928866
Beginning WADL question...
I am trying to follow the example in 6.3 of the latest version of Restlet in Action to add WADL generation to my Restlet (GAE edition) app. My application extends WadlApplication /public class CommitmentServerApplication extends WadlApplication {/ All my resources extend /WadlServerResource/ (but do not override any WADL methods yet) My application attaches the server resources... @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach(/, RootServerResource.class); router.attach(/commitments/, CommitmentsServerResource.class); router.attach(/commitment/{commitmentId}, CommitmentServerResource.class); return router; } My client code is: ClientResource service = new ClientResource(http://localhost:;); System.out.println(service.options().getText()); Yet when I run this I only get information about the root resource, it does cascade down to any of the attached server resources (output shown below). Any idea what I am missing? (I have looked at the sample code, but the difference is eluding me). Thanks so much! RB Output... ?xml version=1.0 standalone=yes? ?xml-stylesheet type=text/xsl href=wadl2html.xslt? application xmlns=http://wadl.dev.java.net/2009/02; doc title=Root Resource for Commit API/ resources resource doc title=Root Resource for Commit APIRoot Resource Description/doc method name=GET response representation id=root mediaType=text/plain doc title=Commitment API titleThis is the text content for the doc that is the representation of the root - where on earth does this appear/doc /representation /response /method /resource /resources /application -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Beginning-WADL-question-tp7328225p7328225.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2927897
Re: Post problems when using Restlet Javascript Edition...
Quick update - I put in explicit media types for the @Post() annotations on my implementing classes, e.g.: @Post(json) public Representation acceptJson(String jsonString) { And that has fixed the problem both when going through tcpmon and without tcpmon involved. I wasn't able to figure out if tcpmon changes the headers. All is good now - thanks again for your help!! RB On Thu, Feb 23, 2012 at 1:00 AM, Thierry Templier [via Restlet Discuss] ml-node+s1400322n7311238...@n2.nabble.com wrote: Hello Richard, I answer in the message content. Thierry: Thanks so much for your help. The short version is that the latest Restlet JS code (plus one change in my code) fixes my problem with post(). There is one strangeness that I will describe below, but it isn't a big problem for me at this point, but I will describe it below in case you think it matters. Again, thank you!! And, please let me know if there is any testing that I can do for you. You're welcome! Thanks very much for your proposal! Details... I installed the new scripts. Only part that confused me was that I initially took restlet-browser.js from: * modules\org.restlet.js\src\dist\restlet-browser.js But that was the wrong file, I had to use: * tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js if that is what was intended, all is fine. The restlet-browser.js in the modules/org.restlet.js/src/dist folder is the assembly file that selects which files to include in the Restlet JS edition for browser. After having run Ant with build.browser task, the js file for the edition can be found in the modules/org.restlet.js/target/browser directory. Once I put in the right restlet-browser.js, I ran my test and got a 415 error. So I ran the test through tcpmon - and when going through tcpmon - it worked! But the mystery was that when going through tcpmon, the server side method acceptJava() was being called, not acceptJson(). I changed the ordering as per your email, but that still didn't fix my problem (but I did discover that the re-ordering is indeed necessary, but that is getting ahead of the story). Do you know if tcpmon updates the request by adding or removing some HTTP headers? At this point I had: public interface CommitmentsResource { @Post(json) public String acceptJson(String value); // For JSON @Post(form) public Representation accept(Form form); // For HTML form @Post() public Representation acceptJava(Commitment commitment); // For Java post } And... public class CommitmentsServerResource extends WadlServerResource implements CommitmentsResource { @Post public Representation acceptJava(Commitment commitment) { } @Override public String acceptJson(String value) { } @Override // This is the code that actually handles posts that come from forms and http posts public Representation accept(Form form) { } I had the thought that acceptJava was the one being called since it was the only one with the @Post annotation. I changed the @Override annotations to @Post. And then the Javascript post was handled by the acceptJson method (which I then fleshed out and changed to return a Represenation). Everything would be perfect at this point, except for the strangeness. Now when I run the test through tcpmon, I get a 415 error there. The call does make it to the server, since I get an error in the console along the lines of: Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation getObject WARNING: Unable to parse the object with Jackson. org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.restlet.data.Form out of START_OBJECT token at [Source: org.restlet.engine.io.UnclosableInputStream@41c7d56b; line: 1, column: 1] at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163) . And then to try and break my non-tcpmon client, I changed the ordering of the @Post methods, and that did indeed break things as you had predicted. I discussed this issue with Restlet team and the problem comes from the Jackson extension. In fact, there is a problem when computing scores to route to the right method. They're working on this issue... Thanks again!! RB Thierry -- If you reply to this email, your message will be added to the discussion below: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7311238.html To unsubscribe from Post problems when using Restlet Javascript Edition..., click herehttp://restlet-discuss.1400322.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=7270413code=cmljaGFyZEBsYW5kaXNmYW1pbHkub3JnfDcyNzA0MTN8LTYxMDE0ODc2 .
Re: Post problems when using Restlet Javascript Edition...
Thierry: Thanks so much for your help. The short version is that the latest Restlet JS code (plus one change in my code) fixes my problem with post(). There is one strangeness that I will describe below, but it isn't a big problem for me at this point, but I will describe it below in case you think it matters. Again, thank you!! And, please let me know if there is any testing that I can do for you. Details... I installed the new scripts. Only part that confused me was that I initially took restlet-browser.js from: * modules\org.restlet.js\src\dist\restlet-browser.js But that was the wrong file, I had to use: * tests\org.restlet.js.tests\src\browser\static\restlet\restlet-browser.js if that is what was intended, all is fine. Once I put in the right restlet-browser.js, I ran my test and got a 415 error. So I ran the test through tcpmon - and when going through tcpmon - it worked! But the mystery was that when going through tcpmon, the server side method acceptJava() was being called, not acceptJson(). I changed the ordering as per your email, but that still didn't fix my problem (but I did discover that the re-ordering is indeed necessary, but that is getting ahead of the story). At this point I had: public interface CommitmentsResource { @Post(json) public String acceptJson(String value); // For JSON @Post(form) public Representation accept(Form form); // For HTML form @Post() public Representation acceptJava(Commitment commitment); // For Java post } And... public class CommitmentsServerResource extends WadlServerResource implements CommitmentsResource { @Post public Representation acceptJava(Commitment commitment) { } @Override public String acceptJson(String value) { } @Override // This is the code that actually handles posts that come from forms and http posts public Representation accept(Form form) { } I had the thought that acceptJava was the one being called since it was the only one with the @Post annotation. I changed the @Override annotations to @Post. And then the Javascript post was handled by the acceptJson method (which I then fleshed out and changed to return a Represenation). Everything would be perfect at this point, except for the strangeness. Now when I run the test through tcpmon, I get a 415 error there. The call does make it to the server, since I get an error in the console along the lines of: Feb 22, 2012 3:07:33 PM org.restlet.ext.jackson.JacksonRepresentation getObject WARNING: Unable to parse the object with Jackson. org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of org.restlet.data.Form out of START_OBJECT token at [Source: org.restlet.engine.io.UnclosableInputStream@41c7d56b; line: 1, column: 1] at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163) . And then to try and break my non-tcpmon client, I changed the ordering of the @Post methods, and that did indeed break things as you had predicted. Thanks again!! RB On Wed, Feb 22, 2012 at 1:07 AM, Thierry Templier [via Restlet Discuss] ml-node+s1400322n730770...@n2.nabble.com wrote: Hello Richard, Regarding the post HTTP method and the annotated methods server resources, I updated the header management in the JavaScript edition. The routing to such methods is based on the Content-Type header. I committed all my updates in GitHub, so feel free to make some tests and give me a feedback. Be aware that there is a bug in Restlet 2.1 regarding the routing to the right methods. If a media isn't specified for the first method, this method will be used and it's not correct... @Put (...) @Put(json) (...) It works with the following: @Put(json) (...) @Put (...) This problem is about to be fixed in the Java version of Restlet. Thierry Thanks again for your help. I downloaded tcpmon and made the suggested changes to my Java client. I then did a post through Java and below are the Request and the Response. Request POST /commitments/ HTTP/1.1 Date: Wed, 15 Feb 2012 22:19:58 GMT Content-Length: 109 Content-Type: application/json; charset=UTF-8 Accept: */* Host: localhost:8880 User-Agent: Restlet-Framework/2.1rc2 Cache-Control: no-cache Pragma: no-cache Connection: keep-alive {id:0,title:Added through post - Java client,description:This is a description of post Java client} Response... HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Date: Wed, 15 Feb 2012 22:19:59 GMT Accept-Ranges: bytes Server: Restlet-Framework/2.1rc2 Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept Content-Length: 1 4 Then I moved to the Javascript side. I didn't install Firebug, but instead I just changed the ClientResource creation from: var clientResource = new ClientResource(/commitments/); / To: var clientResource = new ClientResource(http://localhost:8880/commitments/;); where TCPmon was running on 8880 and forwarding to
Re: Post problems when using Restlet Javascript Edition...
First - thank you for your message and the work that you are doing. I downloaded the latest .js files and the previously reported error is indeed fixed. But my post() is still not being received on the server side when called from Javascript. From Javascript, I am able to succesfully call get and put. From a Java client, I can successfully call post. And a standard HTML form post works too. Details on the error... (from Chrome's Javascript console) POST http://localhost:/commitments/ 415 (Unsupported Media Type) Class.lowLevelSendRequestrestlet-browser.js:3681 Class.sendRequestrestlet-browser.js:3630 Class.commitrestlet-browser.js:3776 Class.handlerestlet-browser.js:3812 Class.handlerestlet-browser.js:3865 Class.handleNextrestlet-browser.js:4311 Class.handleRequestrestlet-browser.js:4301 Class.handlerestlet-browser.js:4293 Class.postrestlet-browser.js:4232 (anonymous function)oldTest.html:64 Test.runqunit.js:102 Test.queue.badqunit.js:232 processqunit.js:865 QUnit.start.config.blocking Details of my client code asyncTest(Post with resource Commitment (json), function() { var clientResource = new ClientResource(/commitments/); var commitment = { title: From automated test, description: This is from our automated test } var jsonRepresentation = new JsonRepresentation(commitment); alert(jsonRepresentation.getText()); // Result is: {title:From automated test,description:This is from our automated test} clientResource.post(jsonRepresentation, function(representation) { console.log(representation.getText() = +representation.getText()); // Note: commenting or not commenting out all the lines below doesn't make a difference //var jsonRepresentation = new JsonRepresentation(representation); //var obj = jsonRepresentation.getObject(); //ok(obj.id, 1); //ok(obj.title, From automated test); //ok(obj.description, This is from our automated test); start(); }, MediaType.APPLICATION_JSON); }); You had mentioned that you are still working on the header management processing - would that be a likely reason for the 415 error or am I not doing something required for Post in particular. Also, would you still like me to open an issue in GitHub for this problem or the previous one? Thanks so much! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7286087.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2922490
Re: Post problems when using Restlet Javascript Edition...
Thanks again for your help. I downloaded tcpmon and made the suggested changes to my Java client. I then did a post through Java and below are the Request and the Response. Request POST /commitments/ HTTP/1.1 Date: Wed, 15 Feb 2012 22:19:58 GMT Content-Length: 109 Content-Type: application/json; charset=UTF-8 Accept: */* Host: localhost:8880 User-Agent: Restlet-Framework/2.1rc2 Cache-Control: no-cache Pragma: no-cache Connection: keep-alive {id:0,title:Added through post - Java client,description:This is a description of post Java client} Response... HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Date: Wed, 15 Feb 2012 22:19:59 GMT Accept-Ranges: bytes Server: Restlet-Framework/2.1rc2 Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept Content-Length: 1 4 Then I moved to the Javascript side. I didn't install Firebug, but instead I just changed the ClientResource creation from: var clientResource = new ClientResource(/commitments/); / To: var clientResource = new ClientResource( http://localhost:8880/commitments/;); where TCPmon was running on 8880 and forwarding to , which is where my server was listening. Below are the Request and Response - and they are definitely different than the Java version... Request... OPTIONS /commitments/ HTTP/1.1 Host: localhost:8880 Connection: keep-alive Access-Control-Request-Method: POST Origin: http://localhost: User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11 Access-Control-Request-Headers: Origin, Content-Type, accept Accept: */* Referer: http://localhost:/oldTest.html Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Response... HTTP/1.1 200 OK Content-Type: application/vnd.sun.wadl+xml; charset=UTF-8 Date: Wed, 15 Feb 2012 22:22:22 GMT Accept-Ranges: bytes Allow: POST, GET Server: Restlet-Framework/2.1rc2 Transfer-Encoding: chunked 5D2 ?xml version=1.0 standalone=yes? ?xml-stylesheet type=text/xsl href=wadl2html.xslt? application xmlns=http://wadl.dev.java.net/2009/02; doc title=Commitments resource/ representation id=commitment mediaType=text/plain doc title=CommitmentSimple string containing the commitment ID/doc /representation resources resource path=commitments/ doc title=Commitments resourceThe resource that contains the list of commitments in the system/doc method name=GET response representation href=#commitment/ representation href=#commitment/ representation href=#commitment/ representation href=#commitment//response /method method name=POST request representation href=#commitment/ representation href=#commitment/ representation href=#commitment/ representation href=#commitment//request response representation href=#commitment/ representation href=#commitment/ representation href=#commitment/ representation href=#commitment/ representation href=#commitment/ representation href=#commitment//response /method /resource /resources /application One small typo on the http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/article, in the ClientResource section the line: Context context = clientResource.getContext(); should be context = clientResource.getContext(); (but this is minor - the ease of getting the trace using Restlet tracing was awesome). Thanks again for all your assistance! (And my apologies in advance if the problem turns out to be some silly mistake in my code - always a real possibility). RB On Wed, Feb 15, 2012 at 6:15 AM, Thierry Templier [via Restlet Discuss] ml-node+s1400322n7287572...@n2.nabble.com wrote: Hello Richard, It could be either an HTTP header not correctly in the JS part or a problem on methods signatures within ServerResource class... Can you give me the request content of both calls from Java and JS? - For Java, simply active tracing mode on the ClientResource client ( http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/ ): http://templth.wordpress.com/2011/05/17/activating-tracing-mode-in-restlet/String url = (...); Context context = new Context(); ClientResource clientResource = new ClientResource(context, url); Context context = clientResource.getContext(); context.getParameters().add(tracing, true); - For JS, you can have access to the content using for example Firebug... Thanks! Thierry First - thank you for your message and the work that you are doing. I downloaded the latest .js files and the previously reported error is indeed fixed. But my post() is still not being received on the server side when called from Javascript. From
Would I be correct in assuming that the Javascript Edition for Restlet is inactive?
Haven't been able to find much documentation - all the posts here are quite old - and just wondering if I should use something else for playing around with a javascript REST client (e.g. JQuery). On the other hand, if folks are hard at work on the Javascript edition - my apologies! Thanks in advance, RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Would-I-be-correct-in-assuming-that-the-Javascript-Edition-for-Restlet-is-inactive-tp7275436p7275436.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2920996
Post problems when using Restlet Javascript Edition...
Working on a small project to learn REST/Restlet and ran into a problem where I can successfully post from a Java client to my server or from an HTML form to my server, but when I try to post from Javascript it fails. I am following the sample code that is now on github (https://github.com/restlet/restlet-framework-js/tree/master/tests/org.restlet.js.tests/src/browser/static/html). On the client side... For Java (working), I have: System.out.println(Adding a commitment); ClientResource client3 = new ClientResource(http://localhost:/commitments/;); client3.setRequestEntityBuffering(true); // Per http://stackoverflow.com/questions/6462142/length-required-411-length-required-in-a-restlet-client Commitment commitment3 = new Commitment(); commitment3.setTitle(Added through post - Java client); commitment3.setDescription(This is a description of post Java client); Representation representation3 = client3.post(commitment3); For Javascript (not working), I have: asyncTest(Post with resource Commitment (json), function() { var clientResource = new ClientResource(/commitments/); var commitment = { title: From automated test, description: This is from our automated test } var jsonRepresentation = new JsonRepresentation(commitment); alert(jsonRepresentation.getText()); // Result is: {title:From automated test,description:This is from our automated test} clientResource.post(jsonRepresentation, function(representation) { console.log(representation.getText() = +representation.getText()); // Note: commenting or not commenting out all the lines below doesn't make a difference //var jsonRepresentation = new JsonRepresentation(representation); //var obj = jsonRepresentation.getObject(); //ok(obj.id, 1); //ok(obj.title, From automated test); //ok(obj.description, This is from our automated test); start(); }, MediaType.APPLICATION_JSON); }); The error, as seen in the Javascript console, is: ReferenceError at restlet-browser.js: 3175 arguments: Array[1] 0: EncodingWriter length: 1 __proto__: Array[0] get message: function getter() { [native code] } get stack: function getter() { [native code] } set message: function setter() { [native code] } set stack: function setter() { [native code] } type: not_defined __proto__: Error On the server side, I have methods to handle the different clients: @Post() public String add(Commitment commitment); // For Java post @Post(json) public String acceptJson(String value); // For JSON @Post(form) public Representation accept(Form form); // For HTML form But the Javascript client does not appear to be even making the call to the server. Has anyone used the Restlet Edition for Javascript to do a post? Thanks so much! RB -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Post-problems-when-using-Restlet-Javascript-Edition-tp7270413p7270413.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2920183
RE: tutorial not working
Tutorial works fine for me in dev mode, but fails when I upload to appspot. I only have a single servlet in my web.xml web-app context-param param-nameorg.restlet.clients/param-name param-valueCLAP FILE/param-value /context-param servlet servlet-nameadapter/servlet-name !-- servlet-classorg.restlet.ext.gwt.GwtShellServletWrapper/servlet-class -- servlet-classorg.restlet.ext.servlet.ServerServlet/servlet-class init-param param-nameorg.restlet.application/param-name param-valueorg.restlet.example.gae.serialization.server.TestServerApplication/param-value /init-param /servlet servlet-mapping servlet-nameadapter/servlet-name url-pattern/*/url-pattern /servlet-mapping /web-app I don't see any errors in the appspot log, just the message: Oops! This link appears to be broken. in the browser. I am using the gwt version of the org.restlet.jar (2.1 M1) on the client and the gae (2.1 M1) version of org.restlet.jar (and the other 6 jars required by the tutorial). Any ideas as to how I can track down the problem? The only change I made to the tutorial was to change to newer jars and the modification you can see above in the web.xml. You can try it for yourself at: http://rbresttest2.appspot.com/ Thanks so much - I am trying to see if I can learn enough about restlet to recommend it for an upcoming product. RB -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2691931