FileDocCategorySizeDatePackage
TXStatefulWebserviceFactoryImpl.javaAPI DocExample16216Tue May 29 16:57:18 BST 2007com.sun.xml.ws.tx.webservice.member

TXStatefulWebserviceFactoryImpl

public final class TXStatefulWebserviceFactoryImpl extends Object implements com.sun.xml.ws.tx.common.StatefulWebserviceFactory
This class ...
author
Ryan.Shoemaker@Sun.COM
version
$Revision: 1.10.2.1 $
since
1.0

Fields Summary
private static final com.sun.xml.ws.tx.common.TxLogger
logger
private static boolean
registeredFallback
private static boolean
wstxServiceAvailable
private boolean
pingServices
Constructors Summary
Methods Summary
public javax.xml.ws.EndpointReferencecreateService(java.lang.String serviceName, java.lang.String portName, java.net.URI address, com.sun.xml.ws.api.addressing.AddressingVersion addressingVersion, java.lang.String activityId, java.lang.String registrantId)

        registerFallback();
        if (serviceName.equals(ParticipantPortTypeImpl.serviceName)) {
            // ParticipantPortTypeImpl && CoordinatorPortTypeImpl have the same serviceName
            if (portName.equals(ParticipantPortTypeImpl.portName)) {
                ParticipantPortTypeImpl participant =
                        new ParticipantPortTypeImpl(activityId, registrantId);
                return ParticipantPortTypeImpl.getManager().
                        export(addressingVersion.eprType.eprClass, address.toString(), participant);
            } else if (portName.equals(CoordinatorPortTypeImpl.portName)) {
                CoordinatorPortTypeImpl coordinator =
                        new CoordinatorPortTypeImpl(activityId, registrantId);
                return CoordinatorPortTypeImpl.getManager().
                        export(addressingVersion.eprType.eprClass, address.toString(), coordinator);
            } else {
                throw new IllegalStateException( LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
            }
        } else if (serviceName.equals(RegistrationRequesterPortTypeImpl.serviceName)) {
            if (portName.equals(RegistrationRequesterPortTypeImpl.portName)) {
                RegistrationRequesterPortTypeImpl registrationRequester =
                        new RegistrationRequesterPortTypeImpl(activityId, registrantId);
                return RegistrationRequesterPortTypeImpl.getManager().
                        export(addressingVersion.eprType.eprClass, address.toString(), registrationRequester);
            } else if (portName.equals(RegistrationCoordinatorPortTypeImpl.portName)) {
                RegistrationCoordinatorPortTypeImpl registrationCoordinator =
                        new RegistrationCoordinatorPortTypeImpl(activityId);
                return RegistrationCoordinatorPortTypeImpl.getManager().
                        export(addressingVersion.eprType.eprClass, address.toString(), registrationCoordinator);
            } else {
                throw new IllegalStateException( LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
            }
        } else {
            throw new IllegalStateException( LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
        }
    
public com.sun.xml.ws.developer.StatefulWebServiceManagergetManager(java.lang.String serviceName, java.lang.String portName)


    
            
        registerFallback();
        if (serviceName.equals(ParticipantPortTypeImpl.serviceName)) {
            // ParticipantPortTypeImpl && CoordinatorPortTypeImpl have the same serviceName
            if (portName.equals(ParticipantPortTypeImpl.portName)) {
                return ParticipantPortTypeImpl.getManager();
            } else if (portName.equals(CoordinatorPortTypeImpl.portName)) {
                return CoordinatorPortTypeImpl.getManager();
            } else {
                throw new IllegalStateException(
                        LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
            }
        } else if (serviceName.equals(RegistrationRequesterPortTypeImpl.serviceName)) {
            if (portName.equals(RegistrationRequesterPortTypeImpl.portName)) {
                return RegistrationRequesterPortTypeImpl.getManager();
            } else if (portName.equals(RegistrationCoordinatorPortTypeImpl.portName)) {
                return RegistrationCoordinatorPortTypeImpl.getManager();
            } else {
                throw new IllegalStateException(LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
            }
        } else {
            throw new IllegalStateException(LocalizationMessages.WSTX_SERVICE_PORT_NOT_FOUND_5001(portName, serviceName));
        }
    
public booleanisWSTXServiceAvailable()
Returns true iff all endpoints for wstx_service are available. Identifies when no coordinator specified for application client. Also, identifies when there is a configuration issue for wstx_service.

   
                                    
       
        registerFallback();
        return wstxServiceAvailable;
    
private voidpingService(java.lang.String urlAddr, java.lang.Class sws)

        final String METHOD = "pingService";
        HttpURLConnection conn = null;
        InputStream response = null;
        BufferedReader reader = null;
        try {
            URL url = new URL(urlAddr);
            conn = (HttpURLConnection) url.openConnection();
            if (conn instanceof HttpsURLConnection) {
                ((HttpsURLConnection) conn).setHostnameVerifier(
                        new HostnameVerifier() {
                            public boolean verify(String string, SSLSession sSLSession) {
                                return true;
                            }
                        });
            }
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded"); // taken from wsimport
            conn.connect();
            response = conn.getInputStream();
            reader = new BufferedReader(
                    new InputStreamReader(response));
            String line = reader.readLine();
            while (line != null) {
//              logger.finest(METHOD, line);
                line = reader.readLine();
            }
            if (logger.isLogging(Level.FINEST)) {
                logger.finest(METHOD, "RESPONSE CODE: " + conn.getResponseCode());
            }
            if (sws.getDeclaredField("manager").equals(null)) {
                logger.severe(METHOD, 
                              LocalizationMessages.ENDPOINT_NOT_AVAILABLE_5002(urlAddr, sws.getName()));
            } else {
                logger.finest(METHOD, "Injection succeeded");
            }
        } catch (Exception e) {
            if (wstxServiceAvailable) {
                wstxServiceAvailable = false;
                
                // only print stacktrace for first endpoint ping failure.
                logger.warning(METHOD,
                        LocalizationMessages.ENDPOINT_NOT_AVAILABLE_5002(urlAddr, sws.getName()));
                logger.fine(METHOD,
                        LocalizationMessages.ENDPOINT_NOT_AVAILABLE_5002(urlAddr, sws.getName()), e);
            } else {
                logger.severe(METHOD, 
                        LocalizationMessages.ENDPOINT_NOT_AVAILABLE_5002(urlAddr, sws.getName()));
            }
        } finally {
            try {
                if (conn != null) conn.disconnect();
                if (reader != null) reader.close();
            } catch (Exception e) {
                // ignore
            }
        }
    
private voidpingStatefulServices()
A workaround for WSIT issue 309

The GF performance team does not want our wstx services to load during app server startup, so they are marked to lazy deploy upon the first invocation. Unfortunately we need to access the stateful webservice manager field in some of these services before the first invocation, so we will ping each of them to force the load to happen.

This will only happen once and it will only happen after we are certain that an app needs these services running.


                                                                                                  
       
        if (pingServices) {
            pingServices = false;
            wstxServiceAvailable = true; // if any pingService fails, this reverts to false.

            if (logger.isLogging(Level.FINEST)) {
                logger.finest("pingStatefulServices", "pinging register service...");
            }
            pingService((AddressManager.getAddress(RegistrationCoordinatorPortType.class, false).toString() + "?wsdl"),
                    RegistrationCoordinatorPortTypeImpl.class);
            if (!wstxServiceAvailable) {
                return; // short-circuit if the first ping fails
            }
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("pingStatefulServices", "pinging registerResponse service...");
            }
            pingService((AddressManager.getAddress(RegistrationRequesterPortType.class, false).toString() + "?wsdl"),
                    RegistrationRequesterPortTypeImpl.class);
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("pingStatefulServices", "pinging ATCoordinator service...");
            }
            pingService((AddressManager.getAddress(CoordinatorPortType.class, false).toString() + "?wsdl"),
                    CoordinatorPortTypeImpl.class);
            if (logger.isLogging(Level.FINEST)) {
                logger.finest("pingStatefulServices", "pinging ATParticipant service...");
            }
            pingService((AddressManager.getAddress(ParticipantPortType.class, false).toString() + "?wsdl"),
                    ParticipantPortTypeImpl.class);
        }
    
private voidregisterFallback()
Instances that handle request for unknown StatefulWebService instance. This can happen when a request for a StatefulWebService is received after the instance has timed out or was explicitly unexported.

        if (!registeredFallback ) {
            registeredFallback = true;

            // force the lazy deployment of our ws so we can access the stateful manager field
            pingStatefulServices();

            if (isWSTXServiceAvailable()) {
                ParticipantPortTypeImpl participant =
                        new ParticipantPortTypeImpl(UNKNOWN_ID, UNKNOWN_ID);
                if (ParticipantPortTypeImpl.getManager() != null) {
                    ParticipantPortTypeImpl.getManager().setFallbackInstance(participant);
                } else {
                    wstxServiceAvailable = false;
                }
                
                CoordinatorPortTypeImpl coordinator =
                        new CoordinatorPortTypeImpl(UNKNOWN_ID, UNKNOWN_ID);
                if (CoordinatorPortTypeImpl.getManager() != null) {
                     CoordinatorPortTypeImpl.getManager().setFallbackInstance(coordinator);
                } else {
                    wstxServiceAvailable = false;
                }
               
                
                RegistrationRequesterPortTypeImpl registrationRequester =
                        new RegistrationRequesterPortTypeImpl(UNKNOWN_ID, UNKNOWN_ID);
                 if (RegistrationRequesterPortTypeImpl.getManager() != null) {
                    RegistrationRequesterPortTypeImpl.getManager().setFallbackInstance(registrationRequester);
                } else {
                    wstxServiceAvailable = false;
                }
               
                RegistrationCoordinatorPortTypeImpl registrationCoordinator =
                        new RegistrationCoordinatorPortTypeImpl(UNKNOWN_ID);
                if (RegistrationCoordinatorPortTypeImpl.getManager() != null) {
                    RegistrationCoordinatorPortTypeImpl.getManager().setFallbackInstance(registrationCoordinator);
                } else {
                    wstxServiceAvailable = false;
                }
            } else {
                registeredFallback = false;
            }
        }