복붙노트

[SPRING] Struts 2에서 WebSocket API 사용하기

SPRING

Struts 2에서 WebSocket API 사용하기

Tomcat 7.0.43에서 실행되는 Struts2 웹 응용 프로그램에서 Rest 및 Convention 플러그인을 사용하여 모든 요청을 매핑했습니다. Struts는 모든 요청을 자체적으로 매핑하려고합니다.

JSR 356은 다음과 같은 주석을 사용하여 서버 끝점을 정의합니다.

@ServerEndpoint(value = "/websocket/chat")

이제 브라우저가 ws : /127.0.0.1 : 8080 / websocket / chat에 연결을 시도하면 Struts 매퍼가 요청을 가로 채기 때문에 요청이 실패합니다.

요청이 올바른 위치에 도달하도록 XML 파일에 지정할 수있는 것이 있습니까?

편집하다:

제안대로, 나는

<constant name="struts.action.excludePattern" value="/websocket.*?" />

내 Struts 설정에 이어 / websocket / chat URL이 404 오류에 도달하기 시작했습니다.

나중에 ServerApplicationConfig 구현을 구성해야한다는 것을 알게되었습니다. 그렇게하면 websocket은 정상적으로 작동하기 시작하지만 나머지 응용 프로그램에서는 오류가 발생하여로드하지 못합니다.

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

여기 내 수업이 있습니다 :

public class Socket implements ServerApplicationConfig {

    @Override
    public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> scanned) {

        Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();

        return result;
    }

    @Override
    public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {

        Set<Class<?>> results = new HashSet<Class<?>>();
        for (Class<?> clazz : scanned) {
            results.add(clazz);
        }
        return results;
    }
}

하모니에서 함께 할 수있는 모든 것을 어떻게 얻을 수 있습니까?

참고 : Spring Security의 Dependency Injection을 위해 Struts Spring Plugin을 사용하고 있습니다.

해결법

  1. ==============================

    1.정규식 패턴을 통해 일부 URL을 제외하도록 Struts 필터를 구성 할 수 있습니다. struts.xml에 상수를 추가해야합니다.

    정규식 패턴을 통해 일부 URL을 제외하도록 Struts 필터를 구성 할 수 있습니다. struts.xml에 상수를 추가해야합니다.

    <constant name="struts.action.excludePattern" value="^ws://.+$"/>
    
  2. from https://stackoverflow.com/questions/20774716/using-a-websocket-api-with-struts-2 by cc-by-sa and MIT license