Giter VIP home page Giter VIP logo

java-spring-js-mtom-download's Introduction

SOAP MTOM / XOP template using Java 8, Spring, JAXB

Uploading and Downloading files is a pain in the ass. It's all hack attempts at creating fake HTML forms and fake clicking them through JavaScript just to send a specific type of file to a specific type of REST endpoint.

I had a lot of trouble figuring out the best way to do this. So I put this here for others that are looking for a quick how-to accept and send binary files through an HTTP end point, and more specifically, to send MTOM / XOP attachments in a SOAP request.

This isn't a completely running example obviously. It is a skeleton of everything you need if you want to send or receive MTOM / XOP SOAP requests.

Backend

Pretty straight forward service oriented architecture. Controller accepts a request. First, Spring unmarshalles the file into a "MultiPartFile". Controller then converts request into DTO then passes it so Service. This is where business logic goes. Then it is passed to a WebService layer where the outgoing request is made.

MTOM

MTOM or the Message Transmission Optimization Mechanism is a low overhead way of sending attachments in a SOAP message

There are only two things that you have to do in addition to normal SOAP messages:

  1. Enable MTOM. There are several ways to do this. In this example, inside the MtomClient.java class, you can see it is enabled through the JaxBMarshaller
  2. Add a SoapAction. One would expect this to happen automatically with the marshaller. That is not the case. Instead, you have to manually set the SOAPAction. Inside the MyWebService.java send() method, you can see I've added a WebServiceMessageCallback that adds it. This method gets called once the SOAP request is ready to be accepted and will tell the server where to send the message. The SOAPACtion is explicitly defined in the WSDL and it can be taken from there and hard-coded.

Front end

This is the hackiest bit. There are no natural ways to download a file through HTML and JavaScript. It takes a lot of parsing and converting, and some fake HTML forms mixed with some real ones. Someone should create a framework to make this better.
We create an object of type FormData and add a file to it. There are some good resources for creating HTML forms that accept a file online.. We just have to call the method in import-file.js when the user hits "submit" and pass the file that is selected.

java-spring-js-mtom-download's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.