JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new EchoService());
sf.setBus(getStaticBus());
sf.setAddress(address);
WSPolicyFeature policyFeature = new WSPolicyFeature();
List<Element> policyElements = new ArrayList<Element>();
if (mtomRequired) {
policyElements.add(StaxUtils.read(
getClass().getResourceAsStream("mtom-policy.xml"))
.getDocumentElement());
} else {
policyElements.add(StaxUtils.read(
getClass().getResourceAsStream("mtom-policy-optional.xml"))
.getDocumentElement());
}
policyFeature.setPolicyElements(policyElements);
sf.getFeatures().add(policyFeature);
sf.create();
}