I've diged furhter more and find the following example:

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class MyResource extends Resource {
    public MyResource(Context context, Request request, Response response) {
        super(context, request, response);
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
    }

    @Override
    public Representation getRepresentation(Variant variant) {
        Representation result = null;
        if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {
            String msg = "ResourceRef:  " + getRequest().getResourceRef()
                    + "\n" + "BaseRef:      "
                    + getRequest().getResourceRef().getBaseRef() + "\n"
                    + "RemainingPart:"
                    + getRequest().getResourceRef().getRemainingPart() + "\n"
                    + "HostRef:      " + getRequest().getHostRef() + "\n"
                    + "RootRef:      " + getRequest().getRootRef();
            result = new StringRepresentation(msg);
        }

        return result;
    }
}



import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.restlet.Router;

import com.noelios.restlet.ext.servlet.ServletConverter;

public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private ServletConverter converter;

    @Override
    public void init() throws ServletException {
        super.init();
        this.converter = new ServletConverter(getServletContext());
        Router router = new Router();
        router.attach("/myResource", MyResource.class);
        this.converter.setTarget(router);
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        this.converter.service(req, res);
    }

}

So my question now is how to call within jsp page a myResource. Do i need
something else to set up? When I try to call it in jsp like this:

 <p>
    1. Simple restlet: 
    <a href="<%= request.getContextPath() 
%>/restlet/myResource">RestletCall</a> 
  </p>
where /restlet/* is in web.xml in:
  <url-pattern>/restlet/*</url-pattern>
i am getting the following error:

SEVERE: Allocate exception for servlet TestServlet
java.lang.NoClassDefFoundError: org/restlet/Restlet
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
        at java.lang.Class.getConstructor0(Class.java:2699)
        at java.lang.Class.newInstance0(Class.java:326)
        at java.lang.Class.newInstance(Class.java:308)


I've imported all libraries that were required.

Thanks for any help!

Reply via email to