Hello All,
I have found a solution of this problem and it is
working fine.I modified my MyURIResolver's resolve
method as follows:
public URILocation resolve(String href, String
documentBase)
throws URIException
{
String importedSchema = "";
URILocation uriLocation = null;
try
{
importedSchema =
getSchemaDocument(href);//Reading Schema
href = "http//localhost:7001/MyServlet?fileName=" +
href
uriLocation = new URILocationImpl(new
java.io.StringReader(importedSchema),
href);
}
catch(Exception ex)
{
throw new URIException(ex.getMessage(), ex);
}
return uriLocation;
}
I have written getSchemaDocument(href) method which
reads the schema by making an URLConnection and return
it as a string. So i dont depend on Castor to read my
schema mentioned schemaLocation(Otherwise get
ConnectException). This implementation works fine but
have following doubt:
a) There is no use of passing "href" in the
URILocationImpl's constructor as i myself has read the
schema and Castor does not try to read it from this
"href" as per coding done in ImportUnmarshaller class.
It uses my StringReader at the folllowing segment of
code in ImportUnmarshaller.
InputSource source = new InputSource(uri.getReader());
source.setSystemId(uri.getAbsoluteURI());
parser.parse(source);
But constructor need it so i am providing it. Does it
have any implication?
b) Is it a right approach to do it?
Please verfiy.
Thanks & Regards,
Deepak
--- Deepak <[EMAIL PROTECTED]> wrote:
> Hello Keith,
> Thanks for reply. I have implemented URIResolver but
> i
> am still getting ConnectException. Here is complete
> code i have written:
>
> In schemaLocation='HP_CI_utility_Schema_ver1'.
>
> In MyURIResolver:
>
> public URILocation resolve(String href, String
> documentBase)
> throws URIException
> {
> // create a reader or inputstream for
> resource
> URL url = new
> URL("http//localhost:7001/MyServlet?fileName=" +
> href)
>
> href = "http//localhost:7001/MyServlet?fileName=" +
> href;//I change it af href contains only
> HP_CI_utility_Schema_ver1, is it correct?, without
> changing it castor looks into local file system.
>
> URILocation uril = new
> URILocationImpl(url.openStream(), href);
>
> /*uril.toString() prints
>
http//localhost:7001/MyServlet?fileName=HP_CI_utility_Schema_ver1*/
>
/*http//localhost:7001/MyServlet?fileName=HP_CI_utility_Schema_ver1
> can be accessed directly from browser*/
>
> return uril ;
> }
>
> While reading Schema:
> SchemaReader schemaReader = new
> SchemaReader(inputSource);
> schemaReader.setValidation(false);
> schemaReader.setURIResolver(new
> MyURIResolver());
> Schema schema = schemaReader.read();
>
> When i run the program, i still get the same
> ConnectException:
>
> Error reading import file
>
'http//localhost:7001/MyServlet?fileName=HP_CI_utility_Schema_ver1':
> java.net.ConnectException: Connection refused:
> connect
> at
>
org.exolab.castor.xml.schema.reader.ImportUnmarshaller.<init>(ImportUnmarshaller.java:199)
> at
>
org.exolab.castor.xml.schema.reader.SchemaUnmarshaller.startElement(SchemaUnmarshaller.java:523)
> at
>
org.exolab.castor.xml.schema.reader.Sax2ComponentReader.startElement(Sax2ComponentReader.java:253)
> at
>
org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
> Source)....some more
>
>
> Please guide me about solving this problem, we are
> facing this problem from long time. Is there
> anysetting required? Does castor uses
> java.net.URLConnection internally or
> SOAPHttpConnection?
>
>
> Thanks a lot in advance,
> Deepak
>
> --- Keith Visco <[EMAIL PROTECTED]> wrote:
>
> > Deepak,
> >
> > You need to implement URIResolver.
> >
> > The InputStream and Reader arguments allow you to
> > provide the URILocationImpl
> > with the way in which to read the URI. So for
> > example, in your URIResolver class
> > you can do something like the following:
> >
> > public URILocation resolve(String href,
> String
> > documentBase)
> > throws URIException
> > {
> > // create a reader or inputstream for
> > resource
> > URL url = new
> > URL("http//localhost:7001/MyServlet?" + href)
> > return new
> > URILocationImpl(url.openStream(), href);
> > }
> >
> > HTH,
> >
> > --Keith
> >
> >
> > Deepak wrote:
> > > Dear All,
> > >
> > > I want to know what is the use of follwoing 2
> > > constructors of the URILocationImpl?
> > >
> > > URILocationImpl(java.io.InputStream is,
> > > java.lang.String href)
> > > URILocationImpl(java.io.Reader reader,
> > > java.lang.String href)
> > > Creates a new URILocationImpl
> > >
> > > I want castor to retrive locally all the
> > > schemaLocation mentioned in the import tag of
> > schema.I
> > > want to implement URIResolver to achieve it. For
> > e.g.
> > > if utility.xsd is mentioned in the
> schemaLocation
> > > attribute then i want castor to look at
> > > http//localhost:7001/MyServlet?utility.xsd. I
> have
> > > implemented my URIResolver class and changing
> the
> > > URILocation to the above URL but castor is
> giving
> > me
> > > ConnectException. Why? I can get this
> utility.xsd
> > file
> > > by simple URLConnection. Can above 2
> constructors
> > be
> > > used is some way so castor can read URILocation?
> > >
> > > Thanks & Regards,
> > > Deepak
> > >
> > >
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > > http://mail.yahoo.com
> > >
> > >
> -------------------------------------------------
> > > If you wish to unsubscribe from this list,
> please
> > > send an empty message to the following address:
> > >
> > > [EMAIL PROTECTED]
> > >
> -------------------------------------------------
> > >
> > >
> >
> >
> > -------------------------------------------------
> > If you wish to unsubscribe from this list, please
> > send an empty message to the following address:
> >
> > [EMAIL PROTECTED]
> > -------------------------------------------------
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------