You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steven Banks <sb...@silacom.com> on 2001/05/24 15:43:21 UTC

HTTPS connections from servlet

I am having severe trouble getting my application to access a secure
web-server from within one of my servlets.

I have installed all the necessary JSSE jar files, set the properties:

    System.setProperty("java.protocol.handler.pkgs",
                       "com.sun.net.ssl.internal.www.protocol");
    java.security.Security.addProvider(
              new com.sun.net.ssl.internal.ssl.Provider());

... and tried fiddling around with the proxy properties, to no avail.

In order to allow this functionality, do we need to build an SSL enabled
tomcat instance? Or am I missing something more fundamental. The code runs
fine outside of Tomcat BTW.

I've searched the net high and low for answers, but found none. ANy help
would be most appreciated. Oh, we're using tomcat 3.2.1 on NT4.

Regards
Steve Banks

RE: HTTPS connections from servlet

Posted by Rams <ra...@cmcltd.com>.
what exactly is ur problem?
u need to connect to a server securely from ur servlet, right?
or anything more?
lf u want to connect thru https to another server, no need for ur tomcat
to get ssl enabled.

elaborate ur problem.

rgrds

--Rams


-----Original Message-----
From: Steven Banks [mailto:sbanks@silacom.com]
Sent: Thursday, May 24, 2001 7:13 PM
To: 'tomcat-user@jakarta.apache.org'
Subject: HTTPS connections from servlet


I am having severe trouble getting my application to access a secure
web-server from within one of my servlets.

I have installed all the necessary JSSE jar files, set the properties:

    System.setProperty("java.protocol.handler.pkgs",
                       "com.sun.net.ssl.internal.www.protocol");
    java.security.Security.addProvider(
              new com.sun.net.ssl.internal.ssl.Provider());

... and tried fiddling around with the proxy properties, to no avail.

In order to allow this functionality, do we need to build an SSL enabled
tomcat instance? Or am I missing something more fundamental. The code runs
fine outside of Tomcat BTW.

I've searched the net high and low for answers, but found none. ANy help
would be most appreciated. Oh, we're using tomcat 3.2.1 on NT4.

Regards
Steve Banks

RE: HTTPS connections from servlet

Posted by Martin van den Bemt <mv...@mvdb.com>.
It's just a code snippet from one of my servlets.. It works fine...

Mvgr,
Martin

   Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.ww
w.protocol");
    String url = "https://<servername>";
    // let's connect to the url
    InputStream is = null;
    dbg.writeln("Status : PAY"+status);
    int maxretries = Integer.parseInt(tdps.get("PAY-"+status,"maxretries"));
    is = letsconnect(is, urltosend.toString());
    maxretries-=1;
    while ( is == null) {
      if (maxretries==0) {
        System.out.println("Error: Unable to connect");
        resp.sendRedirect(tdoffline);
        return;
      }else{
        // a small brake for a couple of second could be nice
        dbg.writeln("attempting to get something from td");
        is = letsconnect(is, urltosend.toString());
        maxretries-=1;
      }
    }
  while(is.available() == 0) {};
    byte[] b = new byte[is.available()];
    is.read(b);
    String bs = new String(b);
    dbg.writeln("Open returned : "+ bs);
      return;
    }

  public InputStream letsconnect(InputStream is,String urltosend) throws
IOException {
    try {
      is = new URL(urltosend.toString()).openConnection().getInputStream();
    }
    catch (IOException e) {
      dbg.writeln("Error : creating new connection "+String.valueOf(e));
    }

    return is;
  }

> -----Original Message-----
> From: Steven Banks [mailto:sbanks@silacom.com]
> Sent: Thursday, May 24, 2001 3:43 PM
> To: 'tomcat-user@jakarta.apache.org'
> Subject: HTTPS connections from servlet
>
>
> I am having severe trouble getting my application to access a secure
> web-server from within one of my servlets.
>
> I have installed all the necessary JSSE jar files, set the properties:
>
>     System.setProperty("java.protocol.handler.pkgs",
>                        "com.sun.net.ssl.internal.www.protocol");
>     java.security.Security.addProvider(
>               new com.sun.net.ssl.internal.ssl.Provider());
>
> ... and tried fiddling around with the proxy properties, to no avail.
>
> In order to allow this functionality, do we need to build an SSL enabled
> tomcat instance? Or am I missing something more fundamental. The code runs
> fine outside of Tomcat BTW.
>
> I've searched the net high and low for answers, but found none. ANy help
> would be most appreciated. Oh, we're using tomcat 3.2.1 on NT4.
>
> Regards
> Steve Banks
>