2017-01-11 1 views
2

스프링 통합과 함께 Jaxb2Marshaller을 사용하고 있습니다. 나는 인바운드 게이트웨이 웹 서비스를 가지고 있는데, 누군가 그것을 호출하면 자동으로 JAXB 생성 클래스로 구문 분석 할 것이다.Spring Integration 웹 서비스 - Jaxb2Marshaller - 어떻게 SAX Parser를 사용할 수 있습니까?

그러나 소스로 디버깅 할 때 DOM을 사용하여 Jaxb2Marshaller이 표시됩니다. SAX를 사용하여 XML 데이터를 Java 객체에 바인딩하는 것으로 생각했지만 SAX가 빠릅니다. 왜 Jaxb2Marshaller가 DOM을 사용합니까? 어떻게하면 SAX를 사용하도록 구성 할 수 있습니까?

나는 문서

Unmarshaller에 체크로

자료의 인스턴스를 필요로한다. 메시지 페이로드가 소스의 인스턴스가 아니면 변환이 시도됩니다. 현재 String, File 및 org.w3c.dom.Document 페이로드는 입니다. Source에 대한 사용자 정의 변환은 SourceFactory의 구현을 주입하여 지원됩니다. SourceFactory가 UnmarshallingTransformer의 속성은 기본적으로 은

SourceFactory

http://docs.spring.io/spring-integration/api/org/springframework/integration/xml/source/SourceFactory.html

에 대한 DomSourceFactory로 설정됩니다 명시 적으로 설정되지 않은 경우 주 우리는 그것을, 그것은 단지 현재 볼 수

DomSourceFactoryStringSourceFactory입니다. SaxSourceFactory은 없습니다.

SAX를 Jaxb2Marshaller과 함께 사용할 수 없으므로, 맞습니까?

미래에 SaxSourceFactory이 될 예정입니까? 아니면 절대? 내가 Jaxb2Marshaller을 확인할 때

이상한 것은, 내가 코드가 이미 SAX에게

XMLReader xmlReader = null; 
    InputSource inputSource = null; 

    if (source instanceof SAXSource) { 
     SAXSource saxSource = (SAXSource) source; 
     xmlReader = saxSource.getXMLReader(); 
     inputSource = saxSource.getInputSource(); 
    } 
    else if (source instanceof StreamSource) { 
     StreamSource streamSource = (StreamSource) source; 
     if (streamSource.getInputStream() != null) { 
      inputSource = new InputSource(streamSource.getInputStream()); 
     } 
     else if (streamSource.getReader() != null) { 
      inputSource = new InputSource(streamSource.getReader()); 
     } 
     else { 
      inputSource = new InputSource(streamSource.getSystemId()); 
     } 
    } 

을 처리 참조, 내가 SAX와 JAXB와 함께 봄의 통합 웹 서비스를 사용하여 구성 할 수있는 마지막 질문은? 내가 놓친 게 있니?

여기 내 구성입니다 :

<ws:inbound-gateway id="inbound-gateway" request-channel="RequestChannel" reply-channel="ResponseChannel" 
     marshaller="marshaller"  unmarshaller="marshaller" /> 
<int:channel id="RequestChannel" /> 
<int:channel id="ResponseChannel" /> 

<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> 
    <property name="contextPath" value="com.example.webservice.api"/> 
</bean> 

이 이름 MessageDispatcherServlet.DEFAULT_MESSAGE_FACTORY_BEAN_NAME으로 AxiomSoapMessageFactory 콩을 구성,

+0

@lexicore 당신이 :-)에 나를 도울 수 –

+0

색소폰 빨리하지 않습니다 .. . 색소폰은 종종 사용자 정의 구현에 필요한 모든 추가 응용 프로그램 논리 때문에 느립니다. –

+0

오해가있는 것 같습니다. 당신은''를 보여 주지만'UnmarshallingTransformer'에 대해서 이야기합니다. 첫 번째 것은 Spring WS'MarshallingUtils.unmarshal()'에 완전히 위임 됨 –

답변

0

시도를

냐 응웬를 당신과 안부 감사드립니다.기본적으로

는 비 정렬 화하기 전에 정확히이 일을 SaajSoapMessageFactory입니다 :

공리는 STAX을 기반으로
public Source getPayloadSource() { 
    SOAPElement bodyElement = SaajUtils.getFirstBodyElement(getSaajBody()); 
    return bodyElement != null ? new DOMSource(bodyElement) : null; 
} 

:

XMLStreamReader streamReader = getStreamReader(payloadElement); 
return StaxUtils.createCustomStaxSource(streamReader); 

그리고 class StaxSource extends SAXSource {

+0

예, 구성을 시도하고 성공했습니다^_ ^. 이제 SAX보다 StAX 파서를 사용한 JAXB 비 정렬 화. –

+0

SAX Source (JAXB가 SAXParser를 호출 할 것임)를 가지고 있기 때문에 getPayloadSource()가 SAXSource를 반환하는 타사 라이브러리를 찾아야합니다 ^^ 감사합니다. –

+0

답변을 수락하고 읽을 시간 수동으로 신중하게 –

1

내가 사용 WebServiceGatewaySupport 클래스와 WebServiceTemplate이 알아낼 때까지 AxiomSoapMessageFactory를 Bean으로 응용 프로그램 컨텍스트에 추가하려고 시도했습니다. 응용 프로그램 컨텍스트에서 WebServiceMessageFactory를로드하지 않습니다. 그래서 생성자를 추가로 결국 :

public class SomeServiceImpl extends WebServiceGatewaySupport implements SomeService { 

    public SomeServiceImpl(WebServiceMessageFactory messageFactory) { 
     super(messageFactory); 
    } 
} 

@Configuration 클래스와 자신을 서비스를 구축 :

@Configuration 
public class WebServicesConfiguration { 

    private WebServiceMessageFactory webServiceMessageFactory = new AxiomSoapMessageFactory(); 

    @Bean 
    public SomeService someService() { 
     return new SomeServiceImpl(webServiceMessageFactory); 
    } 
} 
관련 문제