01: package org.objectweb.celtix.bus.bindings.soap;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06: import java.util.Set;
07:
08: import javax.xml.bind.JAXBContext;
09: import javax.xml.namespace.QName;
10: import javax.xml.soap.SOAPException;
11: import javax.xml.soap.SOAPHeader;
12: import javax.xml.soap.SOAPHeaderElement;
13: import javax.xml.soap.SOAPMessage;
14: import javax.xml.ws.WebServiceException;
15: import javax.xml.ws.handler.MessageContext;
16: import javax.xml.ws.handler.soap.SOAPMessageContext;
17:
18: import org.objectweb.celtix.bus.jaxws.JAXBEncoderDecoder;
19: import org.objectweb.celtix.context.MessageContextWrapper;
20:
21: class SOAPMessageContextImpl extends MessageContextWrapper implements
22: SOAPMessageContext {
23: private static final long serialVersionUID = 1L;
24: private static final String SOAP_MESSAGE = "org.objectweb.celtix.bindings.soap.message";
25: private Set<String> soapRoles;
26:
27: public SOAPMessageContextImpl(MessageContext ctx) {
28: super (ctx);
29: }
30:
31: public SOAPMessage getMessage() {
32: return (SOAPMessage) get(SOAP_MESSAGE);
33: }
34:
35: public void setMessage(SOAPMessage soapMsg) {
36: put(SOAP_MESSAGE, soapMsg);
37: setScope(SOAP_MESSAGE, MessageContext.Scope.HANDLER);
38: }
39:
40: public Object[] getHeaders(QName headerName,
41: JAXBContext jaxbContext, boolean allRoles) {
42: SOAPMessage msg = getMessage();
43: assert msg != null;
44:
45: List<Object> headerList = new ArrayList<Object>();
46:
47: SOAPHeader header = null;
48: try {
49: header = msg.getSOAPHeader();
50: } catch (SOAPException se) {
51: throw new WebServiceException(
52: "Could not get the SOAPHeader node", se);
53: }
54:
55: if (header == null) {
56: return new Object[0];
57: }
58: Iterator iter = header.getChildElements(headerName);
59:
60: //TODO Role/Actor attribute is not supported yet.
61: //Assuming ultimate receiver.
62: while (iter.hasNext()) {
63: SOAPHeaderElement headerNode = (SOAPHeaderElement) iter
64: .next();
65: Object headerValue = JAXBEncoderDecoder.unmarshall(
66: jaxbContext, null, headerNode, headerName);
67: assert headerValue != null;
68: headerList.add(headerValue);
69: }
70:
71: return headerList.toArray();
72: }
73:
74: public Set<String> getRoles() {
75: return soapRoles;
76: }
77: }
|