RE: communication between the Handler and the Service

2005-04-26 Thread Jeff Saremi
I think I'm getting a better understanding of the
problem. here' what i found so far:

- this problem is very much similar to what was
reported (and probably not fixed comprehensively) in
http://issues.apache.org/jira/browse/AXIS-283

- what XMLUtils produces and what SerializationContext
outputs are completely different. SC does not output
any changes that are in the memory!
Compare the following pieces after some modification
to one of the nodes in the body:
 // this one shows all my changes
  System.out.println(
  XMLUtils.ElementToString(env.getBody()));

 // however this one does not -- why?
 // this is very frustrating
  SerializationContext serContext = new
SerializationContext(new PrintWriter(System.out),
messageContext);
  serContext.setSendDecl(true);
  serContext.setEncoding("UTF-8");
  body.output(serContext);


Is this a bug? how can we report it if so?
thanks
jeff




 --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> ashutosh, 
> thanks for taking the time to reply.
> I tried the test code and the resolution you had
> posted but it did not make any difference.
> 
> Then i went on to try the sample code you had and
> realized that i don't get the problem that was
> posted
> as a bug. I didn't even need to call
> setSOAPEnvelope()
> method. May be the issue is gone away in 1.2RC3.
> 
> However my problem still persists. My issue is that
> i
> don't want to add a new element to the body but
> rather
> i'd like to modify an existing one. See the code
> below. None of the saveChanges() or
> setSOAPEnvelope()
> or other method calls can make the modified body
> persist beyon the scope of the invoke() method in
> the
> handler:
> 
> public void invoke(MessageContext context) {
>   ...
>   Node someNode =   
>  
> body.getElementsByTagName("MyNodeName").item(0);
> 
>   someNode.appendChild(
> 
>   body.getOwnerDocument().createTextNode(
>   "someTextForMyNode"));
>   // print the body now
>   // the oputput includes the new text node
>  
> System.out.println(XMLUtils.ElementToString(body));
> 
>   // the body shows the modification correctly here
>   // however after the message is forwarded to the
> service
>   // you can no longer see the changes
> 
> 
> 
> 
> 
>  --- "Shahi, Ashutosh" <[EMAIL PROTECTED]>
> wrote: 
> > Jeff,
> >  I haven't gone through the entire discussion,
> > but the problem might
> > be linked to
> > http://issues.apache.org/jira/browse/AXIS-1469
> > See if it helps.
> > 
> > Thanks,
> > Ashutosh
> > 
> > -Original Message-
> > From: Jeff Saremi [mailto:[EMAIL PROTECTED] 
> > Sent: Monday, April 25, 2005 8:47 PM
> > To: axis-user@ws.apache.org
> > Subject: Re: communication between the Handler and
> > the Service
> > 
> > It did not make any difference. or I don't how
> when
> > and  where to call it. I called saveChanges()
> after
> > the modifications to the body but the Service
> still
> > printed the old body xml.
> > jeff
> > 
> > 
> > 
> >  --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> > > I think I used that one too. But let me give it
> > > another  try and get back to you.
> > > jeff
> > > 
> > > 
> > > 
> > > 
> > >  --- Jeff Greif <[EMAIL PROTECTED]>
> > wrote:
> > > 
> > > > Have you noticed the method saveChanges on
> > > > SOAPMessage?
> > > > Jeff
> > > > 
> > > > Jeff Saremi wrote:
> > > > 
> > > > >So i played more with this and here's what i
> > > found
> > > > >out:
> > > > >- In the handler, the changes to the message,
> > > > envelope
> > > > >and body will all get saved and passed to the
> > > > Service
> > > > >afterwards
> > > > >- Any chnages to the nodes inside the body
> are
> > > > allowed
> > > > >to be made and displayed while in the handler
> > but
> > > > >beyond that none of those changes make it!
> > > > >
> > > > >** some where in the handler **
> > > > >public void invoke(MessageContext context) {
> > > > >  ...
> > > > >  Node someNode =  
> > > >
> > >body.getElementsByTagName("MyNodeName").item(0);   
> > > 
> > > > >someNode.appendChild(
> > > >
> > >
> >
>
>body.getOwnerDocument().createTextNode(&qu

RE: communication between the Handler and the Service

2005-04-26 Thread Jeff Saremi
ashutosh, 
thanks for taking the time to reply.
I tried the test code and the resolution you had
posted but it did not make any difference.

Then i went on to try the sample code you had and
realized that i don't get the problem that was posted
as a bug. I didn't even need to call setSOAPEnvelope()
method. May be the issue is gone away in 1.2RC3.

However my problem still persists. My issue is that i
don't want to add a new element to the body but rather
i'd like to modify an existing one. See the code
below. None of the saveChanges() or setSOAPEnvelope()
or other method calls can make the modified body
persist beyon the scope of the invoke() method in the
handler:

public void invoke(MessageContext context) {
  ...
  Node someNode =   
  body.getElementsByTagName("MyNodeName").item(0);

  someNode.appendChild(

  body.getOwnerDocument().createTextNode(
  "someTextForMyNode"));
  // print the body now
  // the oputput includes the new text node
  System.out.println(XMLUtils.ElementToString(body));

  // the body shows the modification correctly here
  // however after the message is forwarded to the
service
  // you can no longer see the changes





 --- "Shahi, Ashutosh" <[EMAIL PROTECTED]> wrote: 
> Jeff,
>  I haven't gone through the entire discussion,
> but the problem might
> be linked to
> http://issues.apache.org/jira/browse/AXIS-1469
> See if it helps.
> 
> Thanks,
> Ashutosh
> 
> -Original Message-
> From: Jeff Saremi [mailto:[EMAIL PROTECTED] 
> Sent: Monday, April 25, 2005 8:47 PM
> To: axis-user@ws.apache.org
> Subject: Re: communication between the Handler and
> the Service
> 
> It did not make any difference. or I don't how when
> and  where to call it. I called saveChanges() after
> the modifications to the body but the Service still
> printed the old body xml.
> jeff
> 
> 
> 
>  --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> > I think I used that one too. But let me give it
> > another  try and get back to you.
> > jeff
> > 
> > 
> > 
> > 
> >  --- Jeff Greif <[EMAIL PROTECTED]>
> wrote:
> > 
> > > Have you noticed the method saveChanges on
> > > SOAPMessage?
> > > Jeff
> > > 
> > > Jeff Saremi wrote:
> > > 
> > > >So i played more with this and here's what i
> > found
> > > >out:
> > > >- In the handler, the changes to the message,
> > > envelope
> > > >and body will all get saved and passed to the
> > > Service
> > > >afterwards
> > > >- Any chnages to the nodes inside the body are
> > > allowed
> > > >to be made and displayed while in the handler
> but
> > > >beyond that none of those changes make it!
> > > >
> > > >** some where in the handler **
> > > >public void invoke(MessageContext context) {
> > > >  ...
> > > >  Node someNode =  
> > >
> >body.getElementsByTagName("MyNodeName").item(0); 
> > 
> > > >someNode.appendChild(
> > >
> >
>
>body.getOwnerDocument().createTextNode("someTextForMyNode"));
> > > >  // print the body now
> > > >  // the oputput will include the new text node
> > > > 
> > >
> >
> System.out.println(XMLUtils.ElementToString(body));
> > > >
> > > >  // out of desperation you can do the
> following
> > > >  // which should not be needed
> > > >  // but they won't help you with the new Node
> > > >  // being added to the body and hence being
> > passed
> > > >  // to your Service down the chain
> > > >  envelope.removeBody();
> > > >  envelope.setBody(body);
> > > >  Message newMessage = new Message(envelope);
> > > >  messageContext.setRequestMessage(newMessage);
> > > >
> > > >}
> > > >
> > > >** some time later inside the Service  **
> > > >public Element[] service(Element[] elements) {
> > > >  for (int i = 0; i < elements.length; i++) { 
> > > >// print the elements to your hearts
> content
> > > >// you will not see any traces of the
> > textnode
> > > >// you added in your handler
> > > >// all you see is the original elements 
> > > >System.out.println(
> > > >  XMLUtils.ElementToString(elements[i]));
> > > >  }
> > > >  return elements;
> > > >}
> > > >
> > > >jeff
> > > &

RE: communication between the Handler and the Service

2005-04-25 Thread Shahi, Ashutosh
Jeff,
 I haven't gone through the entire discussion, but the problem might
be linked to http://issues.apache.org/jira/browse/AXIS-1469
See if it helps.

Thanks,
Ashutosh

-Original Message-
From: Jeff Saremi [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 25, 2005 8:47 PM
To: axis-user@ws.apache.org
Subject: Re: communication between the Handler and the Service

It did not make any difference. or I don't how when
and  where to call it. I called saveChanges() after
the modifications to the body but the Service still
printed the old body xml.
jeff



 --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> I think I used that one too. But let me give it
> another  try and get back to you.
> jeff
> 
> 
> 
> 
>  --- Jeff Greif <[EMAIL PROTECTED]> wrote:
> 
> > Have you noticed the method saveChanges on
> > SOAPMessage?
> > Jeff
> > 
> > Jeff Saremi wrote:
> > 
> > >So i played more with this and here's what i
> found
> > >out:
> > >- In the handler, the changes to the message,
> > envelope
> > >and body will all get saved and passed to the
> > Service
> > >afterwards
> > >- Any chnages to the nodes inside the body are
> > allowed
> > >to be made and displayed while in the handler but
> > >beyond that none of those changes make it!
> > >
> > >** some where in the handler **
> > >public void invoke(MessageContext context) {
> > >  ...
> > >  Node someNode =  
> > >body.getElementsByTagName("MyNodeName").item(0);   
> 
> > >someNode.appendChild(
> >
>
>body.getOwnerDocument().createTextNode("someTextForMyNode"));
> > >  // print the body now
> > >  // the oputput will include the new text node
> > > 
> >
> System.out.println(XMLUtils.ElementToString(body));
> > >
> > >  // out of desperation you can do the following
> > >  // which should not be needed
> > >  // but they won't help you with the new Node
> > >  // being added to the body and hence being
> passed
> > >  // to your Service down the chain
> > >  envelope.removeBody();
> > >  envelope.setBody(body);
> > >  Message newMessage = new Message(envelope);
> > >  messageContext.setRequestMessage(newMessage);
> > >
> > >}
> > >
> > >** some time later inside the Service  **
> > >public Element[] service(Element[] elements) {
> > >  for (int i = 0; i < elements.length; i++) { 
> > >// print the elements to your hearts content
> > >// you will not see any traces of the
> textnode
> > >// you added in your handler
> > >// all you see is the original elements 
> > >System.out.println(
> > >  XMLUtils.ElementToString(elements[i]));
> > >  }
> > >  return elements;
> > >}
> > >
> > >jeff
> > >
> > > --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> > >  
> > >
> > >>I should have explained more about what i'm
> doing.
> > I
> > >>don't know where this processRequest() method
> is.
> > It
> > >>looks like there are two or more Handler
> concepts
> > >>within Axis. The Handler that i'm talking about
> > are
> > >>the ones you specify in the "requestFlow" or
> > >>"responseFlow" chains:
> > >>
> > >>  
> > >> value="MyService"
> > />
> > >> > value="service"
> > >>/>
> > >>
> > >>  
> > >> 
> > >>  
> > >>
> > >>Here's the method that MyHandler overrides. The
> > code
> > >>below is just to point out the problem -- this
> is
> > >>not
> > >>how i'm planning on writing my final code:
> > >>
> > >>public class WARPHandler extends BasicHandler {
> > >>public void invoke(MessageContext context)
> throws
> > >>AxisFault {
> > >>  try {
> > >>  Message message = context.getRequestMessage();
> > >>  SOAPEnvelope envelope =
> > message.getSOAPEnvelope();
> > >>  SOAPBody body = envelope.getBody();
> > >>  // do some modification to the elements in the
> > >>body
> > >>  // ...
> > >>  System.out.println(
> > >>"Is Body referenced? " + 
> > >>(body ==
> context.getMessage().getSOAPBody()

Re: communication between the Handler and the Service

2005-04-25 Thread Jeff Saremi
It did not make any difference. or I don't how when
and  where to call it. I called saveChanges() after
the modifications to the body but the Service still
printed the old body xml.
jeff



 --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> I think I used that one too. But let me give it
> another  try and get back to you.
> jeff
> 
> 
> 
> 
>  --- Jeff Greif <[EMAIL PROTECTED]> wrote:
> 
> > Have you noticed the method saveChanges on
> > SOAPMessage?
> > Jeff
> > 
> > Jeff Saremi wrote:
> > 
> > >So i played more with this and here's what i
> found
> > >out:
> > >- In the handler, the changes to the message,
> > envelope
> > >and body will all get saved and passed to the
> > Service
> > >afterwards
> > >- Any chnages to the nodes inside the body are
> > allowed
> > >to be made and displayed while in the handler but
> > >beyond that none of those changes make it!
> > >
> > >** some where in the handler **
> > >public void invoke(MessageContext context) {
> > >  ...
> > >  Node someNode =  
> > >body.getElementsByTagName("MyNodeName").item(0);   
> 
> > >someNode.appendChild(
> >
>
>body.getOwnerDocument().createTextNode("someTextForMyNode"));
> > >  // print the body now
> > >  // the oputput will include the new text node
> > > 
> >
> System.out.println(XMLUtils.ElementToString(body));
> > >
> > >  // out of desperation you can do the following
> > >  // which should not be needed
> > >  // but they won't help you with the new Node
> > >  // being added to the body and hence being
> passed
> > >  // to your Service down the chain
> > >  envelope.removeBody();
> > >  envelope.setBody(body);
> > >  Message newMessage = new Message(envelope);
> > >  messageContext.setRequestMessage(newMessage);
> > >
> > >}
> > >
> > >** some time later inside the Service  **
> > >public Element[] service(Element[] elements) {
> > >  for (int i = 0; i < elements.length; i++) { 
> > >// print the elements to your hearts content
> > >// you will not see any traces of the
> textnode
> > >// you added in your handler
> > >// all you see is the original elements 
> > >System.out.println(
> > >  XMLUtils.ElementToString(elements[i]));
> > >  }
> > >  return elements;
> > >}
> > >
> > >jeff
> > >
> > > --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> > >  
> > >
> > >>I should have explained more about what i'm
> doing.
> > I
> > >>don't know where this processRequest() method
> is.
> > It
> > >>looks like there are two or more Handler
> concepts
> > >>within Axis. The Handler that i'm talking about
> > are
> > >>the ones you specify in the "requestFlow" or
> > >>"responseFlow" chains:
> > >>
> > >>  
> > >> value="MyService"
> > />
> > >> > value="service"
> > >>/>
> > >>
> > >>  
> > >> 
> > >>  
> > >>
> > >>Here's the method that MyHandler overrides. The
> > code
> > >>below is just to point out the problem -- this
> is
> > >>not
> > >>how i'm planning on writing my final code:
> > >>
> > >>public class WARPHandler extends BasicHandler {
> > >>public void invoke(MessageContext context)
> throws
> > >>AxisFault {
> > >>  try {
> > >>  Message message = context.getRequestMessage();
> > >>  SOAPEnvelope envelope =
> > message.getSOAPEnvelope();
> > >>  SOAPBody body = envelope.getBody();
> > >>  // do some modification to the elements in the
> > >>body
> > >>  // ...
> > >>  System.out.println(
> > >>"Is Body referenced? " + 
> > >>(body ==
> context.getMessage().getSOAPBody()));
> > >>  MyService.bodyElementInHandler =
> > >>body.getFirstChild();
> > >>  } catch (Exception e) {
> > >>e.printStackTrace();
> > >>AxisFault.makeFault(e);
> > >>  }
> > >>}
> > >>}
> > >>
> > >>And the Service gets the Body document or
> elements
> > >>or
> > >>the SOAPEnvelope after the Handler is done with
> > it:
> > >>
> > >>public class MyService {
> > >>  public static Object bodyElementInHandler;
> > >>  public Document service(Document bodyElement)
> {
> > >>// the bodyElement here has none of the
> > changes
> > >>// that were made to it in the Handler!
> > >>System.out.println(
> > >>  "bodies are not the same: " + 
> > >>  (bodyElementInHandler == bodyElement));
> > >>return bodyElement;
> > >>  }
> > >>}
> > >>
> > >>In the invoke() method of the Handler i tried to
> > >>show
> > >>that the Body that I got is not a copy of what
> is
> > in
> > >>the Message and ultimately in the
> MessageContext.
> > It
> > >>is just a refernce to it. Therefore
> modifications
> > to
> > >>this Body or its subelements need not be set
> again
> > >>in
> > >>the Message. However, regardless of it being a
> > copy
> > >>or
> > >>a reference I also set the CurrentMessage of
> > >>MessageContext to a new Message (i have not
> shown
> > >>this
> > >>part of the code here).
> > >>Then I set a static variable in my Service just
> > for
> > >>the sake of comparison.
> > >>In the service() method of MyService I compare
> the
> > >>passed document to the reference set by the
> > Handler.
> > 

Re: communication between the Handler and the Service

2005-04-25 Thread Jeff Saremi
I think I used that one too. But let me give it
another  try and get back to you.
jeff




 --- Jeff Greif <[EMAIL PROTECTED]> wrote: 
> Have you noticed the method saveChanges on
> SOAPMessage?
> Jeff
> 
> Jeff Saremi wrote:
> 
> >So i played more with this and here's what i found
> >out:
> >- In the handler, the changes to the message,
> envelope
> >and body will all get saved and passed to the
> Service
> >afterwards
> >- Any chnages to the nodes inside the body are
> allowed
> >to be made and displayed while in the handler but
> >beyond that none of those changes make it!
> >
> >** some where in the handler **
> >public void invoke(MessageContext context) {
> >  ...
> >  Node someNode =  
> >body.getElementsByTagName("MyNodeName").item(0);  
> >someNode.appendChild(
>
>body.getOwnerDocument().createTextNode("someTextForMyNode"));
> >  // print the body now
> >  // the oputput will include the new text node
> > 
> System.out.println(XMLUtils.ElementToString(body));
> >
> >  // out of desperation you can do the following
> >  // which should not be needed
> >  // but they won't help you with the new Node
> >  // being added to the body and hence being passed
> >  // to your Service down the chain
> >  envelope.removeBody();
> >  envelope.setBody(body);
> >  Message newMessage = new Message(envelope);
> >  messageContext.setRequestMessage(newMessage);
> >
> >}
> >
> >** some time later inside the Service  **
> >public Element[] service(Element[] elements) {
> >  for (int i = 0; i < elements.length; i++) { 
> >// print the elements to your hearts content
> >// you will not see any traces of the textnode
> >// you added in your handler
> >// all you see is the original elements 
> >System.out.println(
> >  XMLUtils.ElementToString(elements[i]));
> >  }
> >  return elements;
> >}
> >
> >jeff
> >
> > --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> >  
> >
> >>I should have explained more about what i'm doing.
> I
> >>don't know where this processRequest() method is.
> It
> >>looks like there are two or more Handler concepts
> >>within Axis. The Handler that i'm talking about
> are
> >>the ones you specify in the "requestFlow" or
> >>"responseFlow" chains:
> >>
> >>  
> >> />
> >> value="service"
> >>/>
> >>
> >>  
> >> 
> >>  
> >>
> >>Here's the method that MyHandler overrides. The
> code
> >>below is just to point out the problem -- this is
> >>not
> >>how i'm planning on writing my final code:
> >>
> >>public class WARPHandler extends BasicHandler {
> >>public void invoke(MessageContext context) throws
> >>AxisFault {
> >>  try {
> >>  Message message = context.getRequestMessage();
> >>  SOAPEnvelope envelope =
> message.getSOAPEnvelope();
> >>  SOAPBody body = envelope.getBody();
> >>  // do some modification to the elements in the
> >>body
> >>  // ...
> >>  System.out.println(
> >>"Is Body referenced? " + 
> >>(body == context.getMessage().getSOAPBody()));
> >>  MyService.bodyElementInHandler =
> >>body.getFirstChild();
> >>  } catch (Exception e) {
> >>e.printStackTrace();
> >>AxisFault.makeFault(e);
> >>  }
> >>}
> >>}
> >>
> >>And the Service gets the Body document or elements
> >>or
> >>the SOAPEnvelope after the Handler is done with
> it:
> >>
> >>public class MyService {
> >>  public static Object bodyElementInHandler;
> >>  public Document service(Document bodyElement) {
> >>// the bodyElement here has none of the
> changes
> >>// that were made to it in the Handler!
> >>System.out.println(
> >>  "bodies are not the same: " + 
> >>  (bodyElementInHandler == bodyElement));
> >>return bodyElement;
> >>  }
> >>}
> >>
> >>In the invoke() method of the Handler i tried to
> >>show
> >>that the Body that I got is not a copy of what is
> in
> >>the Message and ultimately in the MessageContext.
> It
> >>is just a refernce to it. Therefore modifications
> to
> >>this Body or its subelements need not be set again
> >>in
> >>the Message. However, regardless of it being a
> copy
> >>or
> >>a reference I also set the CurrentMessage of
> >>MessageContext to a new Message (i have not shown
> >>this
> >>part of the code here).
> >>Then I set a static variable in my Service just
> for
> >>the sake of comparison.
> >>In the service() method of MyService I compare the
> >>passed document to the reference set by the
> Handler.
> >>These two objects, even though they display the
> same
> >>XML structure are not the same. the body that was
> >>passed to the service() method is the old version
> of
> >>the body in the SOAPEnvelope. And this is what
> >>frustrates me beyond reason.
> >>
> >>I'd appreciate if someone could explain why this
> is
> >>happenning.
> >>thanks
> >>
> >>
> >>
> >>--- Jeff Greif <[EMAIL PROTECTED]>
> wrote:
> >>
> >>
> >>>This pattern (for one of the jax-rpc handler
> >>>methods) guarantees that no 
> >>>matter what copying takes place, your changes
> will
> >>>register.  If your 
> >>>handler decides to do 

Re: communication between the Handler and the Service

2005-04-25 Thread Jeff Greif
Have you noticed the method saveChanges on SOAPMessage?
Jeff
Jeff Saremi wrote:
So i played more with this and here's what i found
out:
- In the handler, the changes to the message, envelope
and body will all get saved and passed to the Service
afterwards
- Any chnages to the nodes inside the body are allowed
to be made and displayed while in the handler but
beyond that none of those changes make it!
** some where in the handler **
public void invoke(MessageContext context) {
 ...
 Node someNode =  
body.getElementsByTagName("MyNodeName").item(0);	 
someNode.appendChild(
body.getOwnerDocument().createTextNode("someTextForMyNode"));
 // print the body now
 // the oputput will include the new text node
 System.out.println(XMLUtils.ElementToString(body));

 // out of desperation you can do the following
 // which should not be needed
 // but they won't help you with the new Node
 // being added to the body and hence being passed
 // to your Service down the chain
 envelope.removeBody();
 envelope.setBody(body);
 Message newMessage = new Message(envelope);
 messageContext.setRequestMessage(newMessage);
}
** some time later inside the Service  **
public Element[] service(Element[] elements) {
 for (int i = 0; i < elements.length; i++) { 
   // print the elements to your hearts content
   // you will not see any traces of the textnode
   // you added in your handler
   // all you see is the original elements 
   System.out.println(
 XMLUtils.ElementToString(elements[i]));
 }
 return elements;
}

jeff
--- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
 

I should have explained more about what i'm doing. I
don't know where this processRequest() method is. It
looks like there are two or more Handler concepts
within Axis. The Handler that i'm talking about are
the ones you specify in the "requestFlow" or
"responseFlow" chains:
 
   
   
   
 

 
Here's the method that MyHandler overrides. The code
below is just to point out the problem -- this is
not
how i'm planning on writing my final code:
public class WARPHandler extends BasicHandler {
public void invoke(MessageContext context) throws
AxisFault {
 try {
 Message message = context.getRequestMessage();
 SOAPEnvelope envelope = message.getSOAPEnvelope();
 SOAPBody body = envelope.getBody();
 // do some modification to the elements in the
body
 // ...
 System.out.println(
   "Is Body referenced? " + 
   (body == context.getMessage().getSOAPBody()));
 MyService.bodyElementInHandler =
body.getFirstChild();
 } catch (Exception e) {
   e.printStackTrace();
   AxisFault.makeFault(e);
 }
}
}

And the Service gets the Body document or elements
or
the SOAPEnvelope after the Handler is done with it:
public class MyService {
 public static Object bodyElementInHandler;
 public Document service(Document bodyElement) {
   // the bodyElement here has none of the changes
   // that were made to it in the Handler!
   System.out.println(
 "bodies are not the same: " + 
 (bodyElementInHandler == bodyElement));
   return bodyElement;
 }
}

In the invoke() method of the Handler i tried to
show
that the Body that I got is not a copy of what is in
the Message and ultimately in the MessageContext. It
is just a refernce to it. Therefore modifications to
this Body or its subelements need not be set again
in
the Message. However, regardless of it being a copy
or
a reference I also set the CurrentMessage of
MessageContext to a new Message (i have not shown
this
part of the code here).
Then I set a static variable in my Service just for
the sake of comparison.
In the service() method of MyService I compare the
passed document to the reference set by the Handler.
These two objects, even though they display the same
XML structure are not the same. the body that was
passed to the service() method is the old version of
the body in the SOAPEnvelope. And this is what
frustrates me beyond reason.
I'd appreciate if someone could explain why this is
happenning.
thanks

--- Jeff Greif <[EMAIL PROTECTED]> wrote:
   

This pattern (for one of the jax-rpc handler
methods) guarantees that no 
matter what copying takes place, your changes will
register.  If your 
handler decides to do nothing with the message,
return null from 
whatever you implement for processRequest.  In
general it seems that 
items retrieved from MessageContext objects are
copies, and must be set 
back into the context after modification.  This
applies to properties 
and perhaps other things as well.

   public boolean handleRequest(MessageContext
context) {
   SOAPMessageContext soapContext =
(SOAPMessageContext) context;
   SOAPMessage message =
soapContext.getMessage();
   SOAPMessage result =
processRequest(message);
   if (result != null) {
   soapContext.setMessage(result);
}
   return true;
   }
Jeff
Jeff Saremi wrote:
 

Either there is something i'm not getting or my
   

whole
 

code/configuration is wrong.
I'd like to intercept a request

Re: communication between the Handler and the Service

2005-04-25 Thread Jeff Saremi
So i played more with this and here's what i found
out:
- In the handler, the changes to the message, envelope
and body will all get saved and passed to the Service
afterwards
- Any chnages to the nodes inside the body are allowed
to be made and displayed while in the handler but
beyond that none of those changes make it!

** some where in the handler **
public void invoke(MessageContext context) {
  ...
  Node someNode =  
body.getElementsByTagName("MyNodeName").item(0); 
someNode.appendChild(
body.getOwnerDocument().createTextNode("someTextForMyNode"));
  // print the body now
  // the oputput will include the new text node
  System.out.println(XMLUtils.ElementToString(body));

  // out of desperation you can do the following
  // which should not be needed
  // but they won't help you with the new Node
  // being added to the body and hence being passed
  // to your Service down the chain
  envelope.removeBody();
  envelope.setBody(body);
  Message newMessage = new Message(envelope);
  messageContext.setRequestMessage(newMessage);

}

** some time later inside the Service  **
public Element[] service(Element[] elements) {
  for (int i = 0; i < elements.length; i++) { 
// print the elements to your hearts content
// you will not see any traces of the textnode
// you added in your handler
// all you see is the original elements 
System.out.println(
  XMLUtils.ElementToString(elements[i]));
  }
  return elements;
}

jeff

 --- Jeff Saremi <[EMAIL PROTECTED]> wrote: 
> I should have explained more about what i'm doing. I
> don't know where this processRequest() method is. It
> looks like there are two or more Handler concepts
> within Axis. The Handler that i'm talking about are
> the ones you specify in the "requestFlow" or
> "responseFlow" chains:
> 
>   
> 
>  />
> 
>   
>  
>   
> 
> Here's the method that MyHandler overrides. The code
> below is just to point out the problem -- this is
> not
> how i'm planning on writing my final code:
> 
> public class WARPHandler extends BasicHandler {
> public void invoke(MessageContext context) throws
> AxisFault {
>   try {
>   Message message = context.getRequestMessage();
>   SOAPEnvelope envelope = message.getSOAPEnvelope();
>   SOAPBody body = envelope.getBody();
>   // do some modification to the elements in the
> body
>   // ...
>   System.out.println(
> "Is Body referenced? " + 
> (body == context.getMessage().getSOAPBody()));
>   MyService.bodyElementInHandler =
> body.getFirstChild();
>   } catch (Exception e) {
> e.printStackTrace();
> AxisFault.makeFault(e);
>   }
> }
> }
> 
> And the Service gets the Body document or elements
> or
> the SOAPEnvelope after the Handler is done with it:
> 
> public class MyService {
>   public static Object bodyElementInHandler;
>   public Document service(Document bodyElement) {
> // the bodyElement here has none of the changes
> // that were made to it in the Handler!
> System.out.println(
>   "bodies are not the same: " + 
>   (bodyElementInHandler == bodyElement));
> return bodyElement;
>   }
> }
> 
> In the invoke() method of the Handler i tried to
> show
> that the Body that I got is not a copy of what is in
> the Message and ultimately in the MessageContext. It
> is just a refernce to it. Therefore modifications to
> this Body or its subelements need not be set again
> in
> the Message. However, regardless of it being a copy
> or
> a reference I also set the CurrentMessage of
> MessageContext to a new Message (i have not shown
> this
> part of the code here).
> Then I set a static variable in my Service just for
> the sake of comparison.
> In the service() method of MyService I compare the
> passed document to the reference set by the Handler.
> These two objects, even though they display the same
> XML structure are not the same. the body that was
> passed to the service() method is the old version of
> the body in the SOAPEnvelope. And this is what
> frustrates me beyond reason.
> 
> I'd appreciate if someone could explain why this is
> happenning.
> thanks
> 
> 
> 
> --- Jeff Greif <[EMAIL PROTECTED]> wrote:
> > This pattern (for one of the jax-rpc handler
> > methods) guarantees that no 
> > matter what copying takes place, your changes will
> > register.  If your 
> > handler decides to do nothing with the message,
> > return null from 
> > whatever you implement for processRequest.  In
> > general it seems that 
> > items retrieved from MessageContext objects are
> > copies, and must be set 
> > back into the context after modification.  This
> > applies to properties 
> > and perhaps other things as well.
> > 
> > public boolean handleRequest(MessageContext
> > context) {
> >  
> > SOAPMessageContext soapContext =
> > (SOAPMessageContext) context;
> > SOAPMessage message =
> > soapContext.getMessage();
> > SOAPMessage result =
> > processRequest(message);
> > if (res

Re: communication between the Handler and the Service

2005-04-24 Thread Jeff Saremi
I should have explained more about what i'm doing. I
don't know where this processRequest() method is. It
looks like there are two or more Handler concepts
within Axis. The Handler that i'm talking about are
the ones you specify in the "requestFlow" or
"responseFlow" chains:

  



  
 
  

Here's the method that MyHandler overrides. The code
below is just to point out the problem -- this is not
how i'm planning on writing my final code:

public class WARPHandler extends BasicHandler {
public void invoke(MessageContext context) throws
AxisFault {
  try {
  Message message = context.getRequestMessage();
  SOAPEnvelope envelope = message.getSOAPEnvelope();
  SOAPBody body = envelope.getBody();
  // do some modification to the elements in the body
  // ...
  System.out.println(
"Is Body referenced? " + 
(body == context.getMessage().getSOAPBody()));
  MyService.bodyElementInHandler =
body.getFirstChild();
  } catch (Exception e) {
e.printStackTrace();
AxisFault.makeFault(e);
  }
}
}

And the Service gets the Body document or elements or
the SOAPEnvelope after the Handler is done with it:

public class MyService {
  public static Object bodyElementInHandler;
  public Document service(Document bodyElement) {
// the bodyElement here has none of the changes
// that were made to it in the Handler!
System.out.println(
  "bodies are not the same: " + 
  (bodyElementInHandler == bodyElement));
return bodyElement;
  }
}

In the invoke() method of the Handler i tried to show
that the Body that I got is not a copy of what is in
the Message and ultimately in the MessageContext. It
is just a refernce to it. Therefore modifications to
this Body or its subelements need not be set again in
the Message. However, regardless of it being a copy or
a reference I also set the CurrentMessage of
MessageContext to a new Message (i have not shown this
part of the code here).
Then I set a static variable in my Service just for
the sake of comparison.
In the service() method of MyService I compare the
passed document to the reference set by the Handler.
These two objects, even though they display the same
XML structure are not the same. the body that was
passed to the service() method is the old version of
the body in the SOAPEnvelope. And this is what
frustrates me beyond reason.

I'd appreciate if someone could explain why this is
happenning.
thanks



--- Jeff Greif <[EMAIL PROTECTED]> wrote:
> This pattern (for one of the jax-rpc handler
> methods) guarantees that no 
> matter what copying takes place, your changes will
> register.  If your 
> handler decides to do nothing with the message,
> return null from 
> whatever you implement for processRequest.  In
> general it seems that 
> items retrieved from MessageContext objects are
> copies, and must be set 
> back into the context after modification.  This
> applies to properties 
> and perhaps other things as well.
> 
> public boolean handleRequest(MessageContext
> context) {
>  
> SOAPMessageContext soapContext =
> (SOAPMessageContext) context;
> SOAPMessage message =
> soapContext.getMessage();
> SOAPMessage result =
> processRequest(message);
> if (result != null) {
> soapContext.setMessage(result);
>  }
> return true;
> }
> 
> Jeff
> 
> 
> Jeff Saremi wrote:
> 
> >Either there is something i'm not getting or my
> whole
> >code/configuration is wrong.
> >
> >I'd like to intercept a request using a handler,
> >change something in that request and then let my
> >service deal with these changes. However, I cannot
> >this simple, intuitive concept to work! I have
> spent
> >over two full days playing with different objects
> and
> >different template methods in my service (a message
> >service) all to no avail.
> >
> >What i'd like to do is get the XML for the body of
> the
> >incoming request in my handler, change some values
> in
> >it, and then let my message service deal with the
> >modified body. But after extensive testing I
> realized
> >that the Body that is passed to my Service and the
> one
> >i modified in my Handler are completely different!
> >It's as if Axis makes a copy of the incoming
> request,
> >before its modified by my Handler and passes that
> old
> >copy to my Service.
> >
> >Is this true? If not please let me know and i will
> >send you some more code and configuration for you
> guys
> >to examine.
> >
> >thanks,
> >jeff
> >
> >
> >  
> >
> 
> 


Re: communication between the Handler and the Service

2005-04-23 Thread Jeff Greif
This pattern (for one of the jax-rpc handler methods) guarantees that no 
matter what copying takes place, your changes will register.  If your 
handler decides to do nothing with the message, return null from 
whatever you implement for processRequest.  In general it seems that 
items retrieved from MessageContext objects are copies, and must be set 
back into the context after modification.  This applies to properties 
and perhaps other things as well.

   public boolean handleRequest(MessageContext context) {
   SOAPMessageContext soapContext = (SOAPMessageContext) context;
   SOAPMessage message = soapContext.getMessage();
   SOAPMessage result = processRequest(message);
   if (result != null) {
   soapContext.setMessage(result);
}
   return true;
   }
Jeff
Jeff Saremi wrote:
Either there is something i'm not getting or my whole
code/configuration is wrong.
I'd like to intercept a request using a handler,
change something in that request and then let my
service deal with these changes. However, I cannot
this simple, intuitive concept to work! I have spent
over two full days playing with different objects and
different template methods in my service (a message
service) all to no avail.
What i'd like to do is get the XML for the body of the
incoming request in my handler, change some values in
it, and then let my message service deal with the
modified body. But after extensive testing I realized
that the Body that is passed to my Service and the one
i modified in my Handler are completely different!
It's as if Axis makes a copy of the incoming request,
before its modified by my Handler and passes that old
copy to my Service.
Is this true? If not please let me know and i will
send you some more code and configuration for you guys
to examine.
thanks,
jeff
 




communication between the Handler and the Service

2005-04-23 Thread Jeff Saremi
Either there is something i'm not getting or my whole
code/configuration is wrong.

I'd like to intercept a request using a handler,
change something in that request and then let my
service deal with these changes. However, I cannot
this simple, intuitive concept to work! I have spent
over two full days playing with different objects and
different template methods in my service (a message
service) all to no avail.

What i'd like to do is get the XML for the body of the
incoming request in my handler, change some values in
it, and then let my message service deal with the
modified body. But after extensive testing I realized
that the Body that is passed to my Service and the one
i modified in my Handler are completely different!
It's as if Axis makes a copy of the incoming request,
before its modified by my Handler and passes that old
copy to my Service.

Is this true? If not please let me know and i will
send you some more code and configuration for you guys
to examine.

thanks,
jeff