SOAP port initialization in one class

I am creating a Java chat application with a lot of soap services. At the begining of the chat (Dialog start) there are 10 different services and i made a 10 action classes, each class is trying to access different services (handlers in my context) so bassicaly i am creating new instances of ports like that

public class ServiceAction{

    public ServiceAction(){
        ServiceHandler serviceHandler = new ServiceHandler();
    }

    public void process() {
        serviceHandler.initialize();
        serviceHandler.getPaymentDate(ani);
    }
}


public class ServiceHandler{

    public boolean initialize() {
        ssVP = new VPServices(VPServices.WSDL_LOCATION, SERVICE_NAME[VPSERVICES]);
        portVP = ssVP.getServicesWSPort();
        port = portVP;
        initializePort(port);
        return true;
    }

    public void initializePort(Object port) {
        Map<String, Object> reqCtx = ((BindingProvider) port).getRequestContext();
        reqCtx.put(BindingProvider.USERNAME_PROPERTY, wsUsername);
        reqCtx.put(BindingProvider.PASSWORD_PROPERTY, wsPassword);
        reqCtx.put("com.sun.xml.internal.ws.connect.timeout", wsConnTimeout);
        reqCtx.put("com.sun.xml.internal.ws.request.timeout", wsReadTimeout);
        reqCtx.put("com.sun.xml.ws.connect.timeout", wsConnTimeout);
        reqCtx.put("com.sun.xml.ws.request.timeout", wsReadTimeout);
    }

    //Action class referes to this method to obtain paymentDate
    public List<Long> getPaymentDate(String ani) {

        try {
            portVP.getPaymentDate(ani);
            }
            catch(Exception e){

            }
    }
}

and now Im suffering from the consequences since there are different actions that requires same ports. I think to move all port initialization to applicationStart method before dialog even begins, yet I can not think of the way to do that


Ответы (0 шт):