복붙노트

[SPRING] Spring WS : XSD 유효성 검사 오류를 얻고 저장하는 방법

SPRING

Spring WS : XSD 유효성 검사 오류를 얻고 저장하는 방법

나는 비누 서비스를 위해 SpringWS를 사용하고 이것을 이렇게 검증한다.

 <sws:interceptors>
    <bean id="payloadValidatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
        <property name="schema" value="/schemas/my.xsd"/>
        <property name="validateRequest" value="false"/>
        <property name="validateResponse" value="true"/>
    </bean>

@PayloadRoot(namespace = NAMESPACE,  localPart = "ServiceProvider")
@ResponsePayload
public ServiceProviderTxn getAccountDetails(@RequestPayload ServiceProviderrequest)
{ ...}

이것은 정상적으로 작동하지만 오류가있을 때 엔드 포인트에 도달하기 전에 스프링이 생성 한 오류 응답을 리턴하므로 절대로 처리 할 기회가 없습니다. 하지만 데이터베이스에 전체 오류 메시지를 기록하고 저장할 수 있기를 원합니다. 내가 찾은 한 가지 방법은 내 다른 질문에서 이와 같은 것을하는 것이다.

Spring WS 유효성 검사 실패시 모든 오류 메시지를받는 방법

하지만 원하는대로 작동하지 않습니다.

해결법

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

    1.PayloadValidationInterceptor를 확장하고 메소드를 다시 정의 할 수 있습니다.

    PayloadValidationInterceptor를 확장하고 메소드를 다시 정의 할 수 있습니다.

    protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
    

    표준 구현 (여기에서 사용 가능)을 보면 모든 파싱 오류를 어떻게 덤프하는지 알 수 있습니다. messageContext 및 getRequest () 메소드에 액세스 할 수 있으므로 수신 메시지를 덤프 할 수도 있습니다. 너의 수업은 뭔가있을거야.

    public class PayloadValidationgInterceptorCustom extends
    PayloadValidatingInterceptor {
    
    @Override
    protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
            throws TransformerException {
        messageContext.getRequest().writeTo(/*place your Outputstream here something like a ByteArrayOutputStream*/); //use this if you want to dump the message
        for (SAXParseException error : errors) {
            //dump the each error on the db o collect the stack traces in a single string and dump only one or to the database
           /*you can use something like this
             StringWriter sw = new StringWriter();
             PrintWriter pw = new PrintWriter(sw);
             error.printStackTrace(pw);
             sw.toString();
             to get the stack trace
            */
    
        }
        return super.handleRequestValidationErrors(messageContext,errors);
    
    }
    
  2. from https://stackoverflow.com/questions/30666479/spring-ws-how-to-get-and-save-xsd-validation-errors by cc-by-sa and MIT license