2017-01-25 7 views
1

XSD와 관련된 들어오는 XML의 유효성을 검사하는 간단한 웹 서비스 (spring-web)를 만들었습니다. 유효성 검사 오류가 발생하면 요청자에게 반환해야합니다.Unmarshaller의 동작이 일관성없는 이유는 무엇입니까?

아래 코드는 ... 그 일을

@PostMapping(path = "/test", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 
public ResponseEntity<Object> method2(@RequestBody Source request) throws IOException, JAXBException, SAXException { 

    final URL schemaUrl = resourceLoader.getResource("classpath:test.xsd").getURL(); 
    final CumulatingErrorHandler errorHandler = new CumulatingErrorHandler(); 
    final Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) 
      .newSchema(schemaUrl); 
    final ValidationEventCollector validationEventCollector = new MyValidationEventCollector(); 

    final Unmarshaller unmarshaller = JAXBContext 
      .newInstance(IncomingRequestModel.class) 
      .createUnmarshaller(); 
    unmarshaller.setEventHandler(validationEventCollector); 
    unmarshaller.setSchema(schema); 

    final IncomingRequestModel requestModel = (IncomingRequestModel) unmarshaller.unmarshal(request); 

    if (validationEventCollector.hasEvents()) { 
     HttpHeaders responseHeaders = new HttpHeaders(); 
     responseHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); 
     return new ResponseEntity<>(validationEventCollector.getEvents(), responseHeaders, HttpStatus.BAD_REQUEST); 
    } 

    /* do stuff */ 
} 

...하지만, 이상한 이유로, 처리 요청 사이의 오류를 '축적되는'입니다. 첫 번째 요청 중에 3 개의 오류가 반환됩니다. 마찬가지로, 두 번째 및 세 번째 요청. 그러나 4 요청에 UnmarshallingContext의 카운터는 영 (10 카운트 다운)에 도달하고 다음과 같은 오류가 반환됩니다 다섯 번째 요청에

Errors limit exceeded. To receive all errors set com.sun.xml.internal.bind logger to FINEST level. 

, 그것은 어떤 유효성 검사 오류가 발생하지 않습니다! 모든 요청은 정확히 동일합니다.

왜 UnmarhsallingContext에 5 + th 요청의 유효성을 검사하는 정적 카운터가 있습니까? 이 문제를 어떻게 극복 할 수 있습니까? 봄 부팅 1.4.3.RELEASE, Gradle을 deps :

내 빌드 설정

dependencies { 
    compile('org.springframework.boot:spring-boot-starter-amqp') 
    compile('org.springframework.boot:spring-boot-starter-data-redis') 
    compile('org.springframework.boot:spring-boot-starter-jersey') 
    compile('org.springframework.boot:spring-boot-starter-web') 

    compile("com.fasterxml.jackson.core:jackson-databind") 
    compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") 

    compileOnly('org.projectlombok:lombok:1.16.12') 

    compile("net.sf.dozer:dozer:5.5.1") 
    compile("net.sf.dozer:dozer-spring:5.5.1") 

    compile("org.apache.commons:commons-lang3:3.5") 

    testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

답변

0

오늘 같은 오류가 있고, JAXB의 Messages.properties에서 볼 수있는 조언을 적용하여 극복 : 호출하기 전에 java.util.logging.Logger.getLogger("com.sun.xml.internal.bind").setLevel(Level.FINEST); 추가 언 마샬링.