Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webbitserver 0.4.12 SocketException: Unexpected end of file from server #124

Open
buzz3791 opened this issue Oct 1, 2013 · 1 comment
Open

Comments

@buzz3791
Copy link

buzz3791 commented Oct 1, 2013

Per @aslakhellesoy comment on webbit/webbit-rest#3, I'm re-opening against webbit.

Every 5-7 days my webbit-rest 0.3.0 client keeps getting "SocketException: Unexpected end of file from server". At times I can also reproduce this issue by hitting the REST URL using a web browser (Chrome returns Unable to load the webpage because the server sent no data.Error code: ERR_EMPTY_RESPONSE). Some basic googling shows this error typically means that the Content-Length header is not set. Is this a known issue? Should I file a defect against webbitserver rather than webbit-rest?

My webbit-rest app is super simple, supporting just 1 URI.

CoverityProxy.java

package com.somecompany.somepkg;

import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import javax.security.auth.callback.CallbackHandler;

import org.webbitserver.WebServer;
import org.webbitserver.netty.NettyWebServer;
import org.webbitserver.rest.Rest;

/**
 * <p>
 * A RESTful web service intended to sit in
 * front of Coverity Connect so that Groovy/Java clients
 * don't have to deal with JAX-WS.
 * 
 */
public class CoverityProxy {    

    private static final Logger LOG = Logger.getLogger(CoverityIssuesByImpactHttpHandler.class.getName());

    static {
        LOG.setLevel(Level.ALL) ;
    }   

    /**
     * The actual URI Template is specified {@link CoverityIssuesByImpactHttpHandler#ISSUES_BY_IMPACT_URI_TEMPLATE}.
     */
    private static final String EXAMPLE_URL = "Try this: curl -i localhost:9991/coverity-proxy/projects/JenkinsMaxviewStreams/issues?impact=High";

    private CallbackHandler authnHandler ;

    private WebServer server;


    private CoverityProxy(CallbackHandler authnHandler) {
        super();
        this.authnHandler = authnHandler;
    }

    /**
     * <p>
     * Requires <i>user</i> and <i>password</i> arguments.  Password should be in clear text.
     */ 
    public static void main(String[] args) throws InterruptedException, ExecutionException  
    {
        // The root logger's handlers default to INFO. We have to
        // crank them up. We could crank up only some of them
        // if we wanted, but we will turn them all up.
        java.util.logging.Handler[] handlers = Logger.getLogger("")
                .getHandlers();

        for (int index = 0; index < handlers.length; index++)
        {
            handlers[index].setLevel(Level.ALL);
        }

        CallbackHandler authnHandler = new AuthnCallbackHandler(args[0], args[1]);      
        CoverityProxy proxy = new CoverityProxy(authnHandler);
        proxy.start();

        ShutdownCoverityProxy shutdownThread = new ShutdownCoverityProxy(proxy);
        Runtime.getRuntime().addShutdownHook(new Thread(shutdownThread));
    }

    void start()
    throws InterruptedException, ExecutionException
    {
        WebServer webServer = new NettyWebServer(9991);
        Rest rest = new Rest(webServer);
        rest.GET(CoverityIssuesByImpactHttpHandler.ISSUES_BY_IMPACT_URI_TEMPLATE, new CoverityIssuesByImpactHttpHandler(authnHandler));

        server = webServer.start().get();

        System.out
                .println(EXAMPLE_URL);

    }

    void stop()
    throws InterruptedException, ExecutionException
    {
        server.stop().get();
    }

    private static final class ShutdownCoverityProxy implements Runnable
    {
        private CoverityProxy coverityProxy ;

        private ShutdownCoverityProxy(CoverityProxy coverityProxy) {
            super();
            this.coverityProxy = coverityProxy;
        }

        public void run() 
        {
            LOG.fine("Shutdown hook was invoked. Shutting down App1.");
            try {
                coverityProxy.stop();
            } catch (Exception e) {
                LogRecord lr = new LogRecord(Level.SEVERE, "THROW");
                lr.setMessage("problem checking shutting down CoverityProxy");
                lr.setSourceClassName(ShutdownCoverityProxy.class.getName());
                lr.setSourceMethodName("stopCoverityProxy");
                lr.setThrown(e);
                LOG.log(lr);
            }
        }       
    }

}

CoverityIssuesByImpactHttpHandler.java

package com.somecompany.somepkg;

import java.io.Closeable;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.webbitserver.HttpControl;
import org.webbitserver.HttpHandler;
import org.webbitserver.HttpRequest;
import org.webbitserver.HttpResponse;
import org.webbitserver.rest.Rest;

import com.coverity.ws.v6.ConfigurationService;
import com.coverity.ws.v6.ConfigurationServiceService;
import com.coverity.ws.v6.DefectService;
import com.coverity.ws.v6.DefectServiceService;

/**
 * Handles REST requests for ISSUES_BY_IMPACT_URI_TEMPLATE. 
 * @author Administrator
 *
 */
final class CoverityIssuesByImpactHttpHandler implements HttpHandler
{
    private static final Logger LOG = Logger.getLogger(CoverityIssuesByImpactHttpHandler.class.getName());

    static {
        LOG.setLevel(Level.ALL) ;
    }

    private CallbackHandler authnCallback ;
    /**
     * <p>
     * URI Template for Coverity issues filtered by Impact.
     * 
     * <p>
     * URI Templates are specified in the "Internet Engineering Task Force Request for Comments 6570 URI Template".
     * 
     * @see http://dev.pageseeder.com/glossary/URI_Pattern.html
     * @see http://tools.ietf.org/html/rfc6570
     * @see http://www.weborganic.org/furi.html
     * @see http://code.google.com/p/wo-furi/
     * @see http://dev.pageseeder.com/glossary.html
     */
    static final String ISSUES_BY_IMPACT_URI_TEMPLATE = "/coverity-proxy/projects/{projectName}/issues/impacts/{impact}";


    public CoverityIssuesByImpactHttpHandler(CallbackHandler anAuthnCallback) {
        super();
        this.authnCallback = anAuthnCallback ;
    }

    public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl control)
    throws Exception
    {
        Object projectName = Rest.param(req, "projectName");
        Object impact = Rest.param(req, "impact");

        Client configClient = null;
        Client defectClient = null;
        try
        {
            NameCallback userCallback = new NameCallback("Enter Coverity Connect user:");
            authnCallback.handle( new NameCallback[] {userCallback} );
            String user = userCallback.getName();

            Map<String, Object> outProps = new HashMap<String, Object>();
            outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.TIMESTAMP);
            outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);            
            outProps.put(WSHandlerConstants.USER, user);
            outProps.put(WSHandlerConstants.PW_CALLBACK_REF, authnCallback);

            ConfigurationService configurationServicePort = null;
            DefectService defectServicePort = null;
            try
            {
                ConfigurationServiceService configurationServiceService = new ConfigurationServiceService(new URL("http://192.168.180.3:8081/ws/v6/configurationservice?wsdl"));
                configurationServicePort = configurationServiceService.getConfigurationServicePort();
                configClient = ClientProxy.getClient(configurationServicePort) ;
                org.apache.cxf.endpoint.Endpoint configEndpoint = configClient.getEndpoint();
                configEndpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

                DefectServiceService defectServiceService = new DefectServiceService(new URL("http://192.168.180.3:8081/ws/v6/defectservice?wsdl"));
                defectServicePort = defectServiceService.getDefectServicePort();
                defectClient = ClientProxy.getClient(defectServicePort);
                org.apache.cxf.endpoint.Endpoint defectEndpoint = defectClient.getEndpoint();
                defectEndpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

                CoverityWebserviceClient coverity = new CoverityWebserviceClient(configurationServicePort,
                        defectServicePort);

                List<Long> issues = coverity.getIssuesByImpact( String.valueOf(projectName), String.valueOf(impact) );

                coverity = null;

                res.content(String.format("%d", issues.size())).end();

            }
            catch (Exception e)
            {
                LogRecord lr = new LogRecord(Level.SEVERE, "THROW");
                lr.setMessage("problem checking metrics");
                lr.setSourceClassName(this.getClass().getName());
                lr.setSourceMethodName("handleHttpRequest");
                lr.setThrown(e);
                LOG.log(lr);

                // Also re-throw it so that the Jenkins groovy-post-build plugin
                // Will know we failed

                throw e;
            }
            finally
            {
                try
                {
                    if (configurationServicePort instanceof Closeable)
                    {
                        ((Closeable) configurationServicePort).close();
                    }
                }
                finally
                {
                    if (defectServicePort instanceof Closeable)
                    {
                        ((Closeable) defectServicePort).close();
                    }
                }
            }
        }
        finally
        {
            try
            {
                if (null != configClient)
                {
                    configClient.destroy();
                }
            }
            finally
            {            
                if (null != defectClient)
                {
                    defectClient.destroy();
                }            
            }
        }
    }
}

Here are the webbit artifact versions...

        <groupId>org.webbitserver</groupId>
        <artifactId>webbit</artifactId>
        <version>0.4.12</version>
        <scope>compile</scope>

        <groupId>org.webbitserver</groupId>
        <artifactId>webbit-rest</artifactId>
        <version>0.3.0</version>
        <scope>compile</scope>
@buzz3791
Copy link
Author

buzz3791 commented Oct 1, 2013

Also posted about this issue here https://groups.google.com/forum/#!topic/webbit/4MZkpPL7cY4/discussion. No responses yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant