Using a local copy of a WSDL with JAX-WS
By default when JAX-WS auto-generates a proxy stub via wsimport, it will reference the live web version of the WSDL in the stub definition. This means that when the stub object is instantiated, JAX-WS will go over the wire to get a copy of the WSDL. Recently, we had a WAR deploy break because Spring was instantiating one of these on start up, and the actual third party WSDL wasn't there.
I little research turned up a few ways to make this WSDL a local resource, instead. In our case, we just put it in the META-INF directory in the WAR, and made a small manual change to the stub code.
What used to be...
@WebServiceClient(name = "MonsterBusinessGatewayService", targetNamespace = "http://www.monster.com/definitions", wsdlLocation = "https://gateway.monster.com:8443/bgwBroker?WSDL") public class MonsterBusinessGatewayService extends Service { private final static URL MONSTERBUSINESSGATEWAYSERVICE_WSDL_LOCATION; private final static Logger logger = Logger.getLogger(com.monster.definitions.MonsterBusinessGatewayService.class.getName()); static { URL url = null; try { URL baseUrl; baseUrl = com.monster.definitions.MonsterBusinessGatewayService.class.getResource("."); url = new URL(baseUrl, "https://gateway.monster.com:8443/bgwBroker?WSDL"); } catch (MalformedURLException e) { logger.warning("Failed to create URL for the wsdl Location: 'https://gateway.monster.com:8443/bgwBroker?WSDL', retrying as a local file"); logger.warning(e.getMessage()); } MONSTERBUSINESSGATEWAYSERVICE_WSDL_LOCATION = url; }
became...
@WebServiceClient(name = "MonsterBusinessGatewayService", targetNamespace = "http://www.monster.com/definitions", wsdlLocation = "META-INF/wsdl/MonsterWSDL.xml") ... try { URL baseUrl = MonsterBusinessGatewayService.class.getClassLoader().getResource("."); url = new URL(baseUrl, "META-INF/wsdl/Monster.xml"); } catch (MalformedURLException e) { ...