users@glassfish.java.net

HttpsURLConnection fails in web container

From: <forums_at_java.net>
Date: Tue, 7 Jun 2011 09:56:07 -0500 (CDT)

I'm trying to call a paypal api and have a java se program which works just
fine. The problem is that when I use exactly the same code from a jsf managed
bean in my web application the request gets rejected with 'api credentials
are incorrect' - the credentials are sent in the https header. Clearly
something must be going over the wire differently, but what? and how to find
out? This is the code I'm using (the login info is public):   public class
TestConvertCurrency {     private static final String BASE_URI =
"https://svcs.sandbox.paypal.com/AdaptivePayments/ConvertCurrency [1]";
    public static void main(String[] args) throws Exception {
        URL url = new URL(BASE_URI);
        HttpsURLConnection conn = (HttpsURLConnection)
url.openConnection();
        conn.setDoOutput(true);        
conn.setRequestMethod("GET");        
conn.setRequestProperty("X-PAYPAL-REQUEST-DATA-FORMAT", "NV");
        conn.setRequestProperty("X-PAYPAL-APPLICATION-ID",
"APP-80W284485P519543T");
        conn.setRequestProperty("X-PAYPAL-SECURITY-PASSWORD",
"1280413916");
        conn.setRequestProperty("X-PAYPAL-SANDBOX-EMAIL-ADDRESS",
"adaptiveapi_at_yahoo.com [2]");
        conn.setRequestProperty("X-PAYPAL-SECURITY-SIGNATURE",
"AJqTy90-dyotFzmYdTE03ONZPcL-AE0fp4GtTgo6VmrJUATtzrHTSXCY");
        conn.setRequestProperty("X-PAYPAL-SECURITY-USERID",
"agent_1280413911_biz_api1.yahoo.com");
        conn.setRequestProperty("X-PAYPAL-RESPONSE-DATA-FORMAT",
"NV");
        //conn.setRequestProperty("X-PAYPAL-DEVICE-IPADDRESS",
ipaddress);         OutputStreamWriter wr = new
OutputStreamWriter(conn.getOutputStream());         String body =
"requestEnvelope.errorLanguage=en_US&requestEnvelope.details=ReturnAll&baseAmountList.currency(0).amount=10.00&baseAmountList.currency(0).code=USD&convertToCurrencyList.currencyCode(0)=GBP";
        wr.write(body);
        wr.flush();
        wr.close();         BufferedReader rd = new
BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = rd.readLine()) != null) {
            sb.append(line).append('\n');
        }         System.out.println("response: " + sb);
        rd.close();
        conn.disconnect();   I just copy & paste the code into a
managed bean but then I hit problems. I have checked my imports they are
the same in both the standalone and web apps. I've tried using fiddler2 to
inspect the outgoing request but it seems that HttpsURLConnection doesn't use
the WinINET API so I've no idea how to go about setting this up to monitor a
java application.   If anyone has any ideas I'd be eternally grateful for
any help.   Thanks.

[1] https://svcs.sandbox.paypal.com/AdaptivePayments/ConvertCurrency
[2] mailto:adaptiveapi_at_yahoo.com

--
[Message sent by forum member 'oversteer']
View Post: http://forums.java.net/node/809999