    public void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        if (getTarget() != null) {
            ServletCall servletCall = new ServletCall(getLogger(), request
                    .getLocalAddr(), request.getLocalPort(), request, response);
            HttpRequest httpRequest = toRequest(servletCall);
            HttpResponse httpResponse = new HttpResponse(servletCall,
                    httpRequest);
            if (this.baseRef == null) {
                String baseUri = request.getContextPath()
                        + request.getServletPath();
                int baseIndex = request.getRequestURI().indexOf(baseUri);
                if (baseIndex != -1) {
                    this.baseRef = new Reference(request.getRequestURI()
                            .substring(0, baseIndex + baseUri.length()));
                }
            }
            httpRequest.getResourceRef().setBaseRef(this.baseRef);
            getTarget().handle(httpRequest, httpResponse);
            commit(httpResponse);
        } else {
            getLogger().warning("Unable to find the Restlet target");
        }
    }

    public void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        if (getTarget() != null) {
            ServletCall servletCall = new ServletCall(getLogger(), request
                    .getLocalAddr(), request.getLocalPort(), request, response);
            HttpRequest httpRequest = toRequest(servletCall);
            HttpResponse httpResponse = new HttpResponse(servletCall,
                    httpRequest);
            if (this.baseRef == null) {
                String basePath = request.getContextPath()
                        + request.getServletPath();
                String baseUri = request.getRequestURL().toString();
                int baseIndex = baseUri.indexOf(basePath);
                if (baseIndex != -1) {
                    this.baseRef = new Reference(baseUri.substring(0, baseIndex
                            + basePath.length()));
                }
            }
            httpRequest.getResourceRef().setBaseRef(this.baseRef);
            getTarget().handle(httpRequest, httpResponse);
            commit(httpResponse);
        } else {
            getLogger().warning("Unable to find the Restlet target");
        }
    }
