Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.6
-
None
-
Novice
Description
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[]
);
//problem starting server
try
catch (Exception ex)
{ //ignore - probably wasn't fully started anyway } // Add the following to fix the problem
//finally
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.