hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Fang <wahaha...@yahoo.com>
Subject Any idea why new GetMethod("myUrl") failed
Date Mon, 12 Jan 2009 18:48:21 GMT
Hello:
   I am trying to use Apache HttpClient 3.1 API to connect a standalone java application remotely
to weblogic9.1 server in order to download/upload pdf images.
   While i run this standalone application from IDE, such as NetBean6.1, everything works
OK. However, whenever i run this standalone application from DOS command line (WL server runs
on Unix, java client runs on Windows XP Professional), it alwasys throw java.lang.NullPointerException
at the line where the code is: method.releaseConnection(); Here method is a GetMethod instance
and has been initialized by:
   method = new GetMethod(imgUrl);

When debug, I found there is problem in the above line (i.e. method = new GetMethod(imgUrl);).
I tried with:
   method = new GetMethod();
and a method object was initialized OK. As long as i add an image URL to the method constructor,
I believe it failed. The URL issomething like:
  http://www.mycompany.com/contextroot/servlets/ImageServlet?docid=123456
and this URL works OK in our web application deployed on WL9.1 server.
   Any idea?

thanks
John


P.S. Here are part of codes:

    public byte[] downloadImage(long imgId) {
        byte[] data = null;
        GetMethod method = null;
        try {
            String imgUrl = "http://beaserver1.mycompany.com:7001/ctxroot/servlets/ImageServlet?docid=35818";
            log.debug("Servlet URL=" + imgUrl);
            HttpClient client = new HttpClient();
            System.out.println("client=" + client);
            method = new GetMethod(imgUrl);
            if (method != null) {
            	System.out.println("method=" + method);
	    } else {
		System.out.println("method is null");
	    }
//            method.setRequestHeader(new Header("User-Agent",
//            		"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"));
            method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                    new DefaultHttpMethodRetryHandler(3, false));
//            setQueryString(method, imgId, false);
            int statusCode = client.executeMethod(method);
            if (statusCode != HttpStatus.SC_OK) {
                String msg = "Method failed (image id=" + imgId
                        + ") due to: " + method.getStatusLine();
                System.out.println(msg);
                log.error(msg);
                throw new Exception(msg);
            }
            data = method.getResponseBody();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("Failed to retrieve file (imgId="
                    + imgId + ").");
        } finally {
            method.releaseConnection();
        }
        return data;
    }




      

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message