What's the best way for me to change my endpoint dynamically?

I've got a working Axis client that uses the WSDL2Java generated stubs.  I can't figure out a real clean way to utilize the stubs and just change the endpoint.  How are people doing this?

If it helps, here's what I've got so far...

I created a ServiceRequestor class that handles getting my document for the SOAP body, and that class also has a property for the endpoint.  I'd like to change that endpoint for development vs. test vs. production environments.

The problem is my call in the first line of overrideEndpoint() is always null.  Otherwise this would work great!

        [...snip...]
                        CriminalInvestigationsService service = new CriminalInvestigationsServiceLocator();
                        CriminalInvestigationsServiceSoap serviceSoap;
                        MajorCaseResponse response;
                        serviceSoap = service.getCriminalInvestigationsServiceSoap();

                        if (serviceRequestor.getEndpoint() != null) {
                                Stub stub = (Stub) serviceSoap;
                                overrideEndpoint(stub);
                        }

                        CPSINDocument request = new CPSINDocument();
                        String xmlInput = soapBodyElement.getAsString();
                        request.setCPSIN200Document(xmlInput);
                        logger.info("Invoke the web service, passing request object...");
                        response = serviceSoap.submitMajorCaseInvestigation(request);

        [...snip...]

        protected void overrideEndpoint(Stub stub) {
                Call call = stub._getCall();
                if (call == null) {
                        logger.error("Call is null.");
                } else {
                        if (serviceRequestor.getEndpoint() != null) {
                                logger.info("Overriding call endpoint...");
                                call.setTargetEndpointAddress(serviceRequestor.getEndpoint());
                                logger.info("Endpoint overridden as " + call.getTargetEndpointAddress());
                        } else {
                                logger.info("ServiceRequestor endpoint not set, using default.");
                        }
                }
        }


Reply via email to