Skip to content

Add support for MediaType for EDIFACT and EDI-X12 [SPR-14707] #19272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Sep 13, 2016 · 4 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: task A general task

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 13, 2016

Dawud Tan (陳大衛) opened SPR-14707 and commented

Currently, there are no support for the MIME type application/EDIFACT and application/EDI-X12, these MIME types are the most used in B2B environments, after that we could add support for EDIFACTHttpMessageConverter same as ProtobufHttpMessageConverter ##10477.

thanks.


Affects: 4.3.3

Reference URL: https://tools.ietf.org/html/rfc1767

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

There are many media types out there, and our MediaType has a few static instances for those. But the end goal is not to add as much as possible - in fact, we're only adding a few there that are not only very common but also have a specific support in Spring.

Note that some of those aren't even listed in the MediaType class itself, but rather in their respective MessageConverters, like ProtobufHttpMessageConverter.

In your case, you can create your own instance like this:

MediaType EDIFACT = new MediaType("application", "edifact");

Are there Java open source libraries already supporting that format?
As this is the very first time we're asked about such a feature, we'll need many votes and uses cases to think about spending time on this.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 18, 2016

Dawud Tan (陳大衛) commented

well, AFAIK, this MIME type is in very common use on the B2B environment such as retailers and its suppliers like between WalMart, Amazon and SlimFast as their supplier, following are their corresponding guide Walmart Getting Started with EDI Implementation Guide, Amazon EDI Self Service Setup guide, but they transfer this file format using EDIINT AS2 (RFC 4130), but I hardly to find a solution that already integrate this AS2 protocol into spring. So, I would like to exchange this file format with my trading partner using spring mvc instead, that offer a lot of flexibility. AFAIK there is one Java open source library already supporting this format that is

dependencies {
   compile 'org.milyn:milyn-smooks-edi:1.4'
   compile 'org.milyn.edi.unedifact:d01b-binding:1.4'
}

since the time I post this jira ##19272 I've tried to implement this EDIFACTHttpMessageConverter, following is my naive implementation:

package org.springframework.http.converter.edifact;

import org.milyn.edi.unedifact.d01b.D01BInterchangeFactory;
import org.milyn.smooks.edi.unedifact.model.UNEdifactInterchange;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.OutputStreamWriter;

public class EDIFACTHttpMessageConverter extends AbstractHttpMessageConverter<UNEdifactInterchange> {
    private D01BInterchangeFactory factory;

    public EDIFACTHttpMessageConverter() {
        //https://tools.ietf.org/html/rfc1767
        super(new MediaType("application", "EDIFACT"));
        try {
            this.factory = D01BInterchangeFactory.getInstance();
        } catch (IOException | SAXException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    protected UNEdifactInterchange readInternal(Class<? extends UNEdifactInterchange> clazz,
                                                HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
        return factory.fromUNEdifact(inputMessage.getBody());
    }

    @Override
    protected boolean supports(Class<?> clazz) {
        return true;
    }

    @Override
    protected void writeInternal(UNEdifactInterchange interchange,
                                 HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        factory.toUNEdifact(interchange, new OutputStreamWriter(outputMessage.getBody(), "UTF-8"));
    }
}

lastly I've push my sample Spring Boot Project into following Github repository, please if you don't mind could you take a look at it Mr. Brian Clozel

git clone https://github.com/dawud-tan/restful-edifact.git

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

I'm not saying this is not a valid use case - in fact, creating your own message converter implementation is a good place to start - you could even open source it as a library. There are probably a few things to improve in your message converter implementation (adding some test coverage, implementing the supports method properly, etc) and people could be interested in this.

For now, we really have to find the right balance in Spring. We can't just implement message converters for all formats out there, we have to focus our efforts on things that are hard/tedious to implement and very useful to the community. Judging from your initial implementation and the lack of community feedback on that format in the last years, I'd say this is not a good candidate for now.

We will reconsider this (and reopen this issue) when those conditions are met.

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Dawud Tan (陳大衛) commented

I'm Sorry if my words sounds rude, but, honestly I'm really rarely interact with foreign people in my country :( , so I have no idea when certain words have negative emotions.

Well thanks a lot for your feedback Brian Clozel, and thanks for reminds me of something that hard/tedious to implement and very useful to the community. I just wonder why AS2 (RFC 4130) protocol that widely used by large companies like WalMart and Amazon got very little attention from community, but apperently Josh Long had ever made an issue for AS2 support in spring in this issue #SESIA-17, and I also did a search for JSR that ever mention this protocol then I found JSR 67: JavaTM APIs for XML Messaging 1.0, but I'm just not sure what the big picture is, however.

thanks again for your time Brian Clozel.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants