JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new EchoService());
sf.setBus(getBus());
sf.setAddress(address);
WSPolicyFeature policyFeature = new WSPolicyFeature();
List<Element> policyElements = new ArrayList<Element>();
if (mtomRequired) {
policyElements.add(DOMUtils.readXml(
getClass().getResourceAsStream("mtom-policy.xml"))
.getDocumentElement());
} else {
policyElements.add(DOMUtils.readXml(
getClass().getResourceAsStream("mtom-policy-optional.xml"))
.getDocumentElement());
getBus().getExtension(PolicyConstants.class)
.setNamespace(PolicyConstants.NAMESPACE_W3_200607);
}
policyFeature.setPolicyElements(policyElements);
sf.getFeatures().add(policyFeature);
sf.create();
}