You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by cstreiff <ch...@streiff.org> on 2010/05/25 13:50:30 UTC
response message soap header reading problem
Hi,
Summary:
Adding a header to a soap message using the WebServiceContext is working
fine. However, reading the header using the reverse procedure fails.
Environment:
CXF 2.2.7, OSX and GNU Linux
Problem Description:
1) I'm adding the Header:
...
List<Header> headers = new ArrayList<Header>();
Header cidHeader;
try {
cidHeader = new Header(CORRELATION_ID_ELEMENT, cid, new
JAXBDataBinding(String.class));
} catch (JAXBException e) {
throw new IllegalArgumentException("SOAP Header JAXB binding is
broken and needs to be fixed.", e);
}
headers.add(cidHeader);
ctx.put(Header.HEADER_LIST, headers); // WebServiceContext
...
2) and when I look at the service consumers logfile all seems to be OK. The
services response message contains the header:
2010-05-25 11:13:46,512 33093 INFO
[org.apache.cxf.interceptor.LoggingInInterceptor] (btpool0-3:) Inbound
Message
----------------------------
ID: 2evilcom
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml; charset=utf-8
Headers: {Content-Length=[403], Server=[Jetty(6.1.1rc1)],
content-type=[text/xml; charset=utf-8]}
Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><correlationId
xmlns="http://webservices.evilcom.com/header-v1">ff7818d7-60ab-40a2-b594-28515b1007f2</correlationId></soap:Header><soap:Body>....</soap:Body></soap:Envelope>
--------------------------------------
3) Now I'm trying to read the header and all I get is the (local) name of
the header element and a null value:
public CommonSoapHeader(Map<String, Object> requestMessageContext,
Map<String, Object> responseMessageContext) {
log.info("responseMessageContext=" + responseMessageContext);
List<Header> headers =
(List<Header>)responseMessageContext.get(Header.HEADER_LIST);
if(headers == null) { throw new NullPointerException("Unexpected
error: message context should have returned a header list."); }
for(Iterator<Header> i = headers.iterator(); i.hasNext();) {
Header h = i.next();
Element n = (Element)h.getObject();
log.info("lname="+n.getLocalName());
log.info("nv="+ n.getNodeValue());
}
}
getLocalName() yields the expected element name 'correlationId', however
'getNodeValue()' always yields 'null'.
4) It seems that I'm making a mistake along the way. Why am I always getting
a null value for my header element?
I would greatly appreciate a hint on where I went wrong.
chriss
--
View this message in context: http://old.nabble.com/response-message-soap-header-reading-problem-tp28667390p28667390.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: response message soap header reading problem
Posted by cstreiff <ch...@streiff.org>.
Hi Dan,
excellent, you're absolutely right! It worked just the way you said it
would.
Thank you very much for your answer and for saving me another sleepless
night.
chriss
Actually, I don't think it really is null. If you look at the log for the
line:
log.info("header="+hr.getObject());
you see:
(btpool0-4:) header=[correlationId: null]
That is actually how the Xerces DOM would look on a toString. The Xerces
toString impl is pathetic. I'm willing to be if you do:
Element el = (Element) hr.getObject();
String cid = el.getTextContent();
then the cid is there.
Dan
--
View this message in context: http://old.nabble.com/response-message-soap-header-reading-problem-tp28667390p28744374.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: response message soap header reading problem
Posted by Daniel Kulp <dk...@apache.org>.
Actually, I don't think it really is null. If you look at the log for the
line:
log.info("header="+hr.getObject());
you see:
(btpool0-4:) header=[correlationId: null]
That is actually how the Xerces DOM would look on a toString. The Xerces
toString impl is pathetic. I'm willing to be if you do:
Element el = (Element) hr.getObject();
String cid = el.getTextContent();
then the cid is there.
Dan
On Monday 31 May 2010 8:51:24 am cstreiff wrote:
> Glen,
>
> I'm now using interceptors, but the Problem persists. The name, ns, etc. of
> the soap header element is returned correctly, however I always get null
> for the elment value:
> hader=[correlationId: null]
> headerName={http://webservices.evilcom.com/header-v1}correlationId
>
> Does anyone have any idea where I'm going wrong. It must be a fairly
> fundamental mistake that I'm making, having changed to interceptors and
> still experiencing the same problem.
>
> Here is the response message on the wire with header and all:
>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Header>
> <correlationId
> xmlns="http://webservices.evilcom.com/header-v1">666</correlationId>
> </soap:Header>
> <soap:Body>
> <ns2:serviceResponse
> xmlns:ns2="http://evil.evilcom.com/schema/spr/v1_1/local">
> <serviceReturn>
> <code>ACK</code>
> </serviceReturn>
> </ns2:serviceResponse>
> </soap:Body>
> </soap:Envelope>
>
>
> The InInterceptor:
>
> public class SoapHeaderInInterceptor3 extends AbstractSoapInterceptor{
>
> public static final QName CORRELATION_ID_ELEMENT =
> new QName("http://webservices.evilcom.com/header-v1",
> "correlationId");
>
>
> public SoapHeaderInInterceptor3() {
> super(Phase.READ);
> addAfter(ReadHeadersInterceptor.class.getName());
> addAfter(EndpointSelectionInterceptor.class.getName());
>
> }
>
> final Logger log =
> LoggerFactory.getLogger(SoapHeaderInInterceptor3.class);
>
> public void handleMessage(SoapMessage message) throws Fault {
>
> List<Header> hl = message.getHeaders();
> for(Header hr : hl) {
> log.info("header="+hr.getObject());
> log.info("headerName="+hr.getName());
> }
> }
>
>
> The relevant logfile parts:
>
> 2010-05-31 14:42:33,991 114738 INFO
> [org.apache.cxf.interceptor.LoggingInInterceptor] (btpool0-4:) Inbound
> Message
> ----------------------------
> ID: 2
> Response-Code: 200
> Encoding: UTF-8
> Content-Type: text/xml; charset=utf-8
> Headers: {Content-Length=[370], Server=[Jetty(6.1.1rc1)],
> content-type=[text/xml; charset=utf-8]}
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><correl
> ationId
> xmlns="http://webservices.evilcom.com/header-v1">666</correlationId></soap
> :Header><soap:Body><ns2:serviceResponse
> xmlns:ns2="http://sptil.evilcom.com/schema/spr/v1_1/local"><serviceReturn>
> <code>ACK</code></serviceReturn></ns2:serviceResponse></soap:Body></soap:En
> velope> --------------------------------------
> 2010-05-31 14:42:33,992 114739 INFO
> [com.evilcom.aaa.mockserviceprofile.sprovider.SoapHeaderInInterceptor3]
> (btpool0-4:) header=[correlationId: null]
> 2010-05-31 14:42:33,992 114739 INFO
> [com.evilcom.aaa.mockserviceprofile.sprovider.SoapHeaderInInterceptor3]
> (btpool0-4:)
> headerName={http://webservices.evilcom.com/header-v1}correlationId
>
> chriss
>
> Glen Mazza wrote:
> > Hmmm...are you mixing up SOAP headers with HTTP headers--it seems you're
> > creating the former but trying to query the latter, that might be the
> > problem.
> >
> > If it helps with debugging, you can attach JAX-WS Handlers[1] (or CXF
> > interceptors[2]) to either the web service provider or the client and try
> > to read the SOAP (HTTP?) headers there. Wireshark[3] can also help in
> > making sure that what you're looking for is indeed on the wire.
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Re: response message soap header reading problem
Posted by cstreiff <ch...@streiff.org>.
Glen,
I'm now using interceptors, but the Problem persists. The name, ns, etc. of
the soap header element is returned correctly, however I always get null for
the elment value:
hader=[correlationId: null]
headerName={http://webservices.evilcom.com/header-v1}correlationId
Does anyone have any idea where I'm going wrong. It must be a fairly
fundamental mistake that I'm making, having changed to interceptors and
still experiencing the same problem.
Here is the response message on the wire with header and all:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<correlationId
xmlns="http://webservices.evilcom.com/header-v1">666</correlationId>
</soap:Header>
<soap:Body>
<ns2:serviceResponse
xmlns:ns2="http://evil.evilcom.com/schema/spr/v1_1/local">
<serviceReturn>
<code>ACK</code>
</serviceReturn>
</ns2:serviceResponse>
</soap:Body>
</soap:Envelope>
The InInterceptor:
public class SoapHeaderInInterceptor3 extends AbstractSoapInterceptor{
public static final QName CORRELATION_ID_ELEMENT =
new QName("http://webservices.evilcom.com/header-v1",
"correlationId");
public SoapHeaderInInterceptor3() {
super(Phase.READ);
addAfter(ReadHeadersInterceptor.class.getName());
addAfter(EndpointSelectionInterceptor.class.getName());
}
final Logger log = LoggerFactory.getLogger(SoapHeaderInInterceptor3.class);
public void handleMessage(SoapMessage message) throws Fault {
List<Header> hl = message.getHeaders();
for(Header hr : hl) {
log.info("header="+hr.getObject());
log.info("headerName="+hr.getName());
}
}
The relevant logfile parts:
2010-05-31 14:42:33,991 114738 INFO
[org.apache.cxf.interceptor.LoggingInInterceptor] (btpool0-4:) Inbound
Message
----------------------------
ID: 2
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml; charset=utf-8
Headers: {Content-Length=[370], Server=[Jetty(6.1.1rc1)],
content-type=[text/xml; charset=utf-8]}
Payload: <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><correlationId
xmlns="http://webservices.evilcom.com/header-v1">666</correlationId></soap:Header><soap:Body><ns2:serviceResponse
xmlns:ns2="http://sptil.evilcom.com/schema/spr/v1_1/local"><serviceReturn><code>ACK</code></serviceReturn></ns2:serviceResponse></soap:Body></soap:Envelope>
--------------------------------------
2010-05-31 14:42:33,992 114739 INFO
[com.evilcom.aaa.mockserviceprofile.sprovider.SoapHeaderInInterceptor3]
(btpool0-4:) header=[correlationId: null]
2010-05-31 14:42:33,992 114739 INFO
[com.evilcom.aaa.mockserviceprofile.sprovider.SoapHeaderInInterceptor3]
(btpool0-4:)
headerName={http://webservices.evilcom.com/header-v1}correlationId
chriss
Glen Mazza wrote:
>
> Hmmm...are you mixing up SOAP headers with HTTP headers--it seems you're
> creating the former but trying to query the latter, that might be the
> problem.
>
> If it helps with debugging, you can attach JAX-WS Handlers[1] (or CXF
> interceptors[2]) to either the web service provider or the client and try
> to read the SOAP (HTTP?) headers there. Wireshark[3] can also help in
> making sure that what you're looking for is indeed on the wire.
>
--
View this message in context: http://old.nabble.com/response-message-soap-header-reading-problem-tp28667390p28730617.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: response message soap header reading problem
Posted by cstreiff <ch...@streiff.org>.
Thanks for your reply Glen. I'll code up an interceptor as you suggested to
see what's going on. I looks all OK on the wire.
But I don't think that I'm reading the protocol header because
'responseMessageContext.get(Header.HEADER_LIST)' returns almost everything
one would expect: the correct localName of the element in the soap header
(correlationId), the correct namespace of the element
(http://webservices.evilcom.com/header-v1) etc., only when I get the value
of the said element do I get a null value.
chriss
Glen Mazza wrote:
>
> Hmmm...are you mixing up SOAP headers with HTTP headers--it seems you're
> creating the former but trying to query the latter, that might be the
> problem.
>
> If it helps with debugging, you can attach JAX-WS Handlers[1] (or CXF
> interceptors[2]) to either the web service provider or the client and try
> to read the SOAP (HTTP?) headers there. Wireshark[3] can also help in
> making sure that what you're looking for is indeed on the wire.
>
> HTH,
> Glen
>
> [1] http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial
> [2] http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors
> [3] http://www.jroller.com/gmazza/entry/soap_calls_over_wireshark
>
>
> cstreiff wrote:
>>
>> Hi,
>>
>> Summary:
>> Adding a header to a soap message using the WebServiceContext is working
>> fine. However, reading the header using the reverse procedure fails.
>>
>> Environment:
>> CXF 2.2.7, OSX and GNU Linux
>>
>> Problem Description:
>> 1) I'm adding the Header:
>> ...
>> List<Header> headers = new ArrayList<Header>();
>> Header cidHeader;
>> try {
>> cidHeader = new Header(CORRELATION_ID_ELEMENT, cid, new
>> JAXBDataBinding(String.class));
>> } catch (JAXBException e) {
>> throw new IllegalArgumentException("SOAP Header JAXB binding
>> is broken and needs to be fixed.", e);
>> }
>>
>> headers.add(cidHeader);
>> ctx.put(Header.HEADER_LIST, headers); // WebServiceContext
>> ...
>>
>>
>> 2) and when I look at the service consumers logfile all seems to be OK.
>> The services response message contains the header:
>>
>>
>> 2010-05-25 11:13:46,512 33093 INFO
>> [org.apache.cxf.interceptor.LoggingInInterceptor] (btpool0-3:) Inbound
>> Message
>> ----------------------------
>> ID: 2evilcom
>> Response-Code: 200
>> Encoding: UTF-8
>> Content-Type: text/xml; charset=utf-8
>> Headers: {Content-Length=[403], Server=[Jetty(6.1.1rc1)],
>> content-type=[text/xml; charset=utf-8]}
>> Payload: <soap:Envelope
>> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><correlationId
>> xmlns="http://webservices.evilcom.com/header-v1">ff7818d7-60ab-40a2-b594-28515b1007f2</correlationId></soap:Header><soap:Body>....</soap:Body></soap:Envelope>
>> --------------------------------------
>>
>> 3) Now I'm trying to read the header and all I get is the (local) name of
>> the header element and a null value:
>>
>> public CommonSoapHeader(Map<String, Object> requestMessageContext,
>> Map<String, Object> responseMessageContext) {
>> log.info("responseMessageContext=" + responseMessageContext);
>>
>> List<Header> headers =
>> (List<Header>)responseMessageContext.get(Header.HEADER_LIST);
>>
>> if(headers == null) { throw new NullPointerException("Unexpected
>> error: message context should have returned a header list."); }
>>
>> for(Iterator<Header> i = headers.iterator(); i.hasNext();) {
>> Header h = i.next();
>> Element n = (Element)h.getObject();
>>
>> log.info("lname="+n.getLocalName());
>> log.info("nv="+ n.getNodeValue());
>> }
>> }
>>
>>
>> getLocalName() yields the expected element name 'correlationId', however
>> 'getNodeValue()' always yields 'null'.
>>
>>
>> 4) It seems that I'm making a mistake along the way. Why am I always
>> getting a null value for my header element?
>> I would greatly appreciate a hint on where I went wrong.
>> chriss
>>
>>
>>
>>
>
>
--
View this message in context: http://old.nabble.com/response-message-soap-header-reading-problem-tp28667390p28680283.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: response message soap header reading problem
Posted by Glen Mazza <gl...@gmail.com>.
Hmmm...are you mixing up SOAP headers with HTTP headers--it seems you're
creating the former but trying to query the latter, that might be the
problem.
If it helps with debugging, you can attach JAX-WS Handlers[1] (or CXF
interceptors[2]) to either the web service provider or the client and try to
read the SOAP (HTTP?) headers there. Wireshark[3] can also help in making
sure that what you're looking for is indeed on the wire.
HTH,
Glen
[1] http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial
[2] http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors
[3] http://www.jroller.com/gmazza/entry/soap_calls_over_wireshark
cstreiff wrote:
>
> Hi,
>
> Summary:
> Adding a header to a soap message using the WebServiceContext is working
> fine. However, reading the header using the reverse procedure fails.
>
> Environment:
> CXF 2.2.7, OSX and GNU Linux
>
> Problem Description:
> 1) I'm adding the Header:
> ...
> List<Header> headers = new ArrayList<Header>();
> Header cidHeader;
> try {
> cidHeader = new Header(CORRELATION_ID_ELEMENT, cid, new
> JAXBDataBinding(String.class));
> } catch (JAXBException e) {
> throw new IllegalArgumentException("SOAP Header JAXB binding
> is broken and needs to be fixed.", e);
> }
>
> headers.add(cidHeader);
> ctx.put(Header.HEADER_LIST, headers); // WebServiceContext
> ...
>
>
> 2) and when I look at the service consumers logfile all seems to be OK.
> The services response message contains the header:
>
>
> 2010-05-25 11:13:46,512 33093 INFO
> [org.apache.cxf.interceptor.LoggingInInterceptor] (btpool0-3:) Inbound
> Message
> ----------------------------
> ID: 2evilcom
> Response-Code: 200
> Encoding: UTF-8
> Content-Type: text/xml; charset=utf-8
> Headers: {Content-Length=[403], Server=[Jetty(6.1.1rc1)],
> content-type=[text/xml; charset=utf-8]}
> Payload: <soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><correlationId
> xmlns="http://webservices.evilcom.com/header-v1">ff7818d7-60ab-40a2-b594-28515b1007f2</correlationId></soap:Header><soap:Body>....</soap:Body></soap:Envelope>
> --------------------------------------
>
> 3) Now I'm trying to read the header and all I get is the (local) name of
> the header element and a null value:
>
> public CommonSoapHeader(Map<String, Object> requestMessageContext,
> Map<String, Object> responseMessageContext) {
> log.info("responseMessageContext=" + responseMessageContext);
>
> List<Header> headers =
> (List<Header>)responseMessageContext.get(Header.HEADER_LIST);
>
> if(headers == null) { throw new NullPointerException("Unexpected
> error: message context should have returned a header list."); }
>
> for(Iterator<Header> i = headers.iterator(); i.hasNext();) {
> Header h = i.next();
> Element n = (Element)h.getObject();
>
> log.info("lname="+n.getLocalName());
> log.info("nv="+ n.getNodeValue());
> }
> }
>
>
> getLocalName() yields the expected element name 'correlationId', however
> 'getNodeValue()' always yields 'null'.
>
>
> 4) It seems that I'm making a mistake along the way. Why am I always
> getting a null value for my header element?
> I would greatly appreciate a hint on where I went wrong.
> chriss
>
>
>
>
--
View this message in context: http://old.nabble.com/response-message-soap-header-reading-problem-tp28667390p28670536.html
Sent from the cxf-user mailing list archive at Nabble.com.