복붙노트

[SPRING] Axiom과 Spring WS : JAXB가 MTOM 첨부 파일을 인라인합니다.

SPRING

Axiom과 Spring WS : JAXB가 MTOM 첨부 파일을 인라인합니다.

JAXB를 마샬 러 (marshaller)로 사용하고 싶습니다만, JAXB가 메시지 본문에 들어 오거나 나가는 첨부 파일을 base64 문자열로 인라인으로 삽입하므로 많은 양을 소비합니다. 자주 OutOfMemoryError로 이어집니다. 내 설정을 간략하게 설명하고 시도를 수정하고 누군가가 올바르게 할 수있게되기를 바랍니다.

Axiom은 큰 첨부 파일을 처리해야하므로 SAAJ를 메시지 팩토리로 선택했습니다. JAXB를 매개 변수의 마샬 러 (marshaller)와 엔드 포인트 메소드의 리턴 유형으로 성공적으로 사용할 수 있습니다 (첨부가 관련된 경우 제외). 이것은 그것을위한 나의 설정입니다 :

웹 서비스 설정 XML :

<beans xmlns=...>

    <context:component-scan base-package="com.example.webservice" />

    <sws:annotation-driven />

    <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>com.example.webservice.oxm.FileTestResponse</value>
                <value>com.example.webservice.oxm.FileTestRequest</value>
            </list>
        </property>
        <property name="mtomEnabled" value="true"/>
    </bean>

    <bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
        <property name="payloadCaching" value="true"/>
        <property name="attachmentCaching" value="true"/>
    </bean>

    <sws:dynamic-wsdl id="fileTest" portTypeName="fileTest" locationUri="/webservice/fileTest/" targetNamespace="http://example.com/webservice/definitions" >
        <sws:xsd location="/WEB-INF/fileTest.xsd" />
    </sws:dynamic-wsdl>

</beans>

내 XSD의 일부 :

<!-- I generate the marshalling classes with XJB, and using
    xmime:expectedContentTypes it correctly creates mtomData field
    with DataHandler type instead of byte[] -->
<xs:element name="fileTestRequest">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="mtomData" type="xs:base64Binary"
                xmime:expectedContentTypes="application/octet-stream"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

내 엔드 포인트 클래스 :

package com.example.webservice;

import ...

@Endpoint
@Namespace(prefix = "s", uri = FileTestEndpoint.NAMESPACE)
public class FileTestEndpoint {

    public static final String NAMESPACE = "http://example.com/webservice/schemas";

    @PayloadRoot(localPart = "fileTestRequest", namespace = NAMESPACE)
    @ResponsePayload
    public FileTestResponse fileTest(@RequestPayload FileTestRequest req) throws IOException {
        // req.getMtomData() and do something with it
        FileTestResponse resp = new FileTestResponse();
        DataHandler dataHandler = new DataHandler(new ByteArrayDataSource("my file download data".getBytes(), "text/plain"));
        resp.setData(dataHandler);
        return resp;
    }
}

따라서이 코드는 작동하지만 첨부 파일과 같이 작동하지는 않습니다. 나는 workign 해결책을위한 약간 시간을 찾고있다 :

분명히 WSS4J에서 발생하는 인라이닝 문제에 관해 게시 한 다른 질문과 관련하여 가장 도움이되었습니다. 블레이즈 던 (Blaise Doughan)은 AttachmentMarshaller와 AttachmentUnmarshaller가 블로그에서 게시 한 것처럼 적절하게 처리되도록 (un) marshaller를 설정해야한다고 말했습니다.

따라서 첨부 마샬 러가이 문제를 해결하는 열쇠라고 가정합니다.

(un) marshaller에서 그들을 설정하기 위해, 나는 다른 방법을 찾지 못했지만 Jaxb2Marshaller를 확장하고 initJaxbMarshaller와 initJaxbUnmarshaller를 상속 받았다. 주어진 마샬 러에게 부착 마샬 러 (Doughan의 코드를 복사했다.)를 설정했다.

하지만 내 자신의 Jaxb2Marshaller는 수동으로 설정하는 경우조차 사용되지 않습니다. 주석 중심 :

<sws:annotation-driven marshaller="jaxb2Marshaller" unmarshaller="jaxb2Marshaller"/>

<bean id="jaxb2Marshaller" class="com.example.webservice.MyJaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>com.example.webservice.oxm.FileTestResponse</value>
            <value>com.example.webservice.oxm.FileTestRequest</value>
        </list>
    </property>
    <property name="mtomEnabled" value="true"/>
</bean>

이 marshaller 클래스가 생성되었지만 사용 된 적이없는 이유는 모르겠지만 AttachmentMarshallers가 문제를 해결할 수 있는지 테스트 할 수 없습니다.

이것이 내가 지금 말할 수있는 전부입니다. 시도 할 수있는 몇 가지 방법이 있습니다.

나는이 문제에 대해 오랜 시간을 보냈으며 명백한 해결책을 놓치고 있어야합니다. 어떤 도움이라도 대환영입니다.

감사!

라이브러리 버전 :

App 서버는 Java 1.6.0u14가 포함 된 Oracle 11g R1 Patchset 1입니다.

해결법

    from https://stackoverflow.com/questions/11564899/spring-ws-with-axiom-jaxb-is-inlining-mtom-attachments by cc-by-sa and MIT license