Hi Sergey,
so is it possible that there isn't a unique identifier in the XMLMessage,
right?
I can create it without any problem but I wanted to be sure that there
wasn't already one in the message.
For the inputStream when I execute a message.getContentFormats() I see this
response:
[class org.apache.cxf.io.DelegatingInputStream, class
java.io.InputStream]
but when I try to parse the Document from the InputStream it the operation
fails with exception:
org.xml.sax.SAXParseException: Premature end of file.
I should be able to manipulate the Document because I have to add the urn
and the message size into the headers (to pass them from a Dispatcher to the
real ws implementor that is on another machine).
With SOAP ws I tried to perform this adding two new nodes to the header
through a method like this:
private void addInfoToTheMessHeader(Message msg, int size, long startTime){
// TO PASS INFO FROM DISPATCHER TO VELOCITY we must put them
inside the
header of the message...
// ...the only way to allow you to pass this information to the
dispatcher
and from there to the velocity without any change is to encapsulate them in
this way:
try{
Document document = null;
if((InputStream)msg.getContent(InputStream.class) !=
null){
InputStream inputStream =
(InputStream)msg.getContent(InputStream.class);
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
document = builder.parse(inputStream);
}
boolean newNodesAppended = false;
if(document!=null){
int i=0;
while (i < document.getChildNodes().getLength() &&
!newNodesAppended) {
//only a single child node: the soap Envelope
Node nodeR = document.getChildNodes().item(i);
int j=0;
while (j < nodeR.getChildNodes().getLength() &&
!newNodesAppended) {
//two childs: the soap Header and the soap Body
Node nodeF = nodeR.getChildNodes().item(j);
if(nodeF.getLocalName().equals("Header") &&
!newNodesAppended){
//we add a child node to the soap
Header !
Node elem1 =
document.createElement(KPIMsgTracker.KPIWSMsgLen_ByDispatcher);
Node elem2 =
document.createElement(KPIWSLatencyTracker.WSIntercStartTime_ByDispatcher);
//elem.setNodeValue("EANBISO PROV 4A");
elem1.setTextContent(String.valueOf(size));
elem2.setTextContent(String.valueOf(startTime));
nodeF.appendChild(elem1);
nodeF.appendChild(elem2);
newNodesAppended = true;
}
j++;
}
i++;
}
}
//use the changed document to build a new input stream
that will replace
the old in the message...
DOMSource source = new DOMSource(document);
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
TransformerFactory.newInstance().newTransformer().transform(source,
result);
//StringReader xmlReader = new
StringReader(xmlAsWriter.toString());
//InputSource inputSource = new InputSource(xmlReader);
//InputStream tempStream = inputSource.getByteStream();
// write changes:
ByteArrayInputStream inputStream = new
ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
InputStream tempStream = (InputStream)inputStream;
msg.setContent(InputStream.class, tempStream);
tempStream.close();
}catch(Exception e){
log.error("Failed to add the message size to the mess
header.",e);
}
}
But this doesn't work with REST due to the previous problem parsing the
inputStream.
How can I do this?
If I used:
Map headers =
CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS));
headers.put("TEST_SIZE_key", "TEST_SIZE_value");
headers.put("TEST_URN_key", "TEST_URN_value");
message.get(Message.PROTOCOL_HEADERS);
message.put(Message.PROTOCOL_HEADERS, headers);
I would get the same result?
Thanks a lot,
Andrea
--
View this message in context:
http://cxf.547215.n5.nabble.com/CXF-Rest-How-the-get-the-Message-Identifier-from-a-XMLMessage-tp5730734p5730737.html
Sent from the cxf-user mailing list archive at Nabble.com.