Re: passing a flag from impl method to interceptor
On Monday 03 March 2008, Daniel Lipofsky wrote: > So I added a header on the server side using the code below, > I can see the header in client side logging, but how do I > grab it on the client side? I tried an interceptor but it is > not finding any headers. What am I doing wrong? READ phase is propably too early. They probably haven't been read yet. Change the phase to USER_LOGICAL. That said, on the client side, like the server side, you don't need the interceptor. ((BindingProvider)proxy).getResponseContext().get(Header.HEADER_LIST); should return the List objects. One more note though: header elements SHOULD be namespace qualfied per the soap spec. You aren't putting the overflow element into a namespace when you create it so many toolkits may have issues with that. Use the createElementNS call. Dan > > Server side code: > > Document d = DOMUtils.createDocument(); > Element overflowElem = d.createElement("overflow"); > overflowElem.setTextContent(String.valueOf(overflow)); > QName q = new QName(SCHEMA_PREFIX + "headers_ns.xsd", > "OverflowHeader", "h"); > SoapHeader overflowHeader = new SoapHeader(q, overflowElem); > ... > List headers = CastUtils.cast((List) > messageContext.get(Header.HEADER_LIST)); > ... > headers.add(overflowHeader); > > > Client side logging shows: > > http://schemas.xmlsoap.org/soap/envelope/";> > false > ... > > Client side code: > > class HeaderInterceptor extends AbstractSoapInterceptor { > > public HeaderInterceptor() { > super(Phase.READ); > } > > public void handleMessage(SoapMessage message) throws Fault { > List headers = message.getHeaders(); > if(headers.size() == 0) { > log.info("HEADER.size = 0"); > return; > } > for (int i = 0; i < headers.size(); i++) { > log.info("HEADER " + i + ": " + headers.get(i).getName()); > } > } > } > > Thanks, > Dan > > > -Original Message- > > From: Daniel Lipofsky [mailto:[EMAIL PROTECTED] > > Sent: Friday, February 29, 2008 1:23 PM > > To: cxf-user@incubator.apache.org > > Subject: RE: passing a flag from impl method to interceptor > > > > Those all sound good, but unfortunately I am pretty much > > a web-services newbie, I don't have a clue how to > > implement that, especially the @WebParam sugestion. > > Do I need some entries in the WSDL, etc? > > > > the old implementation was basically outputing this: > > > > > xmlns:h="http://www.foobar.com/connector-1.5/headers_ns.xsd";> > > > > false > > > > ... > > > > or > > ... > > true > > ... > > > > so there are a few involved: a namespace, a node, and > > an attribute. I don't have to keep it the same, so maybe > > I can make it a lot simplier, I just need to basically > > communicate overflow=[true|false] somehow. > > > > Thanks, > > Dan > > > > On Friday 29 February 2008, Daniel Kulp wrote: > > > Of course, I typed all that and forgot the most obvious way: > > > > > > Just add a parameter to your method like: > > > > > > @WebParam(header = true, mode = Mode.OUT) > > > Holder header > > > > > > Dan > > > > > > On Friday 29 February 2008, Daniel Kulp wrote: > > > > OK. This is turning into another FAQ type thing that > > > > > > possibly needs > > > > > > > a sample > > > > > > > > There are a couple options open to you: > > > > > > > > First, you need the context injected in: > > > > @Resource > > > > WebServiceContext context; > > > > > > > > 1) Standard JAX-WS API's: throw the value in the > > > > WebServiceContext > > > > > > and in a SoapHandler, use it to modify the SAAJ object > > > > model. This > > > > > > is pure JAXWS and would work on any JAX-WS implementation. The > > > > "problem" is that with the SAAJ model, it breaks streaming and > > > > performance suffers. > > > > > > > > 2) context + CXF interceptor: again, from your impl, throw > > > > > > a value in > > > > > > > the WebServiceContext and then grab that from the message in > > > > your interceptor. You can then call the > > &
RE: passing a flag from impl method to interceptor
So I added a header on the server side using the code below, I can see the header in client side logging, but how do I grab it on the client side? I tried an interceptor but it is not finding any headers. What am I doing wrong? Server side code: Document d = DOMUtils.createDocument(); Element overflowElem = d.createElement("overflow"); overflowElem.setTextContent(String.valueOf(overflow)); QName q = new QName(SCHEMA_PREFIX + "headers_ns.xsd", "OverflowHeader", "h"); SoapHeader overflowHeader = new SoapHeader(q, overflowElem); ... List headers = CastUtils.cast((List) messageContext.get(Header.HEADER_LIST)); ... headers.add(overflowHeader); Client side logging shows: http://schemas.xmlsoap.org/soap/envelope/";> false ... Client side code: class HeaderInterceptor extends AbstractSoapInterceptor { public HeaderInterceptor() { super(Phase.READ); } public void handleMessage(SoapMessage message) throws Fault { List headers = message.getHeaders(); if(headers.size() == 0) { log.info("HEADER.size = 0"); return; } for (int i = 0; i < headers.size(); i++) { log.info("HEADER " + i + ": " + headers.get(i).getName()); } } } Thanks, Dan > -Original Message- > From: Daniel Lipofsky [mailto:[EMAIL PROTECTED] > Sent: Friday, February 29, 2008 1:23 PM > To: cxf-user@incubator.apache.org > Subject: RE: passing a flag from impl method to interceptor > > Those all sound good, but unfortunately I am pretty much > a web-services newbie, I don't have a clue how to > implement that, especially the @WebParam sugestion. > Do I need some entries in the WSDL, etc? > > the old implementation was basically outputing this: > > xmlns:h="http://www.foobar.com/connector-1.5/headers_ns.xsd";> > > false > > ... > > or > ... > true > ... > > so there are a few involved: a namespace, a node, and > an attribute. I don't have to keep it the same, so maybe > I can make it a lot simplier, I just need to basically > communicate overflow=[true|false] somehow. > > Thanks, > Dan > > On Friday 29 February 2008, Daniel Kulp wrote: > > > > Of course, I typed all that and forgot the most obvious way: > > > > Just add a parameter to your method like: > > > > @WebParam(header = true, mode = Mode.OUT) > > Holder header > > > > Dan > > > > > > > > On Friday 29 February 2008, Daniel Kulp wrote: > > > OK. This is turning into another FAQ type thing that > > possibly needs > > > a sample > > > > > > There are a couple options open to you: > > > > > > First, you need the context injected in: > > > @Resource > > > WebServiceContext context; > > > > > > 1) Standard JAX-WS API's: throw the value in the > WebServiceContext > > > and in a SoapHandler, use it to modify the SAAJ object > model. This > > > is pure JAXWS and would work on any JAX-WS implementation. The > > > "problem" is that with the SAAJ model, it breaks streaming and > > > performance suffers. > > > > > > 2) context + CXF interceptor: again, from your impl, throw > > a value in > > > the WebServiceContext and then grab that from the message in your > > > interceptor. You can then call the > > soapMessage.getHeaders() thing to > > > get the list of headers and add a Header object to it. > > > > > > 3) Context only: no interceptors needed. In you impl do: > > > > > > context. > > > ... build a org.apache.cxf.headers.Header object ... > > > List hdrList = (List)ctx.get(Header.HEADER_LIST)); > > > hdrList.add(hdr); > > > > > > And example of this would be our system test that test this: > > > > > > http://svn.apache.org/repos/asf/incubator/cxf/trunk/systests/src/test/ > > >java/org/apache/cxf/systest/outofband/header/ > > > > > > > > > 3 is definitely the simplest. No interceptors needed. Nothing > > > really to configure, etc > > > > > > > > > Dan > > > > > > On Friday 29 February 2008, Daniel Lipofsky wrote: > > > > I have a csae where I want to set something in the SOAP > > > > response header based on what happened in the execution of > > > > the method implementation. > > > > > > > > I suppose I want to extend AbstractSoapInterceptor, but what > > > > I can't figure out is how to pass a flag from the method > > > > to the interceptor. I thought about sticking it in the > > > > ServletRequest attribute map but I don't see a way to access > > > > that from the interceptor. Any way to do it would be fine. > > > > > > > > also is there an example of adding an element to a SOAP header? > > > > > > > > Thanks, > > > > Dan >
Re: passing a flag from impl method to interceptor
On Friday 29 February 2008, Daniel Lipofsky wrote: > Those all sound good, but unfortunately I am pretty much > a web-services newbie, I don't have a clue how to > implement that, especially the @WebParam sugestion. > Do I need some entries in the WSDL, etc? If you want to define it in the wsdl, you would create a new schema element like: Then to your out message, just add another part like: And then in your soap binding for the output: You can see the wsdl in our samples/soap_header dir as an example. Dan > > the old implementation was basically outputing this: > > xmlns:h="http://www.foobar.com/connector-1.5/headers_ns.xsd";> > > false > > ... > > or > ... > true > ... > > so there are a few involved: a namespace, a node, and > an attribute. I don't have to keep it the same, so maybe > I can make it a lot simplier, I just need to basically > communicate overflow=[true|false] somehow. > > Thanks, > Dan > > On Friday 29 February 2008, Daniel Kulp wrote: > > Of course, I typed all that and forgot the most obvious way: > > > > Just add a parameter to your method like: > > > > @WebParam(header = true, mode = Mode.OUT) > > Holder header > > > > Dan > > > > On Friday 29 February 2008, Daniel Kulp wrote: > > > OK. This is turning into another FAQ type thing that > > > > possibly needs > > > > > a sample > > > > > > There are a couple options open to you: > > > > > > First, you need the context injected in: > > > @Resource > > > WebServiceContext context; > > > > > > 1) Standard JAX-WS API's: throw the value in the > > > WebServiceContext and in a SoapHandler, use it to modify the SAAJ > > > object model. This is pure JAXWS and would work on any JAX-WS > > > implementation. The "problem" is that with the SAAJ model, it > > > breaks streaming and performance suffers. > > > > > > 2) context + CXF interceptor: again, from your impl, throw > > > > a value in > > > > > the WebServiceContext and then grab that from the message in your > > > interceptor. You can then call the > > > > soapMessage.getHeaders() thing to > > > > > get the list of headers and add a Header object to it. > > > > > > 3) Context only: no interceptors needed. In you impl do: > > > > > > context. > > > ... build a org.apache.cxf.headers.Header object ... > > > List hdrList = (List)ctx.get(Header.HEADER_LIST)); > > > hdrList.add(hdr); > > > > > > And example of this would be our system test that test this: > > > > http://svn.apache.org/repos/asf/incubator/cxf/trunk/systests/src/tes > >t/ > > > > >java/org/apache/cxf/systest/outofband/header/ > > > > > > > > > 3 is definitely the simplest. No interceptors needed. Nothing > > > really to configure, etc > > > > > > > > > Dan > > > > > > On Friday 29 February 2008, Daniel Lipofsky wrote: > > > > I have a csae where I want to set something in the SOAP > > > > response header based on what happened in the execution of > > > > the method implementation. > > > > > > > > I suppose I want to extend AbstractSoapInterceptor, but what > > > > I can't figure out is how to pass a flag from the method > > > > to the interceptor. I thought about sticking it in the > > > > ServletRequest attribute map but I don't see a way to access > > > > that from the interceptor. Any way to do it would be fine. > > > > > > > > also is there an example of adding an element to a SOAP header? > > > > > > > > Thanks, > > > > Dan -- J. Daniel Kulp Principal Engineer, IONA [EMAIL PROTECTED] http://www.dankulp.com/blog
RE: passing a flag from impl method to interceptor
Those all sound good, but unfortunately I am pretty much a web-services newbie, I don't have a clue how to implement that, especially the @WebParam sugestion. Do I need some entries in the WSDL, etc? the old implementation was basically outputing this: http://www.foobar.com/connector-1.5/headers_ns.xsd";> false ... or ... true ... so there are a few involved: a namespace, a node, and an attribute. I don't have to keep it the same, so maybe I can make it a lot simplier, I just need to basically communicate overflow=[true|false] somehow. Thanks, Dan On Friday 29 February 2008, Daniel Kulp wrote: > > Of course, I typed all that and forgot the most obvious way: > > Just add a parameter to your method like: > > @WebParam(header = true, mode = Mode.OUT) > Holder header > > Dan > > > > On Friday 29 February 2008, Daniel Kulp wrote: > > OK. This is turning into another FAQ type thing that > possibly needs > > a sample > > > > There are a couple options open to you: > > > > First, you need the context injected in: > > @Resource > > WebServiceContext context; > > > > 1) Standard JAX-WS API's: throw the value in the WebServiceContext > > and in a SoapHandler, use it to modify the SAAJ object model. This > > is pure JAXWS and would work on any JAX-WS implementation. The > > "problem" is that with the SAAJ model, it breaks streaming and > > performance suffers. > > > > 2) context + CXF interceptor: again, from your impl, throw > a value in > > the WebServiceContext and then grab that from the message in your > > interceptor. You can then call the > soapMessage.getHeaders() thing to > > get the list of headers and add a Header object to it. > > > > 3) Context only: no interceptors needed. In you impl do: > > > > context. > > ... build a org.apache.cxf.headers.Header object ... > > List hdrList = (List)ctx.get(Header.HEADER_LIST)); > > hdrList.add(hdr); > > > > And example of this would be our system test that test this: > > > http://svn.apache.org/repos/asf/incubator/cxf/trunk/systests/src/test/ > >java/org/apache/cxf/systest/outofband/header/ > > > > > > 3 is definitely the simplest. No interceptors needed. Nothing > > really to configure, etc > > > > > > Dan > > > > On Friday 29 February 2008, Daniel Lipofsky wrote: > > > I have a csae where I want to set something in the SOAP > > > response header based on what happened in the execution of > > > the method implementation. > > > > > > I suppose I want to extend AbstractSoapInterceptor, but what > > > I can't figure out is how to pass a flag from the method > > > to the interceptor. I thought about sticking it in the > > > ServletRequest attribute map but I don't see a way to access > > > that from the interceptor. Any way to do it would be fine. > > > > > > also is there an example of adding an element to a SOAP header? > > > > > > Thanks, > > > Dan
Re: passing a flag from impl method to interceptor
Of course, I typed all that and forgot the most obvious way: Just add a parameter to your method like: @WebParam(header = true, mode = Mode.OUT) Holder header Dan On Friday 29 February 2008, Daniel Kulp wrote: > OK. This is turning into another FAQ type thing that possibly needs > a sample > > There are a couple options open to you: > > First, you need the context injected in: > @Resource > WebServiceContext context; > > 1) Standard JAX-WS API's: throw the value in the WebServiceContext > and in a SoapHandler, use it to modify the SAAJ object model. This > is pure JAXWS and would work on any JAX-WS implementation. The > "problem" is that with the SAAJ model, it breaks streaming and > performance suffers. > > 2) context + CXF interceptor: again, from your impl, throw a value in > the WebServiceContext and then grab that from the message in your > interceptor. You can then call the soapMessage.getHeaders() thing to > get the list of headers and add a Header object to it. > > 3) Context only: no interceptors needed. In you impl do: > > context. > ... build a org.apache.cxf.headers.Header object ... > List hdrList = (List)ctx.get(Header.HEADER_LIST)); > hdrList.add(hdr); > > And example of this would be our system test that test this: > http://svn.apache.org/repos/asf/incubator/cxf/trunk/systests/src/test/ >java/org/apache/cxf/systest/outofband/header/ > > > 3 is definitely the simplest. No interceptors needed. Nothing > really to configure, etc > > > Dan > > On Friday 29 February 2008, Daniel Lipofsky wrote: > > I have a csae where I want to set something in the SOAP > > response header based on what happened in the execution of > > the method implementation. > > > > I suppose I want to extend AbstractSoapInterceptor, but what > > I can't figure out is how to pass a flag from the method > > to the interceptor. I thought about sticking it in the > > ServletRequest attribute map but I don't see a way to access > > that from the interceptor. Any way to do it would be fine. > > > > also is there an example of adding an element to a SOAP header? > > > > Thanks, > > Dan -- J. Daniel Kulp Principal Engineer, IONA [EMAIL PROTECTED] http://www.dankulp.com/blog
Re: passing a flag from impl method to interceptor
OK. This is turning into another FAQ type thing that possibly needs a sample There are a couple options open to you: First, you need the context injected in: @Resource WebServiceContext context; 1) Standard JAX-WS API's: throw the value in the WebServiceContext and in a SoapHandler, use it to modify the SAAJ object model. This is pure JAXWS and would work on any JAX-WS implementation. The "problem" is that with the SAAJ model, it breaks streaming and performance suffers. 2) context + CXF interceptor: again, from your impl, throw a value in the WebServiceContext and then grab that from the message in your interceptor. You can then call the soapMessage.getHeaders() thing to get the list of headers and add a Header object to it. 3) Context only: no interceptors needed. In you impl do: context. ... build a org.apache.cxf.headers.Header object ... List hdrList = (List)ctx.get(Header.HEADER_LIST)); hdrList.add(hdr); And example of this would be our system test that test this: http://svn.apache.org/repos/asf/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/outofband/header/ 3 is definitely the simplest. No interceptors needed. Nothing really to configure, etc Dan On Friday 29 February 2008, Daniel Lipofsky wrote: > I have a csae where I want to set something in the SOAP > response header based on what happened in the execution of > the method implementation. > > I suppose I want to extend AbstractSoapInterceptor, but what > I can't figure out is how to pass a flag from the method > to the interceptor. I thought about sticking it in the > ServletRequest attribute map but I don't see a way to access > that from the interceptor. Any way to do it would be fine. > > also is there an example of adding an element to a SOAP header? > > Thanks, > Dan -- J. Daniel Kulp Principal Engineer, IONA [EMAIL PROTECTED] http://www.dankulp.com/blog