/** * Extends the Spring class responsible of transforming the WSDL before rendering it on a GET request. *

* This is therefore a workaround to avoid the duplicate attributes problem, caused by a buggy Xalan library included in * some application servers such as Wildfly 8 or 9. *

* * @see * Jboss bug tracker
* Jboss forums */ public class NonTransformingWsdlDefinitionHandlerAdapter extends WsdlDefinitionHandlerAdapter { private static final String CONTENT_TYPE = "text/xml"; private boolean transformLocations = false; private boolean transformSchemaLocations = false; public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (HttpTransportConstants.METHOD_GET.equals(request.getMethod())) { response.setContentType(CONTENT_TYPE); // Getting the bytestream from the source WSDL WsdlDefinition definition = (WsdlDefinition) handler; Source definitionSource = definition.getSource(); InputStream sourceIs = SAXSource.sourceToInputSource(definitionSource).getByteStream(); try { // Building a DOM from the bytestream DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document dom = docBuilder.parse(sourceIs); // Transforming locations if necessary if (transformLocations || transformSchemaLocations) { if (transformLocations) { transformLocations(dom, request); } if (transformSchemaLocations) { transformSchemaLocations(dom, request); } } // Serialization and output DOMImplementationLS domImplLs = (DOMImplementationLS) dom.getImplementation().getFeature("LS", "3.0"); LSSerializer serializer = domImplLs.createLSSerializer(); LSOutput output = domImplLs.createLSOutput(); output.setByteStream(response.getOutputStream()); serializer.write(dom, output); } finally { sourceIs.close(); } } else { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } return null; } @Override public void setTransformLocations(boolean transformLocations) { this.transformLocations = transformLocations; } @Override public void setTransformSchemaLocations(boolean transformSchemaLocations) { this.transformSchemaLocations = transformSchemaLocations; } }