• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

Can't execute Get method in HttpConnection in one computer

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
ricjava
Asked:
ricjava
  • 13
  • 5
  • 2
1 Solution
 
CEHJCommented:
Is one using a proxy?
0
 
ricjavaAuthor Commented:
No, it is not using proxy
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Pls post the code you use. Also, are you able to ping to the server?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ricjavaAuthor Commented:
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
 
ricjavaAuthor Commented:
sorry ignore above
0
 
ricjavaAuthor Commented:
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
 
ricjavaAuthor Commented:
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
 
CEHJCommented:
What response code are you getting?
0
 
ricjavaAuthor Commented:
i got

100
0
 
CEHJCommented:
Not even sure that's a valid HTTP code
0
 
ricjavaAuthor Commented:
sorry I may have misunderstood your question CEHJ...
0
 
ricjavaAuthor Commented:
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
 
ricjavaAuthor Commented:
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
 
CEHJCommented:
Can you ping or telnet to that address?
0
 
ricjavaAuthor Commented:
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
 
CEHJCommented:
Try telnetting to it
0
 
ricjavaAuthor Commented:
now i managed to ping with just the host

and got its reply
0
 
ricjavaAuthor Commented:
My colleague has helped to solve the problem.
Thanks for all attempted help given to me.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
What was the resolution
0
 
ricjavaAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 13
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now