1 | package gov.hhs.fha.nhinc.hiemunsubscribe;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Map;
|
---|
7 | import java.util.Set;
|
---|
8 | import javax.xml.namespace.QName;
|
---|
9 | import javax.xml.soap.SOAPMessage;
|
---|
10 | import javax.xml.soap.SOAPHeader;
|
---|
11 | import javax.xml.ws.handler.MessageContext;
|
---|
12 | import javax.xml.ws.handler.soap.SOAPHandler;
|
---|
13 | import javax.xml.ws.handler.soap.SOAPMessageContext;
|
---|
14 | import org.w3c.dom.Node;
|
---|
15 | import org.w3c.dom.NodeList;
|
---|
16 | import org.apache.commons.logging.Log;
|
---|
17 | import org.apache.commons.logging.LogFactory;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | *
|
---|
21 | * @author webbn
|
---|
22 | */
|
---|
23 | public class HiemUnsubscribeSoapHeaderHandler implements SOAPHandler<SOAPMessageContext>
|
---|
24 | {
|
---|
25 | private static Log log = LogFactory.getLog(HiemUnsubscribeSoapHeaderHandler.class);
|
---|
26 |
|
---|
27 | @SuppressWarnings("unchecked")
|
---|
28 | public Set<QName> getHeaders()
|
---|
29 | {
|
---|
30 | return Collections.EMPTY_SET;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public boolean handleMessage(SOAPMessageContext context)
|
---|
34 | {
|
---|
35 | extractReferenceParameters(context);
|
---|
36 | return true;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public boolean handleFault(SOAPMessageContext context)
|
---|
40 | {
|
---|
41 | return true;
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void close(MessageContext context)
|
---|
45 | {
|
---|
46 | }
|
---|
47 |
|
---|
48 | private void extractReferenceParameters(SOAPMessageContext context)
|
---|
49 | {
|
---|
50 | log.debug("******** In handleMessage() *************");
|
---|
51 | try
|
---|
52 | {
|
---|
53 | String subscriptionId = null;
|
---|
54 | if(context != null)
|
---|
55 | {
|
---|
56 | log.debug("******** Context was not null *************");
|
---|
57 | SOAPMessage soapMessage = context.getMessage();
|
---|
58 | log.debug("******** After getMessage *************");
|
---|
59 |
|
---|
60 | if(soapMessage != null)
|
---|
61 | {
|
---|
62 | log.debug("******** Attempting to write out SOAP message *************");
|
---|
63 | try
|
---|
64 | {
|
---|
65 | soapMessage.writeTo(System.out);
|
---|
66 | log.debug("******** After call to write out SOAP message *************");
|
---|
67 |
|
---|
68 | SOAPHeader soapHeader = soapMessage.getSOAPHeader();
|
---|
69 | if(soapHeader != null)
|
---|
70 | {
|
---|
71 | NodeList headerNodes = soapHeader.getChildNodes();
|
---|
72 | log.debug("Header node count: " + headerNodes.getLength());
|
---|
73 | if(headerNodes != null)
|
---|
74 | {
|
---|
75 | for(int i = 0; i < headerNodes.getLength(); i++)
|
---|
76 | {
|
---|
77 | Node node = headerNodes.item(i);
|
---|
78 | processNode(node, context);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | else
|
---|
82 | {
|
---|
83 | log.debug("Header nodes list was null");
|
---|
84 | }
|
---|
85 | }
|
---|
86 | else
|
---|
87 | {
|
---|
88 | log.debug("Soap header was null");
|
---|
89 | }
|
---|
90 | }
|
---|
91 | catch (Throwable t)
|
---|
92 | {
|
---|
93 | log.debug("Exception writing out the message");
|
---|
94 | t.printStackTrace();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | else
|
---|
98 | {
|
---|
99 | log.debug("SOAPMessage was null");
|
---|
100 | }
|
---|
101 | }
|
---|
102 | else
|
---|
103 | {
|
---|
104 | log.debug("SOAPMessageContext was null.");
|
---|
105 | }
|
---|
106 | // if(subscriptionId != null)
|
---|
107 | // {
|
---|
108 | // log.debug("Setting subscription id ----------------");
|
---|
109 | // @SuppressWarnings("unchecked")
|
---|
110 | // Map<String, List<String>> msgCtxMap = (Map<String, List<String>>)context.get(MessageContext.HTTP_REQUEST_HEADERS);
|
---|
111 | // if(msgCtxMap != null)
|
---|
112 | // {
|
---|
113 | // List<String> refParams = new ArrayList<String>();
|
---|
114 | // refParams.add(subscriptionId);
|
---|
115 | // msgCtxMap.put("Subscriptionid", refParams);
|
---|
116 | // log.debug("Added subscription id ###############################");
|
---|
117 | // }
|
---|
118 | // }
|
---|
119 | }
|
---|
120 | catch(Throwable t)
|
---|
121 | {
|
---|
122 | log.debug("Error logging the SOAP message: " + t.getMessage());
|
---|
123 | t.printStackTrace();
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | private void processNode(Node node, SOAPMessageContext context)
|
---|
128 | {
|
---|
129 | if(node != null)
|
---|
130 | {
|
---|
131 | log.debug("Node name: " + node.getNodeName());
|
---|
132 | log.debug("Node local name: " + node.getLocalName());
|
---|
133 | log.debug("Node prefix: " + node.getPrefix());
|
---|
134 | log.debug("Node namespace URI: " + node.getNamespaceURI());
|
---|
135 | log.debug("Node value: " + node.getNodeValue());
|
---|
136 | log.debug("Node text content: " + node.getTextContent());
|
---|
137 |
|
---|
138 | if("SubscriptionId".equalsIgnoreCase(node.getLocalName()))
|
---|
139 | {
|
---|
140 | String subscriptionId = node.getTextContent();
|
---|
141 |
|
---|
142 | @SuppressWarnings("unchecked")
|
---|
143 | Map<String, List<String>> msgCtxMap = (Map<String, List<String>>)context.get(MessageContext.HTTP_REQUEST_HEADERS);
|
---|
144 | if(msgCtxMap != null)
|
---|
145 | {
|
---|
146 | List<String> refParams = new ArrayList<String>();
|
---|
147 | refParams.add(subscriptionId);
|
---|
148 | msgCtxMap.put("Subscriptionid", refParams);
|
---|
149 | log.debug("Added subscription id ###############################");
|
---|
150 | }
|
---|
151 | }
|
---|
152 | if(node.hasChildNodes())
|
---|
153 | {
|
---|
154 | NodeList childNodes = node.getChildNodes();
|
---|
155 | log.debug("Node has " + childNodes.getLength() + " child nodes");
|
---|
156 | for(int i = 0; i < childNodes.getLength(); i++)
|
---|
157 | {
|
---|
158 | Node childNode = childNodes.item(i);
|
---|
159 | processNode(childNode, context);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|