Exception is thrown only the first time an error occur while trying to publish 
a webservice with HTTP transport
---------------------------------------------------------------------------------------------------------------

                 Key: CXF-1589
                 URL: https://issues.apache.org/jira/browse/CXF-1589
             Project: CXF
          Issue Type: Bug
          Components: Transports
    Affects Versions: 2.0.6
            Reporter: Kjell Winblad
             Fix For: 2.0.7


When a webservice with HTTP defined as transport is published with the 
following code and the service is already started at the defined publish 
address an exception is thrown which is a correct behaviour. The problem is 
that if the same publish code is executed again no error is thrown. 

try{
   Endpoint end = Endpoint.create(impl);
   endpoint = (EndpointImpl) end;
   endpoint.setWsdlLocation(wsdlfile);
   endpoint.publish();
}catch(WebServiceException e){
   System.out.println(e);
   
   //The following error message will be printed if the address is already in 
use:
   
   //javax.xml.ws.WebServiceException: org.apache.cxf.interceptor.Fault: 
START_UP_SERVER_FAILED_MSG
   //org.apache.cxf.interceptor.Fault: START_UP_SERVER_FAILED_MSG
   //java.net.BindException: Address already in use
}

try{
   Endpoint end = Endpoint.create(impl);
   endpoint = (EndpointImpl) end;
   endpoint.setWsdlLocation(wsdlfile);
   endpoint.publish();
}catch(WebServiceException e){
   System.out.println(e);
   
   //No exception is thrown this time even if the publish address is already in 
use
}

The problem seems to be in the method 
org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine#addServant. The 
method has the following structure:

    public synchronized void addServant(URL url, JettyHTTPHandler handler) {

        if (server == null) {

            ....  code to start server

            } catch (Exception e) {
                LOG.log(Level.SEVERE, "START_UP_SERVER_FAILED_MSG", new 
Object[] {e.getMessage()});
                //problem starting server
                try {                    
                    server.stop();
                    server.destroy();
                } catch (Exception ex) {
                    //ignore - probably wasn't fully started anyway
                } // Add the following to fix the problem
                  //finally{
                  //  server = null;
                  //}  
                throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG, 
e.getMessage()), e);
            }
        }

The problem is that server field is not null the second time publish is called. 
Adding the expression "server = null;" in a finally block for the server.stop() 
and server.destroy() try seems to fix the problem.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to