HTTP Status 500 - java.lang.ClassCastException: rest.rest Page cannot be cast to javax.servlet.http.HttpServletRequest
<p>I have a rest page to show some text html in browser. Its working fine.</p>

<p>Now I am working to get the URL of the rest page so that I an get the host of this rest call. For this, I tried to add some code with extending HttpRequest, but I am getting Class cast exception as bwlow,</p>

<pre><code>HTTP Status 500 - java.lang.ClassCastException: com.appl.rest.restPage cannot be cast to javax.servlet.http.HttpServletRequest
</code></pre>

<p>Here is my RestPage code</p>

<pre><code>@Path("/paints")
public class restPage {

    private static final long serialVersionUID = 1L;
    private URLServiceImpl urlService = new URLServiceImpl();

    @GET
    @Path("/{param}")
    @Produces({MediaType.TEXT_HTML}) 
    public String printMessage(@PathParam("param") String url) throws IOException {     
        getHost();      
        return urlService.getResponse(url);     
    }

    protected String getHost() {
        HttpServletRequest request = new HttpServletRequest() {


        @Override
        public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1)
                throws IllegalStateException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public AsyncContext startAsync() throws IllegalStateException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void setCharacterEncoding(String arg0)
                throws UnsupportedEncodingException {
            // TODO Auto-generated method stub

        }

        @Override
        public void setAttribute(String arg0, Object arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void removeAttribute(String arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public boolean isSecure() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isAsyncSupported() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isAsyncStarted() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public ServletContext getServletContext() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int getServerPort() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public String getServerName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getScheme() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public RequestDispatcher getRequestDispatcher(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int getRemotePort() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public String getRemoteHost() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getRemoteAddr() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getRealPath(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public BufferedReader getReader() throws IOException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getProtocol() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String[] getParameterValues(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Enumeration&lt;String&gt; getParameterNames() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Map&lt;String, String[]&gt; getParameterMap() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getParameter(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Enumeration&lt;Locale&gt; getLocales() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Locale getLocale() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int getLocalPort() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public String getLocalName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getLocalAddr() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ServletInputStream getInputStream() throws IOException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public DispatcherType getDispatcherType() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getContentType() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getContentLengthLong() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public int getContentLength() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public String getCharacterEncoding() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Enumeration&lt;String&gt; getAttributeNames() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Object getAttribute(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public AsyncContext getAsyncContext() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public &lt;T extends HttpUpgradeHandler&gt; T upgrade(Class&lt;T&gt; arg0)
                throws IOException, ServletException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void logout() throws ServletException {
            // TODO Auto-generated method stub

        }

        @Override
        public void login(String arg0, String arg1) throws ServletException {
            // TODO Auto-generated method stub

        }

        @Override
        public boolean isUserInRole(String arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isRequestedSessionIdValid() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isRequestedSessionIdFromUrl() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isRequestedSessionIdFromURL() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isRequestedSessionIdFromCookie() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public Principal getUserPrincipal() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public HttpSession getSession(boolean arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public HttpSession getSession() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getServletPath() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getRequestedSessionId() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public StringBuffer getRequestURL() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getRequestURI() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getRemoteUser() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getQueryString() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getPathTranslated() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getPathInfo() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Collection&lt;Part&gt; getParts() throws IOException, ServletException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Part getPart(String arg0) throws IOException, ServletException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getMethod() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int getIntHeader(String arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public Enumeration&lt;String&gt; getHeaders(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Enumeration&lt;String&gt; getHeaderNames() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getHeader(String arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getDateHeader(String arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public Cookie[] getCookies() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getContextPath() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getAuthType() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String changeSessionId() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean authenticate(HttpServletResponse arg0) throws IOException,
                ServletException {
            // TODO Auto-generated method stub
            return false;
        }
    };
        System.out.println("getContextPath"+request.getContextPath());
        System.out.println("getRemoteHost"+request.getRemoteHost());
        System.out.println("getRequestURL"+request.getRequestURL());
        System.out.println("getRequestURI"+request.getRequestURI());    
        return request.getRequestURI();
    }
</code></pre>

<p>What is the wrong I am doing here.</p>