Solved

Can't execute Get method in HttpConnection in one computer

Posted on 2007-03-21
23
426 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 74
how to see all occupied ports on windows 10 laptop 15 84
java imports not found 4 50
Java basic valueOf question 1 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

733 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