programing

레스트렛, CLAP, Ajax 및 청크 타임아웃

showcode 2023. 3. 16. 22:03
반응형

레스트렛, CLAP, Ajax 및 청크 타임아웃

RESTlet을 사용하여 프로젝트의 작은 REST 서버를 만들고 있습니다.클래스 내에서 다수의 루트를 설정하고 있습니다.Application:

public static void createRestServer(ApplicationContext appCtx, String propertiesPath) throws Exception {

  // Create a component
  Component component = new Component();
  component.getServers().add(Protocol.HTTP, 8081);
  component.getClients().add(Protocol.FILE);
  component.getClients().add(Protocol.CLAP);

  Context context = component.getContext().createChildContext();
  RestServer application = new RestServer(context);

  application.getContext().getParameters().add("useForwardedForHeader", "true");

  application.getContext().getAttributes().put("appCtx", appCtx);
  application.getContext().getAttributes().put("file", propertiesPath);

  // Attach the application to the component and start it
  component.getDefaultHost().attach(application);
  component.start();
}

private RestServer(Context context) {
  super(context);
}

public synchronized Restlet createInboundRoot() {
  Router router = new Router(getContext());

  // we then have a bunch of these
  router.attach("/accounts/{accountId}", AccountFetcher.class); //LIST Account level
  // blah blah blah

  // finally some stuff for static files:
  //
  Directory directory = new Directory(getContext(),
     LocalReference.createClapReference(LocalReference.CLAP_CLASS, "/"));
  directory.setIndexName("index.html");
  router.attach("/", directory);

  return router;
}

문제:웹 페이지에서 Ajax를 통해 JAR에 .js 파일을 요청하면(이 JAR에서 CLAP을 통해 로드됨) 해당 파일의 처음 7737바이트만 반환되고 중단됩니다.나머지 파일을 돌려줄 수가 없어요.항상 정확히 같은 바이트 수 뒤에 정지합니다. 50분의 1은 작동합니다.

왜 걸려있는지 알아?CLAP 및 정적 파일의 청크 인코딩을 해제해도 될까요?

미치겠네.

어떤 서버 커넥터를 사용하는지 모르겠지만 기본 커넥터인 것 같습니다.

레스트렛은 다양한 수준에서 플러그 및 확장이 가능합니다.Jetty를 사용하는 것을 추천합니다.그러기 위해서는 Jetty 확장자용 JAR 파일을 추가하기만 하면 됩니다).org.restlet.ext.jetty.jar)을 클릭합니다.커넥터가 자동으로 등록되고 기본 커넥터 대신 사용됩니다.

최신 버전(2.3)으로 업그레이드하는 것도 추천합니다.

Restlet 엔진에 등록된 커넥터를 확인하려면 다음 코드를 사용합니다.

List<ConnectorHelper<Server>> serverConnectors
       = Engine.getInstance().getRegisteredServers();
for (ConnectorHelper<Server> connectorHelper : serverConnectors) {
    System.out.println("Server connector: "+connectorHelper);
}

이렇게 하고 나서 그런 문제가 생기면 안 돼요.

도움이 되길 바래, 티에리

언급URL : https://stackoverflow.com/questions/21339855/restlet-clap-ajax-and-chunk-timeouts

반응형