help (newbie): JSP openConnection DataInputStream (from classic ASP)

S

smartminion

Hi all - I'd appreciate any help in replicating the classic ASP code
below using JSP...

My experience has been with ASP, PHP and some .net - JSP is completely
new to me. I installed Ubuntu 7 Server as a lamp server and installed
the java jdk and tomcat. I'm able to do a simple helloworld.jsp page
but perhaps I need to add "www.partnerco.net" to a policy?

Ideally we'd like to be able to give a snippet of code in multiple
server-side languages (ASP, PHP, .NET, JSP) to pull content from our
site - with as little effort on their part as necessary.

In ASP:
getcontent.asp
--------------
<%
strID = "myid"
strURL = "http://www.partnerco.net/shared/?id=" & strID
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", strURL, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
response.write strHTML
%>
--------------


I've made an attempt - however I get a HTTP Status 500 access denied
error...
In JSP:
getcontent.jsp
--------------
<%@ page language="java" import="java.net.*,java.util.*,java.io.*" %>
<%
URL url;
URLConnection urlConn;
DataInputStream in;

url = new URL ("http://www.partnerco.net/shared/?id=01");
urlConn = url.openConnection();

in = new DataInputStream(urlConn.getInputStream());
String strSVContent;
while (null != ((strSVContent = in.readLine()))) {
out.println(strSVContent);
}
in.close();
%>
--------------


Error Info
--------------
exception
org.apache.jasper.JasperException: access denied
(java.net.SocketPermission www.partnerco.net:80 connect,resolve)
....

root cause
java.security.AccessControlException: access denied
(java.net.SocketPermission www.partnerco.net:80 connect,resolve)
....
--------------
Some googling indicates I may need to update a policy file for tomcat.
** Is this something a typical other user of this code would have to
do??


Don't hesitate to give me your recommended sites/books for someone
moving from classic ASP to JSP!

Thanks for any help or directions!
-J-
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

smartminion said:
Ideally we'd like to be able to give a snippet of code in multiple
server-side languages (ASP, PHP, .NET, JSP) to pull content from our
site - with as little effort on their part as necessary.

In ASP:
getcontent.asp
--------------
<%
strID = "myid"
strURL = "http://www.partnerco.net/shared/?id=" & strID
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", strURL, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
response.write strHTML
%>
--------------


I've made an attempt - however I get a HTTP Status 500 access denied
error...
In JSP:
getcontent.jsp
--------------
<%@ page language="java" import="java.net.*,java.util.*,java.io.*" %>
<%
URL url;
URLConnection urlConn;
DataInputStream in;

url = new URL ("http://www.partnerco.net/shared/?id=01");
urlConn = url.openConnection();

in = new DataInputStream(urlConn.getInputStream());
String strSVContent;
while (null != ((strSVContent = in.readLine()))) {
out.println(strSVContent);
}
in.close();
%>
--------------


Error Info
--------------
exception
org.apache.jasper.JasperException: access denied
(java.net.SocketPermission www.partnerco.net:80 connect,resolve)
...

root cause
java.security.AccessControlException: access denied
(java.net.SocketPermission www.partnerco.net:80 connect,resolve)
...

Check conf/catalina.policy !

Arne

PS: Use BufferedReader instead of DataInputStream.
 
S

smartminion

Check conf/catalina.policy !

Arne

PS: Use BufferedReader instead of DataInputStream.


Thanks for the help!

I updated the file /etc/tomcat5/policy.d/99examples.policy with the
following:
grant codeBase "file:${catalina.home}/webapps/jsp-examples/-" {
permission java.security.AllPermission;
};
and restarted tomcat (creating a new conf/catalina.policy I presume).
Success!

HOWEVER, I'm concerned this is a pretty liberal security solution. I
attempted to use:
permission java.net.SocketPermission "*.partnerco.net:80",
"connect,resolve";
but that resulted in the 500 access denied error. Any advice?

-J-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top