Link to home
Start Free TrialLog in
Avatar of girionis
girionisFlag for Greece

asked on

UnknownHostException with WLS 8.1

Hello,

I am using WebLogic Server 8.1 under RedHat Linux 9.0 and JDK1.4.1_05. I am trying to run the following servlet:

package smswebapp;

import java.io.*;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import javax.servlet.*;
import javax.servlet.http.*;

public class SMSServlet extends HttpServlet
{
    // The session ID obtained from the clickatel gateway
    private static String sessionID = null;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    {
        processRequest(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    {
        processRequest(request, response);
    }

    /**
    *   Processes the request from the user.
    *
    *   @param  request - The request object
    *   @param  response - The response object
    */
    public void processRequest(HttpServletRequest request, HttpServletResponse response)
    {
   
        try
        {
            System.out.println("setting properties...");
            System.getProperties().put("http.proxySet", "true");
            System.getProperties().put("http.proxyHost", "192.168.6.92");
            System.getProperties().put("http.proxyPort", "8080");

            // Create a URL for the desired page
            URL url = new URL("http://www.yahoo.com");
            System.out.println("URL object created...");
            // Read all the text returned by the server
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            System.out.println("input from url obtained...");
            String str;
            while ((str = in.readLine()) != null)
            {
                System.out.println("line: " + str);
            }
            in.close();
        }
        catch (MalformedURLException e)
        {
            System.out.println(e);
        }
        catch (IOException e)
        {
            System.out.println(e);
        }
     }
}

but I am getting an UnknowHostException at this line:

BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

I am not sure what is going on but the exact same servlet above runs fine under Tomcat 5.0. I guess WLS does not recognize the http proxy settings I am passing, or could it be something else?

Any thoughts and help is appreciated.

Regards
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

first, use ping command in linux to test connection

$ ping 192.168.6.92

if it's ok, then test www.yahoo.com

$ ping www.yahoo.com

Avatar of girionis

ASKER

I have already tested them and they both work fine. The problem is with WLS since TOmcat (on the same computer) is able to run my servlet. Besides if I run it as a standalone application I am still able to connect to yahoo.
I still haven't found the answer. Any more thoughts on this?
ASKER CERTIFIED SOLUTION
Avatar of Becky
Becky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok let me try it and will let you know... It might take a few days though since I do not currently have access to WLS :)
I just had the time to get back to this question. It seems that it is indeed a bug with WLS 8.1 I tried the exact same code under WLS8.1 on Windows (previous installation was on Red Hat Linux 9.0) and now I am getting a different problem, authentication required. This means that it does find the proxy but it needs to authenticate against it.

Thank you for your help :)
No problem.  I can post some code I've used to log into HTTPS connections in the past, if you need it.  Will have to wait till Monday, though (it's at work). :)  It's pretty straight forward - just have to remember to pass your password properly.
Id' be glad if you could do it :)

I tried using an Authenticator but to no avail, the admin is using NTML proxy, so I have a few problems :(