用java从Liferay服务器下载文件

用java从Liferay服务器下载文件,java,liferay,portlet,Java,Liferay,Portlet,我正试图编写Java代码从Liferay服务器下载一个文件。我找到了这个示例,但我不知道在哪里插入目标URL: static Object setRequest(){ static String getURL(HttpServletRequest req) { String scheme = req.getScheme(); // http String serverName = req.getServerName();

我正试图编写Java代码从Liferay服务器下载一个文件。我找到了这个示例,但我不知道在哪里插入目标URL:

static Object setRequest(){

    static String getURL(HttpServletRequest req) {

        String scheme = req.getScheme();             // http
        String serverName = req.getServerName();     // hostname.com
        int serverPort = req.getServerPort();        // 80
        String contextPath = req.getContextPath();   // /mywebapp
        String servletPath = req.getServletPath();   // /servlet/MyServlet
        String pathInfo = req.getPathInfo();         // /a/b;c=123
        String queryString = req.getQueryString();   // d=789

        // Reconstruct original requesting URL
        StringBuffer url =  new StringBuffer();
        url.append(scheme).append("://").append(serverName);

        if ((serverPort != 80) && (serverPort != 443)) {
            url.append(":").append(serverPort);
        }

        url.append(contextPath).append(servletPath);

        if (pathInfo != null) {
            url.append(pathInfo);
        }
        if (queryString != null) {
            url.append("?").append(queryString);
        }
        return url.toString();
    }
}

正如您可能看到的,这个类需要一个
HttpServletRequest
,那么我如何创建这个请求并将其链接到我的URL?

谢谢,但是在哪里包含我需要阅读的URL呢?getRequestURL()是否将url作为参数?再次感谢,但您没有抓住要点,服务器站点(我正试图从中下载)有lifeRay,此直接连接方法不起作用
String urlname = "";//You set your url path for the file 
URL url = new URL(urlname);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
if (con.getResponseCode() == 200) {
   InputStream stream = con.getInputStream();
   // now you can read the read the data
}