RE: Re: Re: Getting NullPointerException when trying to get serialized object

2012-10-03 Thread Diego Felipe Muñoz Sáez
Thank you very much for your answer.

I wanted to know if I could share it in Stackoverflow.com too, because I asked 
the same question there.

Regards,
Diego

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3011973


Re: Re: Getting NullPointerException when trying to get serialized object

2012-10-03 Thread Thierry Boileau
Hello Diego,

I think it's fine if you share my answer of course!

Best regards,
Thierry Boileau


Thank you very much, Thierry.
>
> I asked the same in Stackoverflow.com, if you don't have any problem I
> will share your answer there too.
>
> > Hello Diego,
> >
> > the common classes between the server and client parts (such as the
> classes
> > for the bean objects that are serialized/deserialized) must be located in
> > the same packages. The reason is that the serialization/deserialization
> > process leverages conventions, in particular convention regarding the
> full
> > path of the bean classes are referenced inside the JSON representation.
> > All other classes such as ClientResource, annotated interfaces could be
> > located in distinct packages between client/server projects.
> >
> > Best regards,
> > Thierry Boileau
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3011928

Re: Re: MyStatusService not invoked after MyRepresentation throws exception

2012-10-03 Thread Thierry Boileau
Hello Jim,

thanks for the sample code, I understand the issue and have entered a new
one in github : https://github.com/restlet/restlet-framework-java/issues/670
.

Best regards,
Thierry Boileau


Thierry -
>
> I very much appreciate your reply, but TestApplication does not take into
> account a custom Representation that may fail.  I've changed the
> TestApplication class to TestApplicationJim to better explain what I am
> trying to do.  The RepresentationFails class demonstrates that the methods
> in MyStatusService are never invoked.
>
> As succinctly as I can state it: If a write operation in a custom
> representation fails, no method in the customized StatusService is invoked.
>
> FYI - The Restlet code is excellent, and I have improved my coding style
> after learning from yours.
>
> Code is below, and also attached
>
>
> package test;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.io.Reader;
> import java.io.Writer;
> import java.nio.channels.ReadableByteChannel;
> import java.nio.channels.WritableByteChannel;
>
> import org.restlet.Application;
> import org.restlet.Component;
> import org.restlet.Request;
> import org.restlet.Response;
> import org.restlet.data.MediaType;
> import org.restlet.data.Protocol;
> import org.restlet.data.Status;
> import org.restlet.representation.OutputRepresentation;
> import org.restlet.representation.Representation;
> import org.restlet.resource.ClientResource;
> import org.restlet.resource.ResourceException;
> import org.restlet.routing.Router;
>
> public class TestApplicationJim extends Application {
>
> /**
>  * @param args
>  * @throws Exception
>  */
> public static void main(String[] args) throws Exception {
> Component c = new Component();
> c.getServers().add(Protocol.HTTP, 8182);
> c.getDefaultHost().attach(new TestApplicationJim());
> c.start();
> System.out.println("TestApplicationJim started");
>
> ClientResource cr = new ClientResource("
> http://localhost:8182/test1";);
> cr.setRetryOnError(false);
> try {
> cr.get();
> } catch (Exception e) {
> cr.getResponseEntity().write(System.out);
> }
>
> cr = new ClientResource("http://localhost:8182/test2";);
> cr.setRetryOnError(false);
> try {
> cr.get();
> } catch (Exception e) {
> cr.getResponseEntity().write(System.out);
> }
> c.stop();
> }
>
> public void handle(Request request, Response response) {
> System.out.println("TestApplicationJim handle");
> class RepresentationFails extends OutputRepresentation {
>
> public RepresentationFails() {
> super(MediaType.APPLICATION_ZIP, -1);
> }
>
> @Override
> public ReadableByteChannel getChannel() throws IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> @Override
> public Reader getReader() throws IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> @Override
> public InputStream getStream() throws IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> @Override
> public void write(Writer writer) throws IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> @Override
> public void write(WritableByteChannel writableChannel) throws
> IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> @Override
> public void write(OutputStream outputStream) throws
> IOException {
> throw new
> ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
> }
>
> }
> response.setEntity(new RepresentationFails());
> }
>
> public TestApplicationJim() {
> super();
> setStatusService(new MyStatusService());
> }
>
> public org.restlet.Restlet createInboundRoot() {
> Router router = new Router(getContext());
> router.attach("/test1", TestExceptionServerResource.class);
> router.attach("/test2", TestResourceExceptionServerResource.class);
> return router;
> };
>
> }

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3011830

Re: Getting NullPointerException when trying to get serialized object

2012-10-03 Thread Thierry Boileau
Hello Diego,

the common classes between the server and client parts (such as the classes
for the bean objects that are serialized/deserialized) must be located in
the same packages. The reason is that the serialization/deserialization
process leverages conventions, in particular convention regarding the full
path of the bean classes are referenced inside the JSON representation.
All other classes such as ClientResource, annotated interfaces could be
located in distinct packages between client/server projects.

Best regards,
Thierry Boileau


After trying many many many many things I made it work. I asked in the
> Restlet Mailing list too, and I will comment this same thing there.
>
> In the try/catch block I put this:
>
>
> Log.w("json
> get(MediaType)",cr.get(MediaType.APPLICATION_JSON).toString());
> ObjectRepresentation r = new
> ObjectRepresentation(cr.get());
> Log.w("get user",r.getObject().toString());
>
> And all I got was a ClassNotFoundException because my Android device said
> it couldn't find the "com.server.common.MyUser" class, I renamed both
> server and clients packages to the same name and it worked.
>
> Is it necessary that the packages are the same too?
>
> --
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3011494
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3011814