Learn JPOS Part 4 throw rest service to Host

This part actually my experiment to throw rest message to host we will using spring boot as RestFul service and using those service to throw ISOMsg as JSON data upon the request on web.

If you read the previous tutorial (Part 3) the code almost same instead we add new QBean to run webservice when Q2 start.

QBean XML for webservice

<qrest class="com.gl.qbean.QRestService">

</qrest>

QBean class

Actually the Qbean class contain spring boot run method.

import org.jpos.q2.QBeanSupport;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * Created by ggpratama on 10/9/2015.
 */
@SpringBootApplication
@ComponentScan(basePackages = "com.gl")
public class QRestService extends QBeanSupport {
    @Override
    protected void startService() throws Exception {
        SpringApplication app = new SpringApplication();
        app.setShowBanner(true);
        app.run(QRestService.class);
    }

}

Controller

The controller will accept get request from localhost:8080/ismsg/

import com.gl.entity.ISOMsgE;
import com.gl.repository.Repository;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by ggpratama on 10/8/2015.
 */
@RestController
public class ISORestController {
    @RequestMapping(value = "/isomsg",method = RequestMethod.GET)
    public ISOMsgE getMessageRest(){
        Repository repository = Repository.getInstance();
        ISOMsg isoMsg = repository.getISOMessage();
        ISOMsgE isoMsgE = new ISOMsgE();
        try {
            //Buat test aja
            isoMsgE.setField0(isoMsg.getMTI());
            isoMsgE.setField11(isoMsg.getString(11));
            isoMsgE.setField3(isoMsg.getString(3));
            isoMsgE.setField4(isoMsg.getString(4));

        } catch (ISOException e) {
            e.printStackTrace();
        }
        return isoMsgE;
    }


}

Entity class

public class ISOMsgE {
    //Test
    private String field0;
    private String field3;
    private String field4;
    private String field7;
    private String field11;
    private String field12;
    private String field13;
    private String field15;
    private String field32;
    private String field39;
    private String field41;
    private String field42;
    private String field48;

    //Getter and Setter

}

That’s it at last you can checkout the code at https://github.com/Gemuruh-Geo/Learn-JPOS.git and chose SimpleListenerRestfulService project

 
71
Kudos
 
71
Kudos

Now read this

Learn JPOS Part 1

Hi Today I am moving to new company and as part of my work I need to learn switching framework that is JPOS. Today I am start to read the JPOS documentation and try to write some blog post as way to remember and learn. In the first part... Continue →