Change webservice endpoint at runtime


Problem Description: In ADF we can create a webservice proxy and if we see the main class which extends Service has references of wsdl like



Now if we have dev/uat/production environment and for each environment we need to change endpoint, it could be very bad to change url manually and then generate ear. We need a way to dynamically change url at runtime.





Solutions

What we can do is keep service class as it is. We can use Client class, which we use to create instance of Servce and while creating instance we can provide url



Let say my client class is HCMUserDetailService. I change its constructor to accept url from outside.



    public HCMUserDetailService(String wsdlLocation, String username, String password) {

        super();

        userDetailsService_Service =  new UserDetailsService_Service(wsdlLocation, new QName("http://xmlns.oracle.com/apps/hcm/people/roles/userDetailsServiceV2/",

                    "UserDetailsService"));

        SecurityPoliciesFeature securityFeatures =     new SecurityPoliciesFeature(new String[] { "oracle/wss_username_token_over_ssl_client_policy" });

        userDetailService =      userDetailsService_Service.getUserDetailsServiceSoapHttpPort(securityFeatures);

        Map<String, Object> reqContext =  ((BindingProvider)userDetailService).getRequestContext();

        reqContext.put(BindingProvider.USERNAME_PROPERTY, username);

        reqContext.put(BindingProvider.PASSWORD_PROPERTY, password);

        objectFactory = new ObjectFactory();

             

       

    }







In above code constructor accepts a wsdl url as input and use that to create service instance using UserDetailsService_Service(wsdlLocation,new QName....





Now anybody needs to invoke service using this proxy we can pass wsdl location as input.



User of this client can read wsdl from

1. web.xml context parameter and then use deployment plan to change value of web.xml

2. from database table.



That way wsdl url is not hardcoded and it will get changed dyanamically.



Thats all.



Related Posts