1

I used wsimport to generate client code from a WSDL file, I have managed to test this generated code and it works but with one problem, the code references the WSDL file like this,

static {
    URL url = null;
    try {
        URL baseUrl;
        baseUrl = com.spx.global.spf_wmis_dev.etq2sapintegration_zqm246f_etq_validate_matnr_webservice.matnr_provider.ETQ2SAPIntegrationZQM246FETQVALIDATEMATNRWebServiceMATNRProvider.class.getResource(".");
        url = new URL(baseUrl, "file:/C:/Users/xx/Desktop/spx/wsdls/validate_MATNR.wsdl");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: 'file:/C:/Users/xx/Desktop/spx/wsdls/validate_MATNR.wsdl', retrying as a local file");
        logger.warning(e.getMessage());
    }
    ETQ2SAPINTEGRATIONZQM246FETQVALIDATEMATNRWEBSERVICEMATNRPROVIDER_WSDL_LOCATION = url;
}

And I have created a mock service for that WSDL file using soapUI running on http://localhost:8088/validate and if I use this exact URL in the WSDL file like this, everything works just fine.

<wsdl:port name="ETQ2SAPIntegration_ZQM246F_ETQ_VALIDATE_MATNR_WebService_MATNR_provider_Port" binding="tns:ETQ2SAPIntegration_ZQM246F_ETQ_VALIDATE_MATNR_WebService_MATNR_provider_Binder">
  <soap:address location="http://localhost:8088/validate"/>
</wsdl:port>

Now I want to be able to specify the web service location without referring to the WSDL file, I tried many things like overriding the port endPointAddress,

ETQ2SAPIntegrationZQM246FETQVALIDATEMATNRWebServiceMATNRProvider ser= new ETQ2SAPIntegrationZQM246FETQVALIDATEMATNRWebServiceMATNRProvider(); this class extends the Service class
        javax.xml.namespace.QName qn= new QName("http://SPF-WMIS-DEV.GLOBAL.SPX.COM/ETQ2SAPIntegration.ZQM246F_ETQ_VALIDATE_MATNR.WebService:MATNR_providera", "ETQ2SAPIntegration.ZQM246F_ETQ_VALIDATE_MATNR.WebService.MATNR_provider");
        ser.addPort(qn,HTTPBinding.HTTP_BINDING, "http://localhost:8088/test");
        ZQM246FETQVALIDATEMATNRResponse response = new ZQM246FETQVALIDATEMATNRResponse();
        MATNRProviderPortType provider = ser.getETQ2SAPIntegrationZQM246FETQVALIDATEMATNRWebServiceMATNRProviderPort();

But no matter what I try the code just keeps trying to read the endPointAddress from the WSDL file, maybe what I am trying to do isn't doable meaning that I cant just get rid of the WSDL file, I am not sure at this point, so any advise would be more than helpful.

P.S: Don't blame me for not following the Java Naming Convention, and I hate it as much as you do.

QuakeCore
  • 1,886
  • 2
  • 15
  • 33

1 Answers1

1

You can change a request context like this (I've shortened names of a service and provider for better readability):

String address = "http://localhost:8088/validate";
BlaBlaWebService service = new BlaBlaWebService();
BlaBlaProviderPort provider = ser.getBlaBlaProviderPort();
if (provider instanceof BindingProvider) {
    BindingProvider bindProvider = (BindingProvider)provider;
    bindProvider.getRequestContext().put(
        BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
} else {
   //log or fail if you want
}
Dmitry P.
  • 824
  • 5
  • 14
  • I have been searching for a solution for the last 8 hours or so, thanks a lot :)) – QuakeCore Feb 02 '16 at 15:05
  • Just one more question if you can answer me, why do the generated code need the WSDL file at run time ? – QuakeCore Feb 02 '16 at 15:07
  • @QuakeCore there is a good anwer here: http://stackoverflow.com/questions/20101009/why-does-a-jax-ws-client-access-the-wsdl-at-run-time – Dmitry P. Feb 02 '16 at 15:08
  • believe it or not I have stumbled upon that question, and something similar to your answer before, I guess I just couldn't make up the right connections, but its all clear now, thanks again. – QuakeCore Feb 02 '16 at 15:11