Great MIME and SOAP application

I have a simple web services server that receives SOAP with a MIME application, saves it in a HashMap and sends a message back with this mime attachment:

If I send a request with a small attachment (<80MB), everything is fine, but when I send a request with an attachment> 80 MB, the DataHandler object is NULL. Therefore, it is not parsed using the query and is not stored in the HashMap. It doesn’t matter if I turned on mimepull, if so, a large attachment is stored in a temporary folder on the hard drive.

MimePull Enabled:

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

Expanded GlassFish Stream Pools:

 "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 } 

package-info.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; } } 

schema.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
source share

Source: https://habr.com/ru/post/1484204/


All Articles