Complexity in understanding

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Complexity in understanding

Shailevit
So I am working on a more complex format from the tutorials but running into some odd issues and/or confusions that I don't quite understand.
To simplify things, I attached my code. There are 3 java files (Main, Tracer and RootRoute).
I am trying to get a better understanding on Router, Directory, Application, Root, Restlet and context.
The code compiles fine, but I get an error:

The filter org.restlet.engine.application.RangeFilter@5c4ef185 was executed without a next Restlet attached to it.
2014-08-06 13:37:42 0:0:0:0:0:0:0:1 - - 8183 GET / - 500 486 0 10 http://localhost:8183        Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36 -

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

MainServer.java (2K) Download Attachment
RootRoute.java (718 bytes) Download Attachment
Tracer.java (677 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Complexity in understanding

Tim Peierls
From a brief look at your code, it looks like you're mixing up Restlets with ServerResources. Restlets are created and added to the routing structure in createInboundRoot, and typically have a lifetime that spans that of the application, while a new ServerResource instance is created for every request that is routed to its class. (You probably don't want to create a new Directory each time a RootRoute is created to handle a request, but that's what would happen at the moment.)

You're also creating a Directory instance and not using it in createInboundRoot. A Directory is a Restlet that you can attach to; just creating it doesn't do anything.

I suggest working from a tutorial example that does work for you, and modifying it incrementally until something happens that you don't understand. Then you can ask why that change broke things.

--tim


On Wed, Aug 6, 2014 at 1:40 PM, Shai Levit <[hidden email]> wrote:
So I am working on a more complex format from the tutorials but running into some odd issues and/or confusions that I don't quite understand.
To simplify things, I attached my code. There are 3 java files (Main, Tracer and RootRoute).
I am trying to get a better understanding on Router, Directory, Application, Root, Restlet and context.
The code compiles fine, but I get an error:

The filter org.restlet.engine.application.RangeFilter@5c4ef185 was executed without a next Restlet attached to it.
2014-08-06      13:37:42        0:0:0:0:0:0:0:1 -       -       8183    GET     /       -       500     486     0       10      http://localhost:8183   Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36        -

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

Reply | Threaded
Open this post in threaded view
|

Re: Complexity in understanding

Shailevit
Hi Tim,
Thank for the insight and so I am working on adding more complexity. So here is a simple code that should work, but for some reason I get this error:
The filter org.restlet.engine.application.RangeFilter@24f2f2 was executed without a next Restlet attached to it.
2014-08-07 15:37:47 0:0:0:0:0:0:0:1 - - 8400 GET / - 500 486 0

The full code is as follows:

package org.simpler.test;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.representation.StringRepresentation;
import org.restlet.routing.Router;

public class PageTest extends Application {

        public static void main(String[] args) throws Exception {
               
                Component component = new Component();
                component.getServers().add(Protocol.HTTP, 8400);
               
                Application application = new Application();
               
                component.getDefaultHost().attach(application);
                component.start();

        }
       
        @Override
        public Restlet createInboundRoot(){
               
                Router router = new Router(this.getContext());
       
                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST application</title></head>");
                                stringBuilder.append("

Click on link

");
                                //stringBuilder.append("<a href=\"/file\">");
                                stringBuilder.append("</html>");
                               
                                response.setEntity(new StringRepresentation(stringBuilder.toString(), MediaType.TEXT_HTML));
                        }
                };
               
                router.attach("", mainpage);
                return router;
        }

}
Reply | Threaded
Open this post in threaded view
|

Re: Complexity in understanding

Tim Peierls
Looks like you're attaching a vanilla Application instead of an instance of PageTest.


On Thu, Aug 7, 2014 at 3:39 PM, Shai Levit <[hidden email]> wrote:
Hi Tim,
Thank for the insight and so I am working on adding more complexity. So here
is a simple code that should work, but for some reason I get this error:
The filter org.restlet.engine.application.RangeFilter@24f2f2 was executed
without a next Restlet attached to it.
2014-08-07      15:37:47        0:0:0:0:0:0:0:1 -       -       8400    GET     /       -       500     486     0

The full code is as follows:

package org.simpler.test;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.representation.StringRepresentation;
import org.restlet.routing.Router;

public class PageTest extends Application {

        public static void main(String[] args) throws Exception {

                Component component = new Component();
                component.getServers().add(Protocol.HTTP, 8400);

                Application application = new Application();

                component.getDefaultHost().attach(application);
                component.start();

        }

        @Override
        public Restlet createInboundRoot(){

                Router router = new Router(this.getContext());

                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST
application</title></head>");
                                stringBuilder.append("
Click on link
");
                                //stringBuilder.append(" ");
                                stringBuilder.append(" <\"/file\"> </html>");

                                response.setEntity(new StringRepresentation(stringBuilder.toString(),
MediaType.TEXT_HTML));
                        }
                };

                router.attach("", mainpage);
                return router;
        }

}



--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Complexity-in-understanding-tp7579254p7579256.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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

Reply | Threaded
Open this post in threaded view
|

Re: Complexity in understanding

Shailevit
Guess I am a bit confused in how Application application = new Application and InboundRoot and Restlet all relate. Should I have nested the Restlet inside the Application like this:?

Application application = new Application(this.getContext()){

@Override
 public Restlet createInboundRoot(){

                Router router = new Router(this.getContext());

                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST
application</title></head>");
                                stringBuilder.append("
Click on link
");
                                //stringBuilder.append(" ");
                                stringBuilder.append(" <\"/file\"> </html>");

                                response.setEntity(new StringRepresentation(stringBuilder.toString(),
MediaType.TEXT_HTML));
                        }
                };

                router.attach("", mainpage);
                return router;
        }
component.getDefaultHost().attach(application);
                component.start();

        }

Or am I missing some major / subtle point here ?

Thanks for the help in advance


On Thu, Aug 7, 2014 at 11:05 PM, Tim Peierls [via Restlet Discuss] <[hidden email]> wrote:
Looks like you're attaching a vanilla Application instead of an instance of PageTest.


On Thu, Aug 7, 2014 at 3:39 PM, Shai Levit <[hidden email]> wrote:
Hi Tim,
Thank for the insight and so I am working on adding more complexity. So here
is a simple code that should work, but for some reason I get this error:
The filter org.restlet.engine.application.RangeFilter@24f2f2 was executed
without a next Restlet attached to it.
2014-08-07      15:37:47        0:0:0:0:0:0:0:1 -       -       8400    GET     /       -       500     486     0

The full code is as follows:

package org.simpler.test;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.representation.StringRepresentation;
import org.restlet.routing.Router;

public class PageTest extends Application {

        public static void main(String[] args) throws Exception {

                Component component = new Component();
                component.getServers().add(Protocol.HTTP, 8400);

                Application application = new Application();

                component.getDefaultHost().attach(application);
                component.start();

        }

        @Override
        public Restlet createInboundRoot(){

                Router router = new Router(this.getContext());

                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST
application</title></head>");
                                stringBuilder.append("
Click on link
");
                                //stringBuilder.append(" ");
                                stringBuilder.append(" <\"/file\"> </html>");

                                response.setEntity(new StringRepresentation(stringBuilder.toString(),
MediaType.TEXT_HTML));
                        }
                };

                router.attach("", mainpage);
                return router;
        }

}



--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Complexity-in-understanding-tp7579254p7579256.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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




If you reply to this email, your message will be added to the discussion below:
http://restlet-discuss.1400322.n2.nabble.com/Complexity-in-understanding-tp7579254p7579257.html
To unsubscribe from Complexity in understanding, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Complexity in understanding

Tim Peierls
Restlet arranges to call the createInboundRoot method of any Application when that application is started. You're defining a createInboundRoot method for an Application subtype but you're not passing an instance of that subtype.

As I wrote before, I recommend starting with a working tutorial example that you do understand, and incrementally change it until it doesn't do what you expect. You can get a lot done by just adapting existing working code.

--tim


On Fri, Aug 8, 2014 at 9:20 AM, Shai Levit <[hidden email]> wrote:
Guess I am a bit confused in how Application application = new Application and InboundRoot and Restlet all relate. Should I have nested the Restlet inside the Application like this:?

Application application = new Application(this.getContext()){

@Override
 public Restlet createInboundRoot(){

                Router router = new Router(this.getContext());

                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST
application</title></head>");
                                stringBuilder.append("
Click on link
");
                                //stringBuilder.append(" ");
                                stringBuilder.append(" <\"/file\"> </html>");

                                response.setEntity(new StringRepresentation(stringBuilder.toString(),
MediaType.TEXT_HTML));
                        }
                };

                router.attach("", mainpage);
                return router;
        }
component.getDefaultHost().attach(application);
                component.start();

        }

Or am I missing some major / subtle point here ?

Thanks for the help in advance


On Thu, Aug 7, 2014 at 11:05 PM, Tim Peierls [via Restlet Discuss] <[hidden email]> wrote:
Looks like you're attaching a vanilla Application instead of an instance of PageTest.


On Thu, Aug 7, 2014 at 3:39 PM, Shai Levit <[hidden email]> wrote:
Hi Tim,
Thank for the insight and so I am working on adding more complexity. So here
is a simple code that should work, but for some reason I get this error:
The filter org.restlet.engine.application.RangeFilter@24f2f2 was executed
without a next Restlet attached to it.
2014-08-07      15:37:47        0:0:0:0:0:0:0:1 -       -       8400    GET     /       -       500     486     0

The full code is as follows:

package org.simpler.test;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.representation.StringRepresentation;
import org.restlet.routing.Router;

public class PageTest extends Application {

        public static void main(String[] args) throws Exception {

                Component component = new Component();
                component.getServers().add(Protocol.HTTP, 8400);

                Application application = new Application();

                component.getDefaultHost().attach(application);
                component.start();

        }

        @Override
        public Restlet createInboundRoot(){

                Router router = new Router(this.getContext());

                Restlet mainpage = new Restlet(){
                        @Override
                        public void handle(Request request, Response response){
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.append("<html>");
                                stringBuilder.append("<head><title>Default Page of my TEST
application</title></head>");
                                stringBuilder.append("
Click on link
");
                                //stringBuilder.append(" ");
                                stringBuilder.append(" <\"/file\"> </html>");

                                response.setEntity(new StringRepresentation(stringBuilder.toString(),
MediaType.TEXT_HTML));
                        }
                };

                router.attach("", mainpage);
                return router;
        }

}



--
View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Complexity-in-understanding-tp7579254p7579256.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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




If you reply to this email, your message will be added to the discussion below:
http://restlet-discuss.1400322.n2.nabble.com/Complexity-in-understanding-tp7579254p7579257.html
To unsubscribe from Complexity in understanding, click here.
NAML



View this message in context: Re: Complexity in understanding

Sent from the Restlet Discuss mailing list archive at Nabble.com.