Generic Packager

878 views
Skip to first unread message

Vishakha

unread,
Jul 5, 2010, 7:44:57 AM7/5/10
to jPOS Users
Hi,

I am creating a generic packager, like this:

GenericPackager pkg = new
GenericPackager(Thread.currentThread().getContextClassLoader().getResourceAsStream("mypackager.xml"));

The packager is part of a server config, it is described as:

<server name="SimulatorServer" class="org.jpos.q2.iso.QServer"
logger="Q2">
<attr name="port" type="java.lang.Integer">8111</attr>
<channel name="xml.channel"
class="org.jpos.iso.channel.ASCIIChannel" logger="Q2" />
<!-- packager="org.jpos.iso.packager.GenericPackager"
logger="Q2">
<property name="packager-config" value="mypackager.xml" />
</channel> -->
<in>client-receive</in>
<out>client-send</out>
<request-listener class="test.ListenerSimulator" logger="Q2"/>
</server>

The required xmls and dtds are all in the base folder of my web app.

However when i run this I get the following exception:

Nested:java.io.FileNotFoundException: E:\java
\tomcat-6.0\genericpackager.dtd (The system cannot find the file
specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at
sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:
70)
at
sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:
161)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:
653)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:
1315)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:
1282)


Any suggestions?

TIA,
Vishakha

Alejandro Revilla

unread,
Jul 5, 2010, 7:58:44 AM7/5/10
to jpos-...@googlegroups.com
As a workaround, you can read the DTD from http://jpos.org/dtd/genericpackager.dtd or place it somewhere in your local Tomcat server. I don't mind having the DTDs in my local file system, but I think we might want to register these DTDs in a resource locator at some point ...

Vishakha

unread,
Jul 5, 2010, 9:08:18 AM7/5/10
to jPOS Users
Thanks for the quick response, I am able to creat the Generic Pacakger
by using
(Thread.currentThread().getContextClassLoader().getResource("mypackager.xml").toString()
and bundling all the xmls and dtd in a jar).

However when I run
ISOServer.getServer("SimulatorServer").getISOChannel("xml.channel"), I
get a null pointer. (The channel is null...)

Any ideas?

On Jul 5, 4:58 pm, Alejandro Revilla <a...@jpos.org> wrote:
> As a workaround, you can read the DTD fromhttp://jpos.org/dtd/genericpackager.dtdor place it somewhere in your local

Alejandro Revilla

unread,
Jul 5, 2010, 12:36:53 PM7/5/10
to jpos-...@googlegroups.com
If there are no client connections to your server, then you'd get a null there.

I suggest you print the content of getISOChannelNames() on your ISOServer object.

--
You received this message because you are subscribed to the  "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users

Vishakha

unread,
Jul 6, 2010, 12:36:29 AM7/6/10
to jPOS Users
YEs, I did try that, the channel names returns an empty string..

On Jul 5, 9:36 pm, Alejandro Revilla <a...@jpos.org> wrote:
> If there are no client connections to your server, then you'd get a null
> there.
>
> I suggest you print the content of getISOChannelNames() on your ISOServer
> object.
>
> On Mon, Jul 5, 2010 at 10:08 AM, Vishakha <vishakha.kulka...@gmail.com>wrote:
>
> > Thanks for the quick response, I am able to creat the Generic Pacakger
> > by using
>
> > (Thread.currentThread().getContextClassLoader().getResource("mypackager.xml").toString()
> > and bundling all the xmls and dtd in a jar).
>
> > However when I run
> > ISOServer.getServer("SimulatorServer").getISOChannel("xml.channel"), I
> > get a null pointer. (The channel is null...)
>
> > Any ideas?
>
> > On Jul 5, 4:58 pm, Alejandro Revilla <a...@jpos.org> wrote:
> > > As a workaround, you can read the DTD fromhttp://
> > jpos.org/dtd/genericpackager.dtdor place it somewhere in your local
> > > Tomcat server. I don't mind having the DTDs in my local file system, but
> > I
> > > think we might want to register these DTDs in a resource locator at some
> > > point ...
>
> > --
> > You received this message because you are subscribed to the  "jPOS Users"
> > group.
> > Please seehttp://jpos.org/wiki/JPOS_Mailing_List_Readme_first
> > To post to this group, send email to jpos-...@googlegroups.com
> > To unsubscribe, send email to jpos-users+...@googlegroups.com<jpos-users%2Bunsu...@googlegroups.com>

Mark Salter

unread,
Jul 6, 2010, 2:36:44 AM7/6/10
to jpos-...@googlegroups.com
On 06/07/2010 05:36, Vishakha wrote:
> YEs, I did try that, the channel names returns an empty string..
>
Great, so you can now adjust your code to check/wait for a client to
connect to your Server (and be allocated a Channel) to allow your
processing to work.

What sort of strategy are you using for Channel selection?
What are you going to do with the Channel once you have one?


--
Mark

Vishakha

unread,
Jul 12, 2010, 8:45:35 AM7/12/10
to jPOS Users
Hi Mark,


How do i check/wait for a client to connect?

I have registered a listener with the server, however that does not
get called.

A client tries to connect, but since i have not yet set the packager,
I get a null pointer here.

How do i get a notification when a connection is being established?

All of this works fine if i specif the packager in the server xml and
place it in a path where it can be loaded, however i want to create a
packager myself.

Thanks,
Vishakha

Mark Salter

unread,
Jul 12, 2010, 9:14:05 AM7/12/10
to jpos-...@googlegroups.com
On 12/07/2010 13:45, Vishakha wrote:

> How do i check/wait for a client to connect?

Until a connection is made, the call to getISOChannelNames will return
an empty String and /or getISOChannel returns null. Either of these
events will allow you to wait for a connection.


>
> I have registered a listener with the server, however that does not
> get called.

Via ISOServer.addISORequestListener(ISORequestListener) or something else?

The Listener above would only be invoked on receipt of a request through
a connection?

>
> A client tries to connect, but since i have not yet set the packager,
> I get a null pointer here.

Please expand on what is happening here and can you include the
Exception too?

>
> All of this works fine if i specif the packager in the server xml and
> place it in a path where it can be loaded, however i want to create a
> packager myself.

Is there something dynamic in the packager content creation or selection
that drives this need?
Is the ability to specify the packager in the xml not flexible enough?
Perhaps you could separate out the types of connection to distinct
ports? What drives your packager selection/construction I wonder?

Perhaps describe what you want to achieve, there might be a better way?

--
Mark

Vishakha

unread,
Jul 12, 2010, 9:36:25 AM7/12/10
to jPOS Users
Thanks for the response.

The reason for instantiating a packager manually is becuase the
packager.xml is bundled in a jar (so that this easy to deploy) and
qserver is not being able to find this xml in the jar.

Even if I decide to deploy the packager.xml outside a jar, the generic
packager.dtd is being searched for in the root directory of tomcat.

To avoid this I thought of instantiating the packager like this:

GenericPackager packager = new
GenericPackager(Thread.currentThread().getContextClassLoader().getResourceAsStream("mypackager.xml"));

However the above give a FileNotFound for <TOMCAT_HOME>
\genericpackager.dtd.

Can you suggest a way in which I can load the packager from my jars?

Mark Salter

unread,
Jul 12, 2010, 9:41:41 AM7/12/10
to jpos-...@googlegroups.com
On 12/07/2010 14:36, Vishakha wrote:
> To avoid this I thought of instantiating the packager like this:
>
> GenericPackager packager = new
> GenericPackager(Thread.currentThread().getContextClassLoader().getResourceAsStream("mypackager.xml"));
>
> However the above give a FileNotFound for <TOMCAT_HOME>
> \genericpackager.dtd.
>
> Can you suggest a way in which I can load the packager from my jars?
>
Did you try adding genericpackager.dtd into <TOMCAT_HOME>?

Just as Alejandro suggested :-
http://groups.google.com/group/jpos-users/msg/9f2bdf68557a136c?hl=en_US

--
Mark

Vishakha

unread,
Jul 12, 2010, 9:53:12 AM7/12/10
to jPOS Users
YEs, placing it <TOMCAT_HOME> does work, but is not an option i am
comfortable with.

Using the http path gave rise to some exception, however it was some
days ago, need to try this again...

Mark Salter

unread,
Jul 12, 2010, 9:57:46 AM7/12/10
to jpos-...@googlegroups.com
On 12/07/2010 14:53, Vishakha wrote:
> YEs, placing it <TOMCAT_HOME> does work, but is not an option i am
> comfortable with.
Ok, just checking in case you missed the suggestion.

>
> Using the http path gave rise to some exception, however it was some
> days ago, need to try this again...

Ok, you are aiming to use a local copy?

--
Mark

Vishakha

unread,
Jul 12, 2010, 10:05:56 AM7/12/10
to jPOS Users
yes.

Is there any other alternative to creating the packager?

Mark Salter

unread,
Jul 13, 2010, 4:55:15 AM7/13/10
to jpos-...@googlegroups.com
On 12/07/2010 15:05, Vishakha wrote:
> yes.
Fine, a local copy makes sense.

>
> Is there any other alternative to creating the packager?

You don't have to use the Generic Packager and thus could avoid needing
the dtd completely by 'hardcoding' your packager. You would need to
balance the pros and cons.

May I also ask why placing the copy of the dtd in TOMCAT_HOME is
unacceptable to you?

--
Mark

Vishakha

unread,
Jul 14, 2010, 3:23:18 AM7/14/10
to jPOS Users
Well, the idea was to be able to create a jar and be able to deploy it
any installation.

For now going ahead with putting the dtd in tomcat home.

Thanks for all the help.

Mark Salter

unread,
Jul 14, 2010, 3:39:07 AM7/14/10
to jpos-...@googlegroups.com
On 14/07/2010 08:23, Vishakha wrote:
> Well, the idea was to be able to create a jar and be able to deploy it
> any installation.
My suggestion using a code Packager instead of a GenericPackager would
allow that, although you loose the flexibility this provides.

>
> For now going ahead with putting the dtd in tomcat home.
Ok, thanks for coming back.

--
Mark

Reply all
Reply to author
Forward
0 new messages