I have set up an App Engine Restlet Project (v 2.2.2) which returns a html or 
json response (web or android client) and different data from a db for 
different users. I have implemented HTTP basic authentication. It all works 
quite well.

my basic setup atm (I have simplified it ofc):

MyApplication.java
public class MyApplication extends Application {

    private ChallengeAuthenticator authenticatior;
    private ChallengeAuthenticator createAuthenticator() {...}
    public boolean authenticate(Request request, Response response) {...}

    @Override
    public Restlet createInboundRoot() {
        this.authenticatior = createAuthenticator();        
        Router router = new Router(getContext());
        router.attachDefault(MyRestlet.class);
        authenticatior.setNext(router);
        return authenticatior;
    }

MyRestlet.java
public class MyRestlet extends ServerResource {

        @Get("json")
        public Representation getJSON() {
            MyApplication app = (MyApplication) getApplication();
                if (!app.authenticate(getRequest(), getResponse())) {
                    // Not authenticated
                    return null;
                }
                else {
                    return data;     
                }

        @Get("html")
        public String getHTML() {...}
}

web.xml
<?xml ...>
<display-name>MyName</display-name>  

<context-param>
<param-name>org.restlet.application</param-name>
<param-value>x.MyApplication</param-value>
</context-param>

<servlet>
<servlet-name>MyRestlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyRestlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Now I want to add encryption and created keys/certificates. My guide was this 
tutorial (http://restlet.com/learn/guide/2.2/core/security/https). I wanted to 
try to add a simple component first, stay with HTTP and change the port to 8183 
as done in this tutorial 
(http://restlet.com/learn/tutorial/2.2/#/docs_2.0/13-restlet/21-restlet/318-restlet/319-restlet.html).
 I have now played around quite a bit and cannot seem to get my component to 
work. So my question is: Where would I put this main-Method (the following code 
is taken from the tutorial)? Into which class should I insert it or should I 
create a seperate server-class and what exactly would the required changes to 
the web.xml look like (I did not find much concerning this and I suspect that 
this is the central problem)? Any help is appreciated!

public static void main(String[] args) throws Exception {
    // Create a new Restlet component and add a HTTP server connector to it
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8182);

    // Then attach it to the local host
    component.getDefaultHost().attach("/trace", Part05.class);

    // Now, let's start the component!
    // Note that the HTTP server connector is also automatically started.
    component.start();
}

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

Reply via email to