0

我有 2 个软件包 - 1 个在传统 Web 服务器(Tomcat 6、Websphere 7)中维护的服务器和 1 个与作为客户端工作的动态 Web 服务器 Jetty 一起维护的服务器。服务器和代理在 Windows 7 机器和 JRE 6 上本地完美运行: (1) 服务器加载到 Tomcat。(2) Agent 使用自定义端口初始化 Jetty 8 Web 服务器。

当我将它投入生产时——Linux 环境——我将 WAR 加载到 WebSphere,这似乎工作正常。我使用“jave -jar”在生产中执行了代理 jar,它似乎可以工作。在他们沟通之后 - 如果在 'java.lang.illegalstateexception: state==header' 异常上失败,则代理失败。

现在,我将 WebSphere 生产应用程序引用到我的本地机器上,所有通信都正常工作(使用 Windows 7 的本地代理,Linux 上的远程服务器)。

因此,代理(或其内部 Jetty)似乎存在问题,代码如下所示:

         private void respondOK(Request baseRequest, HttpServletResponse response)
        throws IOException {
    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    baseRequest.setHandled(true);
    response.getWriter().println("OK");
}

private boolean handleAgentMonitoringTasks( 
                                    Request baseRequest,
                                    HttpServletRequest request,
                                    HttpServletResponse response) {
    boolean didRespond = false;

    // extract the agent data   
    try {
        String reqContent = readRequestContent(baseRequest);

        // handle the input
        theAgentWorker.updateTasksList(reqContent);

    } catch (IOException e) {
        // send a response indicating the error
        respondError(baseRequest, response, "Error getting request content - " + e.getMessage(), e);
        didRespond = true;
    }


    return didRespond;
 }


 private boolean handleServerInfo(  Request baseRequest,
                                    HttpServletRequest request,
                                    HttpServletResponse response) {

    boolean didRespond = false;

    // extract the request content
    try {
        String reqContent = readRequestContent(baseRequest);

        if (reqContent.length() > 0) {
            try {
                theAgentWorker.handleServerInfoData(reqContent);
            }
            catch (Exception e) {
                respondError(baseRequest, response, "Error setting server information - " + e.getMessage(), e);
                didRespond = true;
            }
        }
        else {
            respondError(baseRequest, response, "Server address not found in the request", null);
            didRespond = true;              
        }

    } catch (IOException e) {
        // send a response indicating the error
        respondError(baseRequest, response, "Error getting request content - " + e.getMessage(), e);
        didRespond = true;
    }

    return didRespond;
 }


private String readRequestContent(Request baseRequest) throws IOException {
    BufferedReader br = baseRequest.getReader();
    StringBuilder sBuilder = new StringBuilder();
    char[] buff = new char[4092];

    int charsRead = br.read(buff, 0, buff.length);
    while (charsRead == buff.length) {
        sBuilder.append(buff);
        charsRead = br.read(buff, 0, buff.length);
    }
    sBuilder.append(buff,0, charsRead);
    return sBuilder.toString();
}

以上所有代码都进入这个类: public class AgentHttpHandler extends AbstractHandler

AbstractHandler 是 Jetty 的处理程序类。

当我研究它时,我发现 Jetty 的 getReader() 和 getInputStream() 存在问题,但我找不到合理的解释为什么它不稳定 - 在 Windows 7 中代理工作正常,在 Linux 上它有问题(我尝试了几个 Linux 服务器)。

你知道 Jetty WebServer 的某些 Linux 网络问题吗?我有更多信息,但我认为这些信息应该足够了

4

1 回答 1

0

好的,它可能关注的对象:

I decided to go over ALL WebSphere configurations - and I defined a virtual host with TCP chaining and a new port. Then, I recompiled all the packages with a new ant build.

Afterwards (and this is the most important part) - I defined the urls mentioned in the configuration file with [CDATA] and do not use localhost. Instead I used the hostnames of the server and client.

Viola, everything seems working.

于 2013-04-15T12:14:44.590 回答