1 package org.sentrysoftware.winrm.service;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.List;
24
25 import javax.xml.bind.JAXBElement;
26 import javax.xml.bind.JAXBException;
27
28 import org.apache.cxf.binding.soap.SoapMessage;
29 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
30 import org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor;
31 import org.apache.cxf.headers.Header;
32 import org.apache.cxf.interceptor.Fault;
33 import org.apache.cxf.jaxb.JAXBDataBinding;
34 import org.apache.cxf.phase.Phase;
35
36 import org.sentrysoftware.winrm.Utils;
37 import org.sentrysoftware.winrm.service.wsman.AttributableURI;
38 import org.sentrysoftware.winrm.service.wsman.ObjectFactory;
39
40
41
42
43
44 public class WSManHeaderInterceptor extends AbstractSoapInterceptor {
45
46 private static final JAXBDataBinding ATTRIBUTABLE_URI_JAXB_DATA_BINDING;
47 static {
48 try {
49 ATTRIBUTABLE_URI_JAXB_DATA_BINDING = new JAXBDataBinding(AttributableURI.class);
50 } catch (final JAXBException e) {
51 throw new RuntimeException(
52 "Failed to create JAXBDataBinding for: AttributableURI" + AttributableURI.class,
53 e);
54 }
55 }
56
57 private final String resourceUri;
58
59 public WSManHeaderInterceptor(final String resourceUri) {
60 super(Phase.POST_LOGICAL);
61
62 addAfter(SoapPreProtocolOutInterceptor.class.getName());
63
64 Utils.checkNonNull(resourceUri, "resourceUri");
65
66 this.resourceUri = resourceUri;
67 }
68
69 @Override
70 public void handleMessage(final SoapMessage message) throws Fault {
71
72 final JAXBElement<String> resourceURI = new ObjectFactory().createResourceURI(resourceUri);
73
74 final List<Header> headers = message.getHeaders();
75 headers.add(
76 new Header(resourceURI.getName(), resourceURI, ATTRIBUTABLE_URI_JAXB_DATA_BINDING));
77
78 message.put(Header.HEADER_LIST, headers);
79 }
80
81 }