Solved

Can't execute Get method in HttpConnection in one computer

Posted on 2007-03-21
23
418 Views
Last Modified: 2010-03-31
Hi,

Has anyone used HttpConnection class from HttpClient package before?
I can't execute the Get method from my computer but other computer in my company could. And it is using the same code. Pls help. Thx in advance

0
Comment
Question by:ricjava
  • 13
  • 5
  • 2
23 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18762359
Is one using a proxy?
0
 

Author Comment

by:ricjava
ID: 18762365
No, it is not using proxy
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18772910
Pls post the code you use. Also, are you able to ping to the server?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:ricjava
ID: 18791306
public COMMON_IBE_PaymentManagerRespondData payBankIslam( COMMON_IBE_PaymentManagerData req ) throws COMMON_Exception
    {
        System.out.println( "William printing inc... => In Here!!!" );
            COMMON_IBE_PaymentManagerRespondData payBankMgrRespondData = new COMMON_IBE_PaymentManagerRespondData();
   
        try
        {
            Hashtable htURL = cmmnLblDAO.getPaymentManagerInfo();
           
            String strPort = (String) htURL.get("Port");
            String strHost = (String) htURL.get("Host");
            String strProtocol = (String) htURL.get("Protocol");
            String strPaymenturl = (String) htURL.get("Paymenturl");
            System.out.println("strPort PaymentManagerSBpay *************************" + strPort);
            System.out.println("strHost PaymentManagerSB" + strHost);
            System.out.println("strProtocol PaymentManagerSB" + strProtocol);
            System.out.println("strPaymenturl PaymentManagerSB" + strPaymenturl);
           
            req.setStrHost(strHost);
            req.setStrPort(strPort);
            req.setStrProtocol(strProtocol);
            req.setStrPaymenturl(strPaymenturl);
           
           
            COMMON_PaymentGatewayManager paymgr = new COMMON_PaymentGatewayManager();
           
            //COMMON_PaymentGatewayManager.test();  // For testing only
           
            payBankMgrRespondData = paymgr.payBankIslam( req );
        }
        catch( Exception e )
        {
            e.printStackTrace();
           
            throw new COMMON_Exception( "Exception caught in COMMON_PaymentManagerSB", "Exception caught in COMMON_PaymentManagerSB", 1);
        }
       
        return payBankMgrRespondData;
    }//End: payBankIslam()
0
 

Author Comment

by:ricjava
ID: 18791310
sorry ignore above
0
 

Author Comment

by:ricjava
ID: 18791318
public static COMMON_IBE_PaymentManagerRespondData payBankIslam( COMMON_IBE_PaymentManagerData req)
    {
            NVPair[] pair = new NVPair[11];
            pair[0] = new NVPair("strPaymentAction", req.getStrPaymentAction());
            pair[1] = new NVPair("strOrderInfo", req.getStrOrderInfo());
            pair[2] = new NVPair("strUsrNbr", req.getStrUsrNbr());
            pair[3] = new NVPair("strSessionId", req.getStrSessionId());
            pair[4] = new NVPair("strCurrency", req.getStrCurrency());
            pair[5] = new NVPair("strCardNum", req.getStrCardNum());
            pair[6] = new NVPair("strCardType", req.getStrCardType());
            pair[7] = new NVPair("strCardExp", req.getStrCardExp());
            pair[8] = new NVPair("strCvv", req.getStrCvv());
        pair[9] = new NVPair("strPurchaseAmount", req.getStrPurchaseAmount());
        pair[10] = new NVPair("strSbrNbr", req.getStrSbrNbr());
       
            COMMON_IBE_PaymentManagerRespondData pRes = new COMMON_IBE_PaymentManagerRespondData();

        // DEBUG
        System.out.println("COMMON_PaymentGatewayManager.payBankIslam(): Request URL = [" + req.getStrProtocol() + "://" + req.getStrHost() + ":" + req.getStrPort() + strFile + "]");

       
            try {
                  HTTPConnection con = new HTTPConnection(req.getStrProtocol(), req.getStrHost(), Integer.parseInt(req.getStrPort()));
//      HTTPConnection con = new HTTPConnection("http", "192.168.250.20", 8001);  // For testing only
                  CookieModule.setCookiePolicyHandler(null);
                  con.setTimeout(TIME_OUT);
                  if (log.isDebugEnabled()) {
                        log.debug("DoTransaction through: " + req.getStrProtocol() + "://" + req.getStrHost() + ":" + req.getStrPort() + strFile);
                        for (int i = 0; i < pair.length; i++) {
                              log.debug("NVPair -- " + pair[i].toString());
                        }
                  }

      System.out.println("hi..b4 calling con.Get");
                  HTTPResponse res = con.Get(strFile, pair);
      System.out.println("hi..after calling con.Get");

            // DEBUG
            System.out.println("COMMON_PaymentGatewayManager.payBankIslam(): res.getStatusCode()  = [" + res.getStatusCode() + "]");
            System.out.println("COMMON_PaymentGatewayManager.payBankIslam(): res.getReasonLine()  = [" + res.getReasonLine() + "]");
            System.out.println("COMMON_PaymentGatewayManager.payBankIslam(): res.getOriginalURI()  = [" + res.getOriginalURI() + "]");

                  if (res.getStatusCode() == 200) {
                        InputStream in = null;
                        if (log.isDebugEnabled()) {
                              in = new COMMON_InputStreamViewer(res.getInputStream());
                        } else {
                              in = res.getInputStream();
                        }
                        
                        SAXParser parser = saxFactory.newSAXParser();
                        COMMON_PaymentHandler handler = new COMMON_PaymentHandler( pRes );
                        parser.parse(in, handler);
                        if (log.isDebugEnabled() && (in instanceof COMMON_InputStreamViewer))
                              log.debug("Response from DoTransaction: \n" + ((COMMON_InputStreamViewer)in).getInput());
                  } else {
                        log.info("DoTransaction Response error: " + res.getReasonLine());

                        if (log.isDebugEnabled()) {
                              try {
                                    COMMON_InputStreamViewer in = new COMMON_InputStreamViewer(res.getInputStream());
                                    byte[] b = new byte[1024];
                                    while ( in.read(b) != -1);
                                    in.close();
                                    log.debug("DoTransaction Response error: \n" + in.getInput());
                              } catch (Exception e) {}
                        }
                  }
           
            System.out.println( "William printing inc" + pRes.getStrStatus() );
            } catch (Exception e) {
                  
            // DEBUG
            e.printStackTrace();
           
            if (log.isDebugEnabled()) log.debug("PayServlet Exception.", e);
            }

            return pRes;
      }
0
 

Author Comment

by:ricjava
ID: 18791323
I just can't execute the line
HTTPResponse res = con.Get(strFile, pair);

I get an exception which is connection refused.

But I'm able to put the url into web browser and get response.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18791341
What response code are you getting?
0
 

Author Comment

by:ricjava
ID: 18791357
i got

100
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18791369
Not even sure that's a valid HTTP code
0
 

Author Comment

by:ricjava
ID: 18791375
sorry I may have misunderstood your question CEHJ...
0
 

Author Comment

by:ricjava
ID: 18791431
actually i can't even get the HttpResponse back......
look at the line
 System.out.println("hi..b4 calling con.Get");
                  HTTPResponse res = con.Get(strFile, pair);
      System.out.println("hi..after calling con.Get");

in my program...

It CANNOT reach System.out.println("hi..after calling con.Get");

What i got from my dos prompt is

hi..b4 calling con.Get
java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
        at java.net.Socket.connect(Socket.java:452)
        at java.net.Socket.connect(Socket.java:402)
        at java.net.Socket.<init>(Socket.java:309)
        at java.net.Socket.<init>(Socket.java:153)
        at HTTPClient.HTTPConnection$EstablishConnection.run(HTTPConnection.java:3784)
PayServlet Exception.
0
 

Author Comment

by:ricjava
ID: 18791440
however, the same code is able to run my my colleague's computer

But I can't run it in my computer. I do not have proxy and my window firewall is disabled.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18791447
Can you ping or telnet to that address?
0
 

Author Comment

by:ricjava
ID: 18791561
i'm not allowed to ping to that address according to my supervisor...but I could put the url on my browser and it is ok

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18791573
Try telnetting to it
0
 

Author Comment

by:ricjava
ID: 18791648
now i managed to ping with just the host

and got its reply
0
 

Author Comment

by:ricjava
ID: 18814716
My colleague has helped to solve the problem.
Thanks for all attempted help given to me.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18821210
What was the resolution
0
 

Accepted Solution

by:
ricjava earned 0 total points
ID: 18833929
Hi,

My colleague which could run the program in his pc, took his startWebLogic.cmd file and use it to overwrite the one in my pc. After that, it works. We are using weblogic as app server. He did not read any comments from this site.

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
starter POM and spring-boot-starter,  spring-boot-web 2 54
Java Server Faces parameter pass? 6 48
servlet example issue 6 38
hibernate example for saving data 19 37
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question