users@jaxb.java.net

Re: Problem with using JAXB from applet

From: Hyun Shin <hshin_at_FSC-USA.COM>
Date: Tue, 18 Mar 2003 11:01:24 -0800

Hi,

> I Guess this is not a problem but a feature.
> Really, no joke. Applets run inside a Sandbox. This
> means basically that a applet is not allowed to do
> certain things on you computer (e.g. read files).
> If every program on a website could read all your
> files, nobody would execute any applets.

I do not think this should be a feature since the property
entityExpansionLimit is being accessed by one of the JAXB class not by the
user code as you can see in the stack trace. This is definitely not under
programmer's control.

> > at java.lang.Integer.getInteger(Unknown Source)
> > at
org.apache.xerces.impl.XMLEntityManager.reset(XMLEntityManager.java:1077)

My argument is that if JAXB is designed to run on all java runtime including
in the browser, it should not try to access the property which might fail in
certain curcumstance.

Let me have one question to you all. Has anybody ever been able to run JAXB
on the browser ?

Thanks,
-Hyun

>
> So you have to allow the applet access to the
> system resources you need. There should be some
> tutorial at http://java.sun.com that shows how
> this is done.
>
> CU Christian
>
> > -----Original Message-----
> > From: Hyun Shin [mailto:hshin_at_FSC-USA.COM]
> > Sent: Montag, 17. M?rz 2003 20:34
> > To: JAXB-INTEREST_at_JAVA.SUN.COM
> > Subject: Problem with using JAXB from applet
> >
> >
> > Hi,
> >
> > I am trying to use JAXB from applet but I am getting
> > AccessControlException during unmarshal. The following are
> > stack trace of Exception and the test programs I used (which
> > is modified from SampleApp1 in users guide in order to run in
> > the applet). Of course the same program has no problem if it
> > is invoked as an application. Of course, I haven't had such
> > problem using early access version.
> >
> > Any clue?
> > Regards,
> > -Hyun
> >
> > Stack trace ---
> >
> > Starting ...
> >
> > java.security.AccessControlException: access denied
> > (java.util.PropertyPermission entityExpansionLimit read)
> >
> > at java.security.AccessControlContext.checkPermission(Unknown Source)
> >
> > at java.security.AccessController.checkPermission(Unknown Source)
> >
> > at java.lang.SecurityManager.checkPermission(Unknown Source)
> >
> > at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
> >
> > at java.lang.System.getProperty(Unknown Source)
> >
> > at java.lang.Integer.getInteger(Unknown Source)
> >
> > at java.lang.Integer.getInteger(Unknown Source)
> >
> > at
> > org.apache.xerces.impl.XMLEntityManager.reset(XMLEntityManager
> > .java:1077)
> >
> > at
> > org.apache.xerces.parsers.BasicParserConfiguration.reset(Basic
> > ParserConfiguration.java:544)
> >
> > at
> > org.apache.xerces.parsers.DTDConfiguration.reset(DTDConfigurat
> > ion.java:630)
> >
> > at
> > org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfigurat
> > ion.java:502)
> >
> > at
> > org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfigurat
> > ion.java:585)
> >
> > at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
> >
> > at
> > org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXP
> > arser.java:1142)
> >
> > at
> > com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(Unmar
> > shallerImpl.java:130)
> >
> > at
> > javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Abst
> > ractUnmarshallerImpl.java:139)
> >
> > at
> > javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Abst
> > ractUnmarshallerImpl.java:186)
> >
> > at Main.<init>(Main.java:82)
> >
> > at Test.start(Test.java:43)
> >
> > at sun.applet.AppletPanel.run(Unknown Source)
> >
> > at java.lang.Thread.run(Unknown Source)
> >
> >
> >
> >
> >
> > Main.java ---
> > import java.io.ByteArrayInputStream;
> > import java.io.IOException;
> > import java.util.Iterator;
> > import java.util.List;
> >
> > import javax.xml.bind.JAXBContext;
> > import javax.xml.bind.JAXBException;
> > import javax.xml.bind.Unmarshaller;
> >
> > // import java content classes generated by binding compiler
> > import primer.po.*;
> >
> > /*
> > * $Id: Main.java,v 1.3.4.1 2003/02/03 16:23:21 ryans Exp $
> > *
> > * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
> > *
> > * This software is the proprietary information of Sun
> > Microsystems, Inc.
> > * Use is subject to license terms.
> > *
> > */
> >
> > public class Main {
> >
> > static String postr = "<?xml version=\"1.0\"?>
> > <purchaseOrder orderDate=\"1999-10-20\"><shipTo
> > country=\"US\"><name>Alice Smith</name><street>123 Maple
> > Street</street> <city>Cambridge</city> <state>MA</state>
> > <zip>12345</zip> </shipTo> <billTo country=\"US\">
> > <name>Robert Smith</name> <street>8 Oak Avenue</street>
> > <city>Cambridge</city> <state>MA</state> <zip>12345</zip>
> > </billTo> <items> <item partNum=\"242-NO\" >
> > <productName>Nosferatu - Special Edition (1929)</productName>
> > <quantity>5</quantity> <USPrice>19.99</USPrice> </item> <item
> > partNum=\"242-MU\" > <productName>The Mummy
> > (1959)</productName> <quantity>3</quantity>
> > <USPrice>19.98</USPrice> </item> <item partNum=\"242-GZ\" >
> > <productName>Godzilla and Mothra: Battle for Earth/Godzilla
> > vs. King Ghidora</productName> <quantity>3</quantity>
> > <USPrice>27.95</USPrice> </item> </items> </purchaseOrder>";
> >
> > // This sample application demonstrates how to unmarshal
> > an instance
> > // document into a Java content tree and access data
> > contained within it.
> >
> > Main()
> > {
> > try {
> > // create a JAXBContext capable of handling
> > classes generated into
> > // the primer.po package
> > JAXBContext jc = JAXBContext.newInstance( "primer.po" );
> >
> > // create an Unmarshaller
> > Unmarshaller u = jc.createUnmarshaller();
> >
> > // unmarshal a po instance document into a tree
> > of Java content
> > // objects composed of classes from the primer.po package.
> > PurchaseOrder po =
> > (PurchaseOrder)u.unmarshal(new ByteArrayInputStream(
> > postr.getBytes("UTF-8")));
> >
> > // examine some of the content in the PurchaseOrder
> > System.out.println( "Ship the following items to: " );
> >
> > // display the shipping address
> > USAddress address = po.getShipTo();
> > displayAddress( address );
> >
> > // display the items
> > Items items = po.getItems();
> > displayItems( items );
> >
> > } catch( JAXBException je ) {
> > je.printStackTrace();
> > } catch( IOException ioe ) {
> > ioe.printStackTrace();
> > }
> > }
> >
> > public static void displayAddress( USAddress address ) {
> > // display the address
> > System.out.println( "\t" + address.getName() );
> > System.out.println( "\t" + address.getStreet() );
> > System.out.println( "\t" + address.getCity() +
> > ", " + address.getState() +
> > " " + address.getZip() );
> > System.out.println( "\t" + address.getCountry() + "\n");
> > }
> >
> > public static void displayItems( Items items ) {
> > // the items object contains a List of
> > primer.po.ItemType objects
> > List itemTypeList = items.getItem();
> >
> >
> > // iterate over List
> > for( Iterator iter = itemTypeList.iterator();
> > iter.hasNext(); ) {
> > Items.ItemType item = (Items.ItemType)iter.next();
> > System.out.println( "\t" + item.getQuantity() +
> > " copies of \"" +
> > item.getProductName() +
> > "\"" );
> > }
> > }
> > }
> >
> > Test.java --
> >
> > import java.io.*;
> > import java.net.*;
> > import java.applet.*;
> > import java.util.*;
> > import java.awt.*;
> > import java.awt.event.*;
> > import javax.swing.*;
> > import javax.swing.border.*;
> > import javax.swing.event.*;
> > import javax.swing.text.*;
> > import javax.accessibility.*;
> >
> > public class Test extends JApplet {
> >
> > public static URL codeBase = null;
> > JFrame root;
> >
> > public Test()
> > {
> > }
> >
> > public void init()
> > {
> > codeBase = this.getCodeBase();
> > root = new JFrame("Test Frame");
> > root.addWindowListener(new WindowAdapter() {
> > public void windowClosing(WindowEvent e) {
> > destroy();
> > }
> > } );
> > }
> >
> > public void destroy()
> > {
> > if (root != null)
> > root.dispose();
> > setVisible(false);
> > }
> >
> > public void start()
> > {
> > System.out.println("Starting ...");
> > new Main();
> > System.out.println("Starting done ...");
> > }
> >
> > public void stop()
> > {
> > System.out.println("Stopping ...");
> > destroy();
> > }
> >
> > void destroyApplet()
> > {
> > destroy();
> > }
> >
> > public static void main(String args[]) {
> > new Main();
> > }
> > }
> >
>