5

我有一个简单的 Web 服务服务器,它接收带有 MIME 附件的 SOAP,将其存储到 HashMap 并用这个 mime 附件发回消息:

  • Java 1.7.0_13-b20
  • 春季 WS 2.1.3
  • JAXB 的 MOXy 实现 (EclipseLink 2.4.1)
  • 玻璃鱼 3.1.1
  • MIME 附件和 SOAP
  • 启用 SAAJ MimePull 以保存到硬盘
  • 基于使用 Spring WS、MTOM/XOP 和 JAXB2和 Spring WS“mtom”示例通过 SOAP 启用大文件传输
  • 由 SoapUI 测试

如果我发送带有小附件 (<80MB) 的请求,一切正常,但是当我发送带有 >80 MB 附件的请求时,DataHandler 对象为空。所以它不会从 Request 中解析出来,也不会存储到 HashMap 中。我是否启用了 mimepull 无关紧要,如果是,则大附件存储到硬盘驱动器上的临时文件夹中。

启用 MimePull:

-Dsaaj.use.mimepull=true
-Djava.io.tmpdir=/path/to/tmpdir

扩大的 GlassFish 线程池:

"Max Thread Pool Size" from 5 to 32
"Min Thread Pool Size" from 2 to 16

ImageRequest.java

package sample.mtom.schema;
@XmlRootElement
@XmlType(propOrder = {"fileName", "data"})
public class ImageRequest {

    protected String fileName;
    protected DataHandler data;

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @XmlMimeType("*/*")
    public DataHandler getData() {
        return data;
    }

    public void setData(DataHandler data) {
        this.data = data;
    }
}

ImageResponse.java

package sample.mtom.schema;
@XmlRootElement
@XmlType(propOrder = {"fileName", "data"})
public class ImageResponse {
    // the same as ImageRequest
}

包信息.java

@XmlSchema(namespace = "http://www.example.org/Image",
        elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package sample.mtom.schema;

import javax.xml.bind.annotation.XmlSchema;

StubRepository.java

package sample.mtom.service;
public class StubRepository implements Repository {

    private Map<String, DataHandler> files = new HashMap();

    public DataHandler readFile(String name) throws IOException {
        return files.get(name);
    }

    public void storeFile(String name, DataHandler file) throws IOException {
        files.put(name, file);
    }
}

ImageRepositoryEndpoint.java

package sample.mtom.ws;
@Endpoint
public class ImageRepositoryEndpoint {

    private static Repository repository;
    static {
        repository = new StubRepository();
    }

    @PayloadRoot(localPart = "imageRequest", namespace = "http://www.example.org/Image")
    @ResponsePayload
    public ImageResponse handleRequest(@RequestPayload ImageRequest request) throws IOException {
        repository.storeFile(request.getFileName(), request.getData());

        ImageResponse response = new ImageResponse();
        response.setFileName(request.getFileName());
        response.setData(repository.readFile(request.getFileName()));
        return response;
    }
}

架构.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
            targetNamespace="http://www.example.org/Image"
            elementFormDefault="qualified">

    <xsd:element name="imageRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="fileName" type="xsd:string"/>
                <xsd:element name="data" type="xsd:base64Binary" xmime:expectedContentTypes="*/*"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="imageResponse">
        <!-- the same as imageRequest -->
    </xsd:element>
</xsd:schema>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

    <display-name>MyCompany HR Holiday Service</display-name>
    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

spring-ws-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:sws="http://www.springframework.org/schema/web-services"
       xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
                           http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="sample.mtom.ws"/>

    <bean id="defaultMethodEndpointAdapter"
      class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
        <property name="methodArgumentResolvers" ref="marshallingPayloadMethodProcessor"/>
        <property name="methodReturnValueHandlers" ref="marshallingPayloadMethodProcessor"/>
    </bean>

    <bean id="marshallingPayloadMethodProcessor"
      class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
        <constructor-arg ref="jaxb2Marshaller"/>
    </bean>

    <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="packagesToScan" value="sample.mtom.schema"/>
        <property name="mtomEnabled" value="true"/>
    </bean>

    <sws:dynamic-wsdl id="image"
                      portTypeName="ImageResource"
                      locationUri="/">
        <sws:xsd location="/WEB-INF/schema.xsd"/>
    </sws:dynamic-wsdl>
</beans>
4

0 回答 0