Hi
I'm a bit confused, sorry. I'd expect the code below work for non-SOAP
exchanges too. Unless it is HTTP GET for example, where you may have an
empty InputStream stream set.
Re XMLMessage id, I guess you can use your own algorithm to create a
unique id and set it as a message property
Cheers, Sergey
On 15/07/13 10:13, eanbiso wrote:
Hi all,
I need to get the equivalent of the SOAP MessageID with REST ws.
I have an interceptor that must register a message in a MAP and I have to
use the message urn as the unique message identifier.
How can I get it?
With SOAP technology I used an interceptor like this:
public class WSKPIMsgSizeInInterceptor extends AbstractLoggingInterceptor {
....
public WSKPIMsgSizeInInterceptor() {
super(Phase.RECEIVE);
}
public void handleMessage(Message message) throws Fault {
.....
//retrieve URN of the message (unique id)
String msgUrn = getMessageId(message);
.....
}
/**
* This method is useful to try to get the Message ID from the message
dom
Node.
* @param message
* @return the urn of the message
*/
private String getMessageId(Message message){
try{
//message.getContentFormats();
String urn = "";
Document document = null;
if((InputStream)message.getContent(InputStream.class)
!= null){
InputStream inputStream =
(InputStream)message.getContent(InputStream.class);
//do not change the input stream
CachedOutputStream bos = new
CachedOutputStream();
IOUtils.copy(inputStream, bos);
bos.flush();
inputStream.close();
message.setContent(InputStream.class,
bos.getInputStream());
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
document = builder.parse(bos.getInputStream());
bos.close();
}
if(document!=null){
int i=0;
while (i < document.getChildNodes().getLength()) {
Node node = document.getChildNodes().item(i);
int j=0;
while (j < node.getChildNodes().getLength()) {
Node nodeF = node.getChildNodes().item(j);
int k=0;
while(k < nodeF.getChildNodes().getLength()){
Node nodeFF =
nodeF.getChildNodes().item(k);
if(nodeFF.getNodeName().equals("MessageID")){
urn =
nodeFF.getChildNodes().item(0).getNodeValue();
if(urn!=null)
return urn;
}
k++;
}
j++;
}
i++;
}
}
return "";
}catch(Exception e){
log.error("Failed to get the MessageID (urn) from the mess
header.",e);
return "";
}
}
}
In this way I was able to get the MessageID (the urn:..... of the Message).
But now that I use REST ws I arrive in the same interceptor with an
XMLMessage and I have two problems:
1. the operation to get the document from the message fails (how can I build
the document with REST?)
2. in general I'm not able to find in the XMLMessage a value that identifies
the message in any way (there is an identifier in the message?).
Bets regards,
Andrea
--
View this message in context:
http://cxf.547215.n5.nabble.com/CXF-Rest-How-the-get-the-Message-Identifier-from-a-XMLMessage-tp5730734.html
Sent from the cxf-user mailing list archive at Nabble.com.