Author: veithen Date: Mon Oct 12 18:59:31 2015 New Revision: 1708203 URL: http://svn.apache.org/viewvc?rev=1708203&view=rev Log: Initial implementation of MTOM attachment streaming.
Added: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java (with props) Modified: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java webservices/axiom/experimental/axiom-spring-integration/src/test/java/org/apache/axiom/spring/integration/WebServiceOutboundGatewayTest.java webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml Added: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java?rev=1708203&view=auto ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java (added) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java Mon Oct 12 18:59:31 2015 @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.axiom.spring.integration; + +import java.io.IOException; + +import javax.activation.DataHandler; + +import org.apache.axiom.util.stax.xop.MimePartProvider; +import org.springframework.oxm.UnmarshallingFailureException; +import org.springframework.oxm.mime.MimeContainer; + +final class MimePartProviderAdapter implements MimeContainer { + private final MimePartProvider provider; + + MimePartProviderAdapter(MimePartProvider provider) { + this.provider = provider; + } + + @Override + public boolean isXopPackage() { + return true; + } + + @Override + public boolean convertToXopPackage() { + throw new UnsupportedOperationException(); + } + + @Override + public void addAttachment(String contentId, DataHandler dataHandler) { + throw new UnsupportedOperationException(); + } + + @Override + public DataHandler getAttachment(String contentId) { + if (contentId.charAt(0) == '<' && contentId.charAt(contentId.length()-1) == '>') { + contentId = contentId.substring(1, contentId.length()-1); + } + try { + return provider.getDataHandler(contentId); + } catch (IOException ex) { + throw new UnmarshallingFailureException("Failed to retrieve attachment with content ID " + contentId, ex); + } + } +} Propchange: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/MimePartProviderAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java?rev=1708203&r1=1708202&r2=1708203&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/main/java/org/apache/axiom/spring/integration/WebServiceOutboundGateway.java Mon Oct 12 18:59:31 2015 @@ -25,6 +25,7 @@ import java.net.URL; import java.text.ParseException; import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stax.StAXSource; import org.apache.axiom.attachments.Attachments; @@ -37,11 +38,16 @@ import org.apache.axiom.om.OMXMLBuilderF import org.apache.axiom.soap.SOAPFactory; import org.apache.axiom.soap.SOAPMessage; import org.apache.axiom.soap.SOAPModelBuilder; +import org.apache.axiom.util.stax.xop.XOPEncodedStream; +import org.apache.axiom.util.stax.xop.XOPUtils; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; +import org.springframework.oxm.mime.MimeContainer; +import org.springframework.oxm.mime.MimeMarshaller; +import org.springframework.oxm.mime.MimeUnmarshaller; public final class WebServiceOutboundGateway extends AbstractReplyProducingMessageHandler { private final OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(); @@ -83,15 +89,30 @@ public final class WebServiceOutboundGat soapMessage.serializeAndConsume(out, format); out.close(); ContentType contentType = new ContentType(connection.getContentType()); + XMLStreamReader reader; + MimeContainer mimeContainer; if (contentType.getMediaType().equals(MediaType.MULTIPART_RELATED)) { SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder( new Attachments(connection.getInputStream(), contentType.toString())); - return unmarshaller.unmarshal(new StAXSource(builder.getSOAPEnvelope().getBody().getFirstElement().getXMLStreamReader(false))); + reader = builder.getSOAPEnvelope().getBody().getFirstElement().getXMLStreamReader(false); + if (marshaller instanceof MimeMarshaller) { + XOPEncodedStream xopEncodedStream = XOPUtils.getXOPEncodedStream(reader); + reader = xopEncodedStream.getReader(); + mimeContainer = new MimePartProviderAdapter(xopEncodedStream.getMimePartProvider()); + } else { + mimeContainer = null; + } + } else { + // TODO + return null; + } + if (mimeContainer != null) { + return ((MimeUnmarshaller)unmarshaller).unmarshal(new StAXSource(reader), mimeContainer); + } else { + return unmarshaller.unmarshal(new StAXSource(reader)); } } catch (IOException | XMLStreamException | ParseException ex) { throw new MessageDeliveryException(requestMessage, ex); } - // TODO - return null; } } Modified: webservices/axiom/experimental/axiom-spring-integration/src/test/java/org/apache/axiom/spring/integration/WebServiceOutboundGatewayTest.java URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/test/java/org/apache/axiom/spring/integration/WebServiceOutboundGatewayTest.java?rev=1708203&r1=1708202&r2=1708203&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/test/java/org/apache/axiom/spring/integration/WebServiceOutboundGatewayTest.java (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/test/java/org/apache/axiom/spring/integration/WebServiceOutboundGatewayTest.java Mon Oct 12 18:59:31 2015 @@ -20,6 +20,7 @@ package org.apache.axiom.spring.integrat import javax.xml.ws.Endpoint; +import org.apache.axiom.attachments.lifecycle.DataHandlerExt; import org.apache.axiom.testutils.PortAllocator; import org.apache.axiom.testutils.activation.RandomDataSource; import org.apache.axiom.testutils.io.IOTestUtils; @@ -47,11 +48,11 @@ public class WebServiceOutboundGatewayTe FileService fileService = context.getBean(FileService.class); GetFileRequest request = new GetFileRequest(); request.setSeed(12345678); - request.setLength(4096); + request.setLength(Runtime.getRuntime().maxMemory()); GetFileResponse response = fileService.getFile(request); IOTestUtils.compareStreams( - response.getContent().getInputStream(), - new RandomDataSource(request.getSeed(), request.getLength()).getInputStream()); + ((DataHandlerExt)response.getContent()).readOnce(), "actual", + new RandomDataSource(request.getSeed(), request.getLength()).getInputStream(), "expected"); } finally { context.close(); } Modified: webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml URL: http://svn.apache.org/viewvc/webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml?rev=1708203&r1=1708202&r2=1708203&view=diff ============================================================================== --- webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml (original) +++ webservices/axiom/experimental/axiom-spring-integration/src/test/resources/org/apache/axiom/spring/integration/mtom-client-context.xml Mon Oct 12 18:59:31 2015 @@ -28,10 +28,16 @@ http://ws.apache.org/axiom/spring-integration http://ws.apache.org/axiom/schema/spring-integration.xsd"> <int:channel id="request"/> <int:gateway id="fileService" service-interface="org.apache.axiom.spring.integration.FileService" default-request-channel="request"/> - <oxm:jaxb2-marshaller id="marshaller"> - <oxm:class-to-be-bound name="org.apache.axiom.spring.integration.GetFileRequest"/> - <oxm:class-to-be-bound name="org.apache.axiom.spring.integration.GetFileResponse"/> - </oxm:jaxb2-marshaller> + <!-- TODO: can't use oxm:jaxb2-marshaller here because mtomEnabled is not supported --> + <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> + <property name="classesToBeBound"> + <array> + <value>org.apache.axiom.spring.integration.GetFileRequest</value> + <value>org.apache.axiom.spring.integration.GetFileResponse</value> + </array> + </property> + <property name="mtomEnabled" value="true"/> + </bean> <axiom:ws-outbound-gateway request-channel="request" url="http://localhost:${port}/mtom" marshaller="marshaller" unmarshaller="marshaller"/> </beans>