Search code examples
javaspring-bootsoapiso8583jpos

What is the right place to put custom logic in JPOS?


I am working in a project where a request(ISO 8583) need to be send via JPOS server to the backed (Remote Host as per official doc) via SOAP api.

We have implemented our system as follows:

enter image description here

We implemented a ISOListner in a middle ware(spring boot project) where it converts the incoming ISO message to SOAP request.

Is it possible to embed the Middle ware code to JPOS server itself and omit the mw?

If possible , what is the right place to put our conversion logic ? Is it the ChannelAdaptor or TransactionManager ?

Few blogs suggest that we can put all logic to TransactionManager or ChannelAdaptor. If it is true then why we need mux and channel at all? Or our architecture is ok to proceed further ?


Solution

  • For the sake of completeness I will include the answer to this question that was also asked in jPOS Users group (https://groups.google.com/forum/#!topic/jpos-users/PGzb4syQRzs):

    We usually implement a custom participant doing the SOAP/REST thing.

    In the case of REST, we use Apache's HTTP Client (org.apache.httpcomponents:httpclient:4.5.5) that provides a nice async interface that works great with the TransactionManager's PAUSE.

    Here is an example:

    public int prepare (long id, Serializable o) {
            Context ctx = (Context) o;
            String url = getURL (ctx);
            HttpPost post = new HttpPost(url);
            StringEntity entity = new StringEntity(ctx.getString(JSON_REQUEST.name()),ContentType.create("application/json", Consts.UTF_8));
            post.setEntity(entity);
    
            try {
                client.execute(post, response -> {
                    int sc = response.getStatusLine().getStatusCode();
                    if (sc == HttpStatus.SC_CREATED || sc == HttpStatus.SC_OK)
                        ctx.put (JSON_RESPONSE.name(), EntityUtils.toString(response.getEntity()));
                    ctx.resume();
                    return null;
                });
                return PREPARED | PAUSE | NO_JOIN | READONLY;
            } catch (IOException e) {
                warn (e);
            }
            return ABORTED;
        }