You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Tony Thompson <to...@stone-ware.com> on 2004/04/01 17:07:25 UTC

Re: AW: AW: AW: MessageContext.getCurrentContext() returns null

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

>>> Thomas.Dorner@t-systems.com 04/01/04 08:44AM >>>
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:tony.thompson@stone-ware.com] 
Gesendet: Donnerstag, 1. April 2004 15:38
An: Thomas.Dorner@t-systems.com; axis-user@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

>>> Thomas.Dorner@t-systems.com 04/01/04 07:45AM >>>

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:tony.thompson@stone-ware.com] 
Gesendet: Donnerstag, 1. April 2004 14:38
An: Thomas.Dorner@t-systems.com; axis-user@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

>>> Thomas.Dorner@t-systems.com 04/01/04 02:37AM >>>
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:tony.thompson@stone-ware.com] 
Gesendet: Mittwoch, 31. März 2004 15:51
An: axis-user@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

Re: AW: AW: AW: MessageContext.getCurrentContext() returnsnull

Posted by Glen Daniels <gl...@thoughtcraft.com>.
Hi Tony:

> 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

Re: AW: AW: AW: MessageContext.getCurrentContext() returnsnull

Posted by Jeff <je...@cogentlogic.com>.
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" <to...@stone-ware.com>
To: <Th...@t-systems.com>; <ax...@ws.apache.org>
Sent: Thursday, April 01, 2004 10:07 AM
Subject: Re: AW: AW: AW: MessageContext.getCurrentContext() returnsnull


> 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
>
> >>> Thomas.Dorner@t-systems.com 04/01/04 08:44AM >>>
> 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:tony.thompson@stone-ware.com]
> Gesendet: Donnerstag, 1. April 2004 15:38
> An: Thomas.Dorner@t-systems.com; axis-user@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
>
> >>> Thomas.Dorner@t-systems.com 04/01/04 07:45AM >>>
>
> 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:tony.thompson@stone-ware.com]
> Gesendet: Donnerstag, 1. April 2004 14:38
> An: Thomas.Dorner@t-systems.com; axis-user@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
>
> >>> Thomas.Dorner@t-systems.com 04/01/04 02:37AM >>>
> 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:tony.thompson@stone-ware.com]
> Gesendet: Mittwoch, 31. März 2004 15:51
> An: axis-user@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