Solved

Can't execute Get method in HttpConnection in one computer

Posted on 2007-03-21
23
411 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:mayankeagle
ID: 18772910
Pls post the code you use. Also, are you able to ping to the server?
0
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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:mayankeagle
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now