Discussion:
AW: AW: AW: MessageContext.getCurrentContext() returns null
Dorner, Thomas
2004-04-01 13:44:32 UTC
Permalink
You will send a attachment - i do it like this:

**********************
Server
**********************
public java.lang.String getFileAsAttachment(java.lang.String
XMLRequest) throws java.rmi.RemoteException {

String fileName = "C:\\WebService\\webapps\\xxx\\arrow.gif";
String fileName1 =
"C:\\WebService\\webapps\\xxx\\folder.gif";

//explicitly set format to DIME, default is MIME
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();

rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachme
nts.SEND_TYPE_DIME);

DataHandler dh = new DataHandler(new
FileDataSource(fileName));
if (dh == null ) System.err.println("dhSource is null");

DataHandler dh1 = new DataHandler(new
FileDataSource(fileName1));
if (dh1 == null ) System.err.println("dhSource is null");

AttachmentPart ap = new AttachmentPart(dh);
AttachmentPart ap1 = new AttachmentPart(dh1);
ap.setContentId("Filename1");
ap1.setContentId("Filename2");

MessageContext context=MessageContext.getCurrentContext();
Message responseMessage=context.getResponseMessage();

responseMessage.addAttachmentPart(ap);
responseMessage.addAttachmentPart(ap1);

return XMLRequest;
}


******************
Client
********************

String doc = soapService.getFileAsAttachment(xml);


Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart)
attachments[0];
AttachmentPart attachPart1 = (AttachmentPart)
attachments[1];

DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();

File myFile1 = new File("C:\\temp\\" +
attachPart.getContentId() + ".gif");
FileOutputStream myFOS1 = new
FileOutputStream(myFile1);
arrow.writeTo(myFOS1);

File myFile2 = new File("C:\\temp\\" +
attachPart1.getContentId() + ".gif");
FileOutputStream myFOS2 = new
FileOutputStream(myFile2);
folder.writeTo(myFOS2);

System.out.println(attachPart1.getContentId());


Tomi



-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Donnerstag, 1. April 2004 15:38
An: ***@t-systems.com; axis-***@ws.apache.org
Betreff: Re: AW: AW: MessageContext.getCurrentContext() returns null


OK, forgive my stupidity, but I am trying to send an attachment back
from the server. I did say that I was trying to send the attachment
back in the response in my original message but, I probably should have
been clearer. That would also explain why I was confused about your
orginal response.

Anyway, I have attempted to model my service after the attachments
example included in the Axis distribution. On the server side, I get
null for the message context (which seems impossible to me). Any
ideas?

Thanks.
Tony
oService is your Service or your locator (both are Service or extend
Service!)
--> read my text and think about! ;)

Forget the MessageContext - you can t make

MessageContext context = MessageContext.get....

if you use the stub and the skeleton!
I get also null from MessageContext


-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Donnerstag, 1. April 2004 14:38
An: ***@t-systems.com; axis-***@ws.apache.org
Betreff: Re: AW: MessageContext.getCurrentContext() returns null


In your examples, what is "soapService" and "oService"?

Is it possible that my service is not deployed correctly and that is
why the current message context is null?

Thanks.
Tony
You can handle your attachment like this - without using the
MessageContext

Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart) attachments[0];
AttachmentPart attachPart1 = (AttachmentPart) attachments[1];

DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();

File myFile1 = new File("C:\\temp\\" + attachPart.getContentId() +
".gif");
FileOutputStream myFOS1 = new FileOutputStream(myFile1);
arrow.writeTo(myFOS1);

....

Another solution can be - take your Service or Locator (also Service)
and get the AxisEngine --> then make
engine.getCurrentMessageContext()!?

AxisEngine engine = oService.getEngine();
engine.getCurrentMessageContext();

Thomas

-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Mittwoch, 31. März 2004 15:51
An: axis-***@ws.apache.org
Betreff: MessageContext.getCurrentContext() returns null


When I invoke MessageContext.getCurrentContext(), it returns null.
Can
anyone explain why that might happen and how I can fix it? I am
trying
to add a DIME attachment to a response and it is hard to do without a
MessageContext.

Thanks.
Tony
s***@hotmail.com
2004-04-01 14:48:04 UTC
Permalink
Hi all,

I got one WSDL file with the following defination:

<types>
....
<s:complexType name="IPOQuoteResponse"/>
...
</types>


Then I genarate the java files with WSDL2Java. I wonder what does it means
with no more defination within the complexType? How should I implement this
type in java?

Any suggestion would be appreciate!

Thanks!

Sam Ye
Anne Thomas Manes
2004-04-02 13:27:09 UTC
Permalink
You need to provide a definition for the complex type.
Post by s***@hotmail.com
Hi all,
<types>
....
<s:complexType name="IPOQuoteResponse"/>
...
</types>
Then I genarate the java files with WSDL2Java. I wonder what does it means
with no more defination within the complexType? How should I implement this
type in java?
Any suggestion would be appreciate!
Thanks!
Sam Ye
~~~~~~~~~~~~~~~~~~
Anne Thomas Manes
VP & Research Director
Burton Group

Tony Thompson
2004-04-01 15:07:25 UTC
Permalink
OK, this looks pretty much like what I am doing but, this line throws a
NullPointerException because getCurrentMessageContext() returns null:

Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();

So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?

Tony
You will send a attachment - i do it like this:

**********************
Server
**********************
public java.lang.String getFileAsAttachment(java.lang.String
XMLRequest) throws java.rmi.RemoteException {

String fileName =
"C:\\WebService\\webapps\\xxx\\arrow.gif";
String fileName1 =
"C:\\WebService\\webapps\\xxx\\folder.gif";

//explicitly set format to DIME, default is MIME
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();

rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachme
nts.SEND_TYPE_DIME);

DataHandler dh = new DataHandler(new
FileDataSource(fileName));
if (dh == null ) System.err.println("dhSource is
null");

DataHandler dh1 = new DataHandler(new
FileDataSource(fileName1));
if (dh1 == null ) System.err.println("dhSource is
null");

AttachmentPart ap = new AttachmentPart(dh);
AttachmentPart ap1 = new AttachmentPart(dh1);
ap.setContentId("Filename1");
ap1.setContentId("Filename2");

MessageContext
context=MessageContext.getCurrentContext();
Message responseMessage=context.getResponseMessage();

responseMessage.addAttachmentPart(ap);
responseMessage.addAttachmentPart(ap1);

return XMLRequest;
}


******************
Client
********************

String doc =
soapService.getFileAsAttachment(xml);


Object[] attachments =
soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart)
attachments[0];
AttachmentPart attachPart1 = (AttachmentPart)
attachments[1];

DataHandler arrow =
attachPart.getDataHandler();
DataHandler folder =
attachPart1.getDataHandler();

File myFile1 = new File("C:\\temp\\" +
attachPart.getContentId() + ".gif");
FileOutputStream myFOS1 = new
FileOutputStream(myFile1);
arrow.writeTo(myFOS1);

File myFile2 = new File("C:\\temp\\" +
attachPart1.getContentId() + ".gif");
FileOutputStream myFOS2 = new
FileOutputStream(myFile2);
folder.writeTo(myFOS2);

System.out.println(attachPart1.getContentId());


Tomi



-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Donnerstag, 1. April 2004 15:38
An: ***@t-systems.com; axis-***@ws.apache.org
Betreff: Re: AW: AW: MessageContext.getCurrentContext() returns null


OK, forgive my stupidity, but I am trying to send an attachment back
from the server. I did say that I was trying to send the attachment
back in the response in my original message but, I probably should
have
been clearer. That would also explain why I was confused about your
orginal response.

Anyway, I have attempted to model my service after the attachments
example included in the Axis distribution. On the server side, I get
null for the message context (which seems impossible to me). Any
ideas?

Thanks.
Tony
oService is your Service or your locator (both are Service or extend
Service!)
--> read my text and think about! ;)

Forget the MessageContext - you can t make

MessageContext context = MessageContext.get....

if you use the stub and the skeleton!
I get also null from MessageContext


-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Donnerstag, 1. April 2004 14:38
An: ***@t-systems.com; axis-***@ws.apache.org
Betreff: Re: AW: MessageContext.getCurrentContext() returns null


In your examples, what is "soapService" and "oService"?

Is it possible that my service is not deployed correctly and that is
why the current message context is null?

Thanks.
Tony
You can handle your attachment like this - without using the
MessageContext

Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart) attachments[0];
AttachmentPart attachPart1 = (AttachmentPart) attachments[1];

DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();

File myFile1 = new File("C:\\temp\\" + attachPart.getContentId() +
".gif");
FileOutputStream myFOS1 = new FileOutputStream(myFile1);
arrow.writeTo(myFOS1);

....

Another solution can be - take your Service or Locator (also Service)
and get the AxisEngine --> then make
engine.getCurrentMessageContext()!?

AxisEngine engine = oService.getEngine();
engine.getCurrentMessageContext();

Thomas

-----Ursprüngliche Nachricht-----
Von: Tony Thompson [mailto:***@stone-ware.com]
Gesendet: Mittwoch, 31. März 2004 15:51
An: axis-***@ws.apache.org
Betreff: MessageContext.getCurrentContext() returns null


When I invoke MessageContext.getCurrentContext(), it returns null.
Can
anyone explain why that might happen and how I can fix it? I am
trying
to add a DIME attachment to a response and it is hard to do without a
MessageContext.

Thanks.
Tony
Glen Daniels
2004-04-01 15:24:28 UTC
Permalink
Post by Tony Thompson
So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?
It returns null if there isn't a current MessageContext.

When are you calling it? If you're calling it outside the context of an
active invocation, you won't get anything because there is no "current"
MessageContext. If you're on the client side and you've already returned
from the call.invoke() or the stub method call, you won't get anything. The
correct thing to do in those cases is to use call.getMessageContext() or
locator.getCall().getMessageContext(), both of which return the last MC
which was used, even though the interaction is technically over.

--Glen
Jeff
2004-04-01 15:44:37 UTC
Permalink
I'll try this again...

You need activation.jar and mail.jar in the class path.

Yet another class path issue...it'll be the death of Java...I hope...perhaps
J3SE can solve it before we move on to something better!


Jeff


----- Original Message -----
From: "Tony Thompson" <***@stone-ware.com>
To: <***@t-systems.com>; <axis-***@ws.apache.org>
Sent: Thursday, April 01, 2004 10:07 AM
Subject: Re: AW: AW: AW: MessageContext.getCurrentContext() returnsnull
Post by Tony Thompson
OK, this looks pretty much like what I am doing but, this line throws a
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?
Tony
**********************
Server
**********************
public java.lang.String getFileAsAttachment(java.lang.String
XMLRequest) throws java.rmi.RemoteException {
String fileName =
"C:\\WebService\\webapps\\xxx\\arrow.gif";
String fileName1 =
"C:\\WebService\\webapps\\xxx\\folder.gif";
//explicitly set format to DIME, default is MIME
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachme
Post by Tony Thompson
nts.SEND_TYPE_DIME);
DataHandler dh = new DataHandler(new
FileDataSource(fileName));
if (dh == null ) System.err.println("dhSource is
null");
DataHandler dh1 = new DataHandler(new
FileDataSource(fileName1));
if (dh1 == null ) System.err.println("dhSource is
null");
AttachmentPart ap = new AttachmentPart(dh);
AttachmentPart ap1 = new AttachmentPart(dh1);
ap.setContentId("Filename1");
ap1.setContentId("Filename2");
MessageContext
context=MessageContext.getCurrentContext();
Message responseMessage=context.getResponseMessage();
responseMessage.addAttachmentPart(ap);
responseMessage.addAttachmentPart(ap1);
return XMLRequest;
}
******************
Client
********************
String doc =
soapService.getFileAsAttachment(xml);
Object[] attachments =
soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart)
attachments[0];
AttachmentPart attachPart1 = (AttachmentPart)
attachments[1];
DataHandler arrow =
attachPart.getDataHandler();
DataHandler folder =
attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" +
attachPart.getContentId() + ".gif");
FileOutputStream myFOS1 = new
FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
File myFile2 = new File("C:\\temp\\" +
attachPart1.getContentId() + ".gif");
FileOutputStream myFOS2 = new
FileOutputStream(myFile2);
folder.writeTo(myFOS2);
System.out.println(attachPart1.getContentId());
Tomi
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 15:38
Betreff: Re: AW: AW: MessageContext.getCurrentContext() returns null
OK, forgive my stupidity, but I am trying to send an attachment back
from the server. I did say that I was trying to send the attachment
back in the response in my original message but, I probably should
have
been clearer. That would also explain why I was confused about your
orginal response.
Anyway, I have attempted to model my service after the attachments
example included in the Axis distribution. On the server side, I get
null for the message context (which seems impossible to me). Any
ideas?
Thanks.
Tony
oService is your Service or your locator (both are Service or extend
Service!)
--> read my text and think about! ;)
Forget the MessageContext - you can t make
MessageContext context = MessageContext.get....
if you use the stub and the skeleton!
I get also null from MessageContext
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 14:38
Betreff: Re: AW: MessageContext.getCurrentContext() returns null
In your examples, what is "soapService" and "oService"?
Is it possible that my service is not deployed correctly and that is
why the current message context is null?
Thanks.
Tony
You can handle your attachment like this - without using the
MessageContext
Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart) attachments[0];
AttachmentPart attachPart1 = (AttachmentPart) attachments[1];
DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" + attachPart.getContentId() +
".gif");
FileOutputStream myFOS1 = new FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
....
Another solution can be - take your Service or Locator (also Service)
and get the AxisEngine --> then make
engine.getCurrentMessageContext()!?
AxisEngine engine = oService.getEngine();
engine.getCurrentMessageContext();
Thomas
-----Ursprüngliche Nachricht-----
Gesendet: Mittwoch, 31. März 2004 15:51
Betreff: MessageContext.getCurrentContext() returns null
When I invoke MessageContext.getCurrentContext(), it returns null.
Can
anyone explain why that might happen and how I can fix it? I am
trying
to add a DIME attachment to a response and it is hard to do without a
MessageContext.
Thanks.
Tony
Tony Thompson
2004-04-01 16:03:45 UTC
Permalink
I am calling it during an active invocation on the server side (not sure
how you would call it outside of an active invocation there?). I
basically have a method in my service like this:

public String getFile( String ) {
// NullPointerException thrown here because
AxisEngine.getCurrentMessageContext() is null.
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();

// File attachment code here.

return someString;
}

Shouldn't there be an active invocation context in this case?

Thanks.
Tony
Post by Tony Thompson
So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?
It returns null if there isn't a current MessageContext.

When are you calling it? If you're calling it outside the context of
an
active invocation, you won't get anything because there is no
"current"
MessageContext. If you're on the client side and you've already
returned
from the call.invoke() or the stub method call, you won't get anything.
The
correct thing to do in those cases is to use call.getMessageContext()
or
locator.getCall().getMessageContext(), both of which return the last
MC
which was used, even though the interaction is technically over.

--Glen
Glen Daniels
2004-04-01 16:37:22 UTC
Permalink
Post by Tony Thompson
I am calling it during an active invocation on the server side (not sure
how you would call it outside of an active invocation there?). I
public String getFile( String ) {
// NullPointerException thrown here because
AxisEngine.getCurrentMessageContext() is null.
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
// File attachment code here.
return someString;
}
Shouldn't there be an active invocation context in this case?
Yes, there definitely should. I would try starting with a fresh "framework"
service that has no code in it, confirm that you are in fact getting valid
MessageContexts:

public class MyService {
public void checkMC() {
MessageContext mc = MessageContext.getCurrentContext();
// Should not be null
System.out.println("Got MessageContext : " + mc);
}
}

and then progressively build up pieces to your service until you see the
problem. You didn't spawn off another thread, by any chance, did you? That
would cause the behaviour you're seeing, since the active MC is kept in
thread-local storage....

--Glen
Tony Thompson
2004-04-01 16:05:15 UTC
Permalink
They are in the classpath.
I'll try this again...

You need activation.jar and mail.jar in the class path.

Yet another class path issue...it'll be the death of Java...I
hope...perhaps
J3SE can solve it before we move on to something better!


Jeff


----- Original Message -----
From: "Tony Thompson" <***@stone-ware.com>
To: <***@t-systems.com>; <axis-***@ws.apache.org>
Sent: Thursday, April 01, 2004 10:07 AM
Subject: Re: AW: AW: AW: MessageContext.getCurrentContext()
returnsnull
Post by Tony Thompson
OK, this looks pretty much like what I am doing but, this line throws
a
Post by Tony Thompson
NullPointerException because getCurrentMessageContext() returns
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?
Tony
**********************
Server
**********************
public java.lang.String getFileAsAttachment(java.lang.String
XMLRequest) throws java.rmi.RemoteException {
String fileName =
"C:\\WebService\\webapps\\xxx\\arrow.gif";
String fileName1 =
"C:\\WebService\\webapps\\xxx\\folder.gif";
//explicitly set format to DIME, default is MIME
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachme
Post by Tony Thompson
nts.SEND_TYPE_DIME);
DataHandler dh = new DataHandler(new
FileDataSource(fileName));
if (dh == null ) System.err.println("dhSource is
null");
DataHandler dh1 = new DataHandler(new
FileDataSource(fileName1));
if (dh1 == null ) System.err.println("dhSource is
null");
AttachmentPart ap = new AttachmentPart(dh);
AttachmentPart ap1 = new AttachmentPart(dh1);
ap.setContentId("Filename1");
ap1.setContentId("Filename2");
MessageContext
context=MessageContext.getCurrentContext();
Message responseMessage=context.getResponseMessage();
responseMessage.addAttachmentPart(ap);
responseMessage.addAttachmentPart(ap1);
return XMLRequest;
}
******************
Client
********************
String doc =
soapService.getFileAsAttachment(xml);
Object[] attachments =
soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart)
attachments[0];
AttachmentPart attachPart1 = (AttachmentPart)
attachments[1];
DataHandler arrow =
attachPart.getDataHandler();
DataHandler folder =
attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" +
attachPart.getContentId() + ".gif");
FileOutputStream myFOS1 = new
FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
File myFile2 = new File("C:\\temp\\" +
attachPart1.getContentId() + ".gif");
FileOutputStream myFOS2 = new
FileOutputStream(myFile2);
folder.writeTo(myFOS2);
System.out.println(attachPart1.getContentId());
Tomi
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 15:38
Betreff: Re: AW: AW: MessageContext.getCurrentContext() returns null
OK, forgive my stupidity, but I am trying to send an attachment back
from the server. I did say that I was trying to send the attachment
back in the response in my original message but, I probably should
have
been clearer. That would also explain why I was confused about your
orginal response.
Anyway, I have attempted to model my service after the attachments
example included in the Axis distribution. On the server side, I
get
Post by Tony Thompson
null for the message context (which seems impossible to me). Any
ideas?
Thanks.
Tony
oService is your Service or your locator (both are Service or extend
Service!)
--> read my text and think about! ;)
Forget the MessageContext - you can t make
MessageContext context = MessageContext.get....
if you use the stub and the skeleton!
I get also null from MessageContext
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 14:38
Betreff: Re: AW: MessageContext.getCurrentContext() returns null
In your examples, what is "soapService" and "oService"?
Is it possible that my service is not deployed correctly and that is
why the current message context is null?
Thanks.
Tony
You can handle your attachment like this - without using the
MessageContext
Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart) attachments[0];
AttachmentPart attachPart1 = (AttachmentPart) attachments[1];
DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" + attachPart.getContentId() +
".gif");
FileOutputStream myFOS1 = new FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
....
Another solution can be - take your Service or Locator (also
Service)
Post by Tony Thompson
and get the AxisEngine --> then make
engine.getCurrentMessageContext()!?
AxisEngine engine = oService.getEngine();
engine.getCurrentMessageContext();
Thomas
-----Ursprüngliche Nachricht-----
Gesendet: Mittwoch, 31. März 2004 15:51
Betreff: MessageContext.getCurrentContext() returns null
When I invoke MessageContext.getCurrentContext(), it returns null.
Can
anyone explain why that might happen and how I can fix it? I am
trying
to add a DIME attachment to a response and it is hard to do without
a
Post by Tony Thompson
MessageContext.
Thanks.
Tony
Tony Thompson
2004-04-01 17:26:29 UTC
Permalink
OK, but that got me thinking a bit more and now it works (and yes it was
my fault, D'oh!). It came down to a classloader (another thing add to
the list of things to fix) issue. Axis is running in a web application
on my web server, of course, in its own classloader. The Axis JARs were
in the WEB-INF/lib directory. But, my service class was only available
in its parent classloader. Unfortunately, the Axis JARs were also
accessible by the parent classloader. So, the parent classloader had no
context for Axis because Axis is actually running in the web app
classloader. Once the JARs were only accessible by one classloader, I
get a real message context back.

Sorry to have bugged everyone. Thanks for the help!
Tony
I'll try this again...

You need activation.jar and mail.jar in the class path.

Yet another class path issue...it'll be the death of Java...I
hope...perhaps
J3SE can solve it before we move on to something better!


Jeff


----- Original Message -----
From: "Tony Thompson" <***@stone-ware.com>
To: <***@t-systems.com>; <axis-***@ws.apache.org>
Sent: Thursday, April 01, 2004 10:07 AM
Subject: Re: AW: AW: AW: MessageContext.getCurrentContext()
returnsnull
Post by Tony Thompson
OK, this looks pretty much like what I am doing but, this line throws
a
Post by Tony Thompson
NullPointerException because getCurrentMessageContext() returns
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
So, I am back to my original question. Why does
AxisEngine.getCurrentMessageContext() return null?
Tony
**********************
Server
**********************
public java.lang.String getFileAsAttachment(java.lang.String
XMLRequest) throws java.rmi.RemoteException {
String fileName =
"C:\\WebService\\webapps\\xxx\\arrow.gif";
String fileName1 =
"C:\\WebService\\webapps\\xxx\\folder.gif";
//explicitly set format to DIME, default is MIME
Message rspmsg =
AxisEngine.getCurrentMessageContext().getResponseMessage();
rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachme
Post by Tony Thompson
nts.SEND_TYPE_DIME);
DataHandler dh = new DataHandler(new
FileDataSource(fileName));
if (dh == null ) System.err.println("dhSource is
null");
DataHandler dh1 = new DataHandler(new
FileDataSource(fileName1));
if (dh1 == null ) System.err.println("dhSource is
null");
AttachmentPart ap = new AttachmentPart(dh);
AttachmentPart ap1 = new AttachmentPart(dh1);
ap.setContentId("Filename1");
ap1.setContentId("Filename2");
MessageContext
context=MessageContext.getCurrentContext();
Message responseMessage=context.getResponseMessage();
responseMessage.addAttachmentPart(ap);
responseMessage.addAttachmentPart(ap1);
return XMLRequest;
}
******************
Client
********************
String doc =
soapService.getFileAsAttachment(xml);
Object[] attachments =
soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart)
attachments[0];
AttachmentPart attachPart1 = (AttachmentPart)
attachments[1];
DataHandler arrow =
attachPart.getDataHandler();
DataHandler folder =
attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" +
attachPart.getContentId() + ".gif");
FileOutputStream myFOS1 = new
FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
File myFile2 = new File("C:\\temp\\" +
attachPart1.getContentId() + ".gif");
FileOutputStream myFOS2 = new
FileOutputStream(myFile2);
folder.writeTo(myFOS2);
System.out.println(attachPart1.getContentId());
Tomi
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 15:38
Betreff: Re: AW: AW: MessageContext.getCurrentContext() returns null
OK, forgive my stupidity, but I am trying to send an attachment back
from the server. I did say that I was trying to send the attachment
back in the response in my original message but, I probably should
have
been clearer. That would also explain why I was confused about your
orginal response.
Anyway, I have attempted to model my service after the attachments
example included in the Axis distribution. On the server side, I
get
Post by Tony Thompson
null for the message context (which seems impossible to me). Any
ideas?
Thanks.
Tony
oService is your Service or your locator (both are Service or extend
Service!)
--> read my text and think about! ;)
Forget the MessageContext - you can t make
MessageContext context = MessageContext.get....
if you use the stub and the skeleton!
I get also null from MessageContext
-----Ursprüngliche Nachricht-----
Gesendet: Donnerstag, 1. April 2004 14:38
Betreff: Re: AW: MessageContext.getCurrentContext() returns null
In your examples, what is "soapService" and "oService"?
Is it possible that my service is not deployed correctly and that is
why the current message context is null?
Thanks.
Tony
You can handle your attachment like this - without using the
MessageContext
Object[] attachments = soapService.getAttachments();
AttachmentPart attachPart = (AttachmentPart) attachments[0];
AttachmentPart attachPart1 = (AttachmentPart) attachments[1];
DataHandler arrow = attachPart.getDataHandler();
DataHandler folder = attachPart1.getDataHandler();
File myFile1 = new File("C:\\temp\\" + attachPart.getContentId() +
".gif");
FileOutputStream myFOS1 = new FileOutputStream(myFile1);
arrow.writeTo(myFOS1);
....
Another solution can be - take your Service or Locator (also
Service)
Post by Tony Thompson
and get the AxisEngine --> then make
engine.getCurrentMessageContext()!?
AxisEngine engine = oService.getEngine();
engine.getCurrentMessageContext();
Thomas
-----Ursprüngliche Nachricht-----
Gesendet: Mittwoch, 31. März 2004 15:51
Betreff: MessageContext.getCurrentContext() returns null
When I invoke MessageContext.getCurrentContext(), it returns null.
Can
anyone explain why that might happen and how I can fix it? I am
trying
to add a DIME attachment to a response and it is hard to do without
a
Post by Tony Thompson
MessageContext.
Thanks.
Tony
d***@iwon.com
2004-04-02 08:54:56 UTC
Permalink
Hi,
sorry this is a newbie question. I wanted to get the source
code from Thomas Dorner to work(sending a gif file as an
attachment back to the caller of a web service). But I'm stuck
with the client code. I did the following

0. Ran Java2WSDL on AXIS_HOME%/samples/userguide/example6. This
created my wsdl file.

1. Ran WSDL2Java to create the java classes. Added Thomas's source code to the %AXIS_HOME%/samples/userguide/example6/ WidgetPriceSoapBindingImpl.java file.

2. Deployed the webservice.

3. I can run the Main test program, no errors. I ran the
test program with tcpmon and the response does seems to contain the gif file attachment. Now I want to read the attachment.

How can I get the attachment?

Object[] attachments = binding.getAttachments();
Where do I define/get this getAttachments() api?

Any help greatly appreciated.

-dwong

_______________________________________________
Loading...