2013-05-06 2 views
2

RESTful API를 호스트하는 웹 서버로 Jetty를 임베드하는 애플리케이션이 있습니다. 우분투에서 이클립스에서 개발 해왔고, IDE에서 시작하면 모든 것이 잘 돌아 간다. 그러나 애플리케이션을 패키징하고 서버에 배치하면 더 이상 요청에 응답하지 않습니다.Eclipse에서 임베디드 jetty가 요청을 처리하지만 배치되지 않았습니다.

서버가 지정한 포트에서 소켓을 열고 spring-mvc에 대한 INFO 로깅을 켜면 내 컨트롤러가 표시되고 적절히 매핑됩니다. 요청이 연결을 성공적으로 열었지만 아무 데이터도 되돌려 보내지지 않으며 요청이 내 컨트롤러 코드로 전송되지 않습니다. 응용 프로그램을 종료하면 모든 연결이 끊어집니다.

Eclipse 프로젝트의 클래스 경로에있는 모든 라이브러리가 전개 될 때 클래스 경로에 있는지 점검했습니다. 이클립스에서 작동하는 이유를 알아 내기 위해 무엇을 확인해야합니까?

부두는 버전 9, Java 버전 1.7, 스프링 3.2.2입니다.

2013-05-06 09:40:30,214 DEBUG [email protected]{HTTP/1.1}{0.0.0.0:8090} [SelectorManager.java submit]-: <Queued change [email protected]f589> 
2013-05-06 09:40:30,215 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java runChange]-: <Running change [email protected]f589> 
2013-05-06 09:40:30,217 DEBUG qtp1215430550-29-selector-2 [AbstractEndPoint.java onOpen]-: <onOpen [email protected]{/127.0.0.1:39895<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{false,null},[email protected]{IDLE},it=30000}{null}{io=0,kio=0,kro=0}> 
2013-05-06 09:40:30,220 DEBUG qtp1215430550-29-selector-2 [IdleTimeout.java checkIdleTimeout]-: <[email protected]{/127.0.0.1:39895<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{false,null},[email protected]{IDLE},it=30000}{null}{io=0,kio=0,kro=0} idle timeout check, elapsed: 3 ms, remaining: 29997 ms> 
2013-05-06 09:40:30,221 DEBUG qtp1215430550-29-selector-2 [HttpConnection.java <init>]-: <New HTTP Connection [email protected]{IDLE},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}> 
2013-05-06 09:40:30,224 DEBUG qtp1215430550-29-selector-2 [AbstractConnection.java onOpen]-: <onOpen [email protected]{IDLE},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}> 
2013-05-06 09:40:30,227 DEBUG qtp1215430550-29-selector-2 [AbstractConnection.java fillInterested]-: <fillInterested [email protected]{IDLE},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}> 
2013-05-06 09:40:30,229 DEBUG qtp1215430550-29-selector-2 [SelectChannelEndPoint.java updateLocalInterests]-: <Local interests updated 0 -> 1 for [email protected]{/127.0.0.1:39895<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{true,[email protected]},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=1,kio=0,kro=0}> 
2013-05-06 09:40:30,232 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java createEndPoint]-: <Created [email protected]{/127.0.0.1:39895<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{true,[email protected]},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=1,kio=0,kro=0}> 
2013-05-06 09:40:30,233 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java runChange]-: <Running change [email protected]> 
2013-05-06 09:40:30,233 DEBUG qtp1215430550-29-selector-2 [SelectChannelEndPoint.java setKeyInterests]-: <Key interests updated 0 -> 1> 
2013-05-06 09:40:30,234 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java select]-: <Selector loop waiting on select> 
2013-05-06 09:40:30,234 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java select]-: <Selector loop woken up from select, 1/1 selected> 
2013-05-06 09:40:30,234 DEBUG qtp1215430550-29-selector-2 [SelectChannelEndPoint.java setKeyInterests]-: <Key interests updated 1 -> 0> 
2013-05-06 09:40:30,238 DEBUG qtp1215430550-29-selector-2 [SelectChannelEndPoint.java updateLocalInterests]-: <Local interests updated 1 -> 0 for [email protected]{/127.0.0.1:39895<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{true,[email protected]},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=0,kio=0,kro=1}> 
2013-05-06 09:40:30,238 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java runChange]-: <Running change [email protected]> 
2013-05-06 09:40:30,239 DEBUG qtp1215430550-29-selector-2 [QueuedThreadPool.java dispatch]-: <qtp1215430550{STARTED,2<=10<=10,i=0,q=4} dispatched [email protected]> 
2013-05-06 09:40:30,240 DEBUG qtp1215430550-29-selector-2 [SelectorManager.java select]-: <Selector loop waiting on select> 
2013-05-06 09:40:35,88 DEBUG Scheduler-702565976 [IdleTimeout.java checkIdleTimeout]-: <[email protected]{/127.0.0.1:39894<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{false,null},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=0,kio=0,kro=1} idle timeout check, elapsed: 29996 ms, remaining: 4 ms> 
2013-05-06 09:40:35,96 DEBUG Scheduler-702565976 [IdleTimeout.java checkIdleTimeout]-: <SelectCha[email protected]{/127.0.0.1:39894<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{false,null},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=0,kio=0,kro=1} idle timeout check, elapsed: 30005 ms, remaining: -5 ms> 
2013-05-06 09:40:35,99 DEBUG Scheduler-702565976 [IdleTimeout.java checkIdleTimeout]-: <[email protected]{/127.0.0.1:39894<r-l>/127.0.0.1:8090,o=true,is=false,os=false,[email protected]{false,null},[email protected]{IDLE},it=30000}{[email protected]{INTERESTED},g=HttpGenerator{s=START},p=HttpParser{s=START,0 of 0}}{io=0,kio=0,kro=1} idle timeout expired> 

편집 2 내 부두 서버는 모든 봄 콩으로 구성됩니다 :

<bean id="JettyServer" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop"> 

<property name="connectors"> 
    <list> 
     <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
      <property name="port" value="8090"/> 
     </bean> 
    </list> 
</property> 

<property name="handler"> 
    <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> 
     <property name="handlers"> 
      <list> 
       <bean id="servletContextHandler" class="org.eclipse.jetty.servlet.ServletContextHandler"> 
        <property name="contextPath" value="/"/> 
        <property name="servletHandler"> 
         <bean class="org.eclipse.jetty.servlet.ServletHandler"> 

          <property name="servlets"> 
           <list> 
            <bean class="org.eclipse.jetty.servlet.ServletHolder"> 
             <property name="name" value="DefaultServlet"/> 
             <property name="servlet"> 
              <bean class="com.company.project.api.DispatcherServletWrapper"/> 
             </property> 
            </bean> 
           </list> 
          </property> 
          <property name="servletMappings"> 
           <list> 
            <bean class="org.eclipse.jetty.servlet.ServletMapping"> 
             <property name="pathSpecs"> 
              <list><value>/</value></list> 
             </property> 
             <property name="servletName" value="DefaultServlet"/> 
            </bean> 
           </list> 
          </property> 
         </bean> 
        </property> 
       </bean> 
       <bean class="org.eclipse.jetty.server.handler.RequestLogHandler"> 
        <property name="requestLog"> 
         <bean class="org.eclipse.jetty.server.NCSARequestLog"> 
          <constructor-arg value="/opt/company/logs/jetty-yyyy_mm_dd.log"/> 
          <property name="extended" value="false" /> 
         </bean> 
        </property> 
       </bean> 
      </list> 
     </property> 
    </bean> 
</property> 
</bean> 

나는 디스패처 서블릿이 필요 부두에서

편집 디버그 로깅은 내가 요청을 할 때 이 Jetty 서버를 정의하는 ApplicationContext를 알고 있기 때문에 참조 용 DispatcherServletWrapper 클래스는 다음과 같습니다 :

,691,363,210
package com.company.project.api; 

import org.springframework.beans.BeansException; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.ApplicationContextAware; 
import org.springframework.web.context.WebApplicationContext; 
import org.springframework.web.context.support.GenericWebApplicationContext; 
import org.springframework.web.servlet.DispatcherServlet; 

public class DispatcherServletWrapper extends DispatcherServlet implements ApplicationContextAware { 

    private static final long serialVersionUID = -2281511575328213502L; 
    private ApplicationContext appContext; 

    @Override 
    public void setApplicationContext(ApplicationContext arg0) 
      throws BeansException { 
     this.appContext = arg0; 
    } 

    protected WebApplicationContext createWebApplicationContext(WebApplicationContext arg0) { 
     GenericWebApplicationContext wac = new GenericWebApplicationContext(); 
     wac.setParent(appContext); 
     wac.refresh(); 

     return wac; 
    } 

} 
+0

필자는 내 개발 환경이 프로덕션 서버와 완전히 동일한 JRE를 사용하고 있고 IDE 클래스 경로가 exa와 일치하는지 확인했습니다 서버에서 실행할 때 클래스 경로를 지정하십시오. 서버는 CentOS 5.9를 실행합니다. Jetty 서버가 예상대로 작동하고 CentOS 6.4 서버에서 예상대로 내 요청과 결과를 처리하는 것을 발견했습니다. JRE와 클래스 경로가 동일하므로 내 응용 프로그램이 "java - cp $ (classpath variable) com.company.project.Main "다른 어떤 점이 그것이 내 우분투 개발 환경과 6.4 서버에서 작동하도록하지만 5.9가 아닌가? – tdimmig

+0

이동할 정보가 충분하지 않습니다. 부두를 어떻게 * 시작했는지 표시하지 않았습니다. 부두를 시작하는 방법에 대한 몇 가지 코드를 포함시킬 수 있습니까?'Server' 인스턴스로 무엇을 할 것인가? 당신은'server.start()'와'server.join()'을하거나 프로젝트에서 서버 쓰레드를 다르게 관리합니까? –

+0

Jetty 8 (커넥터에 대해 다른 클래스가 필요하고 라이브러리 스왑 이외의 다른 변경 사항이 필요하지 않음)로 전환하고 모든 것이 작동합니다. 필자는 앞서 언급 한 여러 다른 플랫폼에서 작동했던 Jetty 9가 완벽한 폭풍우 조합으로 인해 부서 졌음을 알지 못합니다. 그러나 Jetty 8을 백업하면 배치 플랫폼에서 작동하므로 이동 방향이됩니다. 방법을 알고 있다면이 질문을 닫거나 삭제할 수 있습니다. 의견을 보내 주셔서 감사합니다, 나는 누군가에게 도움에 관심을 보여 주셔서 감사드립니다. – tdimmig

답변

1

아 커넥터 부두 9부터 부두 9

으로 변경된 커넥터이다 연결 유형과 감지 폴백을 제공 ConnectionFactory에의 체인과 빌드 업.

이것은 대체 웹 연결 유형 (예 : TLS 확장, NPN, SPDY, WebSocket 및 심지어 HTTP/2.0 준비)의 현대적인 현실을 지원하기 위해 수행되었습니다. 부두에서 SSL + NPN + SPDY/3 + SPDY/2 + HTTPS 용 커넥터 체인을 구성 부두 9

package org.eclipse.jetty.embedded; 

import org.eclipse.jetty.server.Server; 
import org.eclipse.jetty.server.ServerConnector; 

public class OneConnector 
{ 
    public static void main(String[] args) throws Exception 
    { 
     // The Server 
     Server server = new Server(); 

     // HTTP connector 
     ServerConnector http = new ServerConnector(server); 
     http.setHost("localhost"); 
     http.setPort(8080); 
     http.setIdleTimeout(30000); 

     // Set the connector 
     server.addConnector(http); 

     // Set a handler 
     server.setHandler(new HelloHandler()); 

     // Start the server 
     server.start(); 
     server.join(); 
    } 
} 

에 표준 HTTP 커넥터 구성

: 여기

몇 가지 내장 예입니다 9

package org.eclipse.jetty.embedded; 

import org.eclipse.jetty.server.HttpConfiguration; 
import org.eclipse.jetty.server.HttpConnectionFactory; 
import org.eclipse.jetty.server.SecureRequestCustomizer; 
import org.eclipse.jetty.server.Server; 
import org.eclipse.jetty.server.ServerConnector; 
import org.eclipse.jetty.server.SslConnectionFactory; 
import org.eclipse.jetty.spdy.server.NPNServerConnectionFactory; 
import org.eclipse.jetty.spdy.server.SPDYServerConnectionFactory; 
import org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory; 
import org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy; 
import org.eclipse.jetty.util.ssl.SslContextFactory; 

public class SpdyConnector 
{ 
    public static void main(String[] args) throws Exception 
    { 
     String jetty_home = System.getProperty("jetty.home","../../jetty-distribution/target/distribution"); 
     System.setProperty("jetty.home", jetty_home); 

     // The Server 
     Server server = new Server(); 

     // HTTP Configuration 
     HttpConfiguration http_config = new HttpConfiguration(); 
     http_config.setSecureScheme("https"); 
     http_config.setSecurePort(8443); 

     // HTTP connector 
     ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(http_config));   
     http.setPort(8080); 
     server.addConnector(http); 

     // SSL Context Factory for HTTPS and SPDY 
     SslContextFactory sslContextFactory = new SslContextFactory(); 
     sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore"); 
     sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); 
     sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); 

     // HTTPS Configuration 
     HttpConfiguration https_config = new HttpConfiguration(http_config); 
     https_config.addCustomizer(new SecureRequestCustomizer()); 

     // SPDY versions 
     HTTPSPDYServerConnectionFactory spdy2 = 
      new HTTPSPDYServerConnectionFactory(2,https_config); 

     HTTPSPDYServerConnectionFactory spdy3 = 
      new HTTPSPDYServerConnectionFactory(3,https_config,new ReferrerPushStrategy()); 

     // NPN Factory 
     SPDYServerConnectionFactory.checkNPNAvailable(); 
     NPNServerConnectionFactory npn = 
      new NPNServerConnectionFactory(spdy3.getProtocol(),spdy2.getProtocol(),http.getDefaultProtocol()); 
     npn.setDefaultProtocol(http.getDefaultProtocol()); 

     // SSL Factory 
     SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,npn.getProtocol()); 

     // SPDY Connector 
     ServerConnector spdyConnector = 
      new ServerConnector(server,ssl,npn,spdy3,spdy2,new HttpConnectionFactory(https_config)); 
     spdyConnector.setPort(8443); 
     server.addConnector(spdyConnector); 

     // Set a handler 
     server.setHandler(new HelloHandler()); 

     // Start the server 
     server.start(); 
     server.join(); 
    } 
} 
+0

코드 샘플과 제티 서버를 시작하는 방법을 보여주는 XML로 내 질문을 업데이트했습니다. 9 포트에서 Jetty 8로 다시 전환 할 때 변경해야하는 구성의 유일한 부분임을 표시하기 위해 커넥터 차이점을 언급했습니다. 내 개발 환경과 CentOS에서 서버가 버전 9로 예상대로 작동했습니다. 6 서버. CentOS 5 서버에서는 작동하지 않습니다. Jetty 8로 다시 전환하면 어디서나 사용할 수 있습니다. 소프트웨어의 완벽한 폭풍으로 인해 제티 9 버전의 프로젝트가 실패하게 될지 모르지만 시간이 부족합니다. – tdimmig

+0

도움을 주려는 노력에 감사 드리며, 시도한 3 가지 플랫폼 중 2 가지에서 작동한다는 점을 고려할 때 구성 문제라고 생각하지 않습니다. – tdimmig