Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
smartminion - 20 Aug 2007 14:31 GMT
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-
smartminion - 21 Aug 2007 00:30 GMT
Nobody can help a brother out?!
Arne Vajhøj - 21 Aug 2007 00:48 GMT
> 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
[quoted text clipped - 52 lines]
> ** Is this something a typical other user of this code would have to
> do??

Check conf/catalina.policy !

Arne

PS: Use BufferedReader instead of DataInputStream.
smartminion - 22 Aug 2007 06:23 GMT
> 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-


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.