3

I'm beginner for using JPOS with ISO8583. At this time, I try my application using Spring to build the request using JPOS where I want to send it to BASE24.

Here my code for build :

public class BuildISO {

    public void sentISOMsg(String hostname, int portNumber) {

    // Create Packager based on XML that contain DE type
    GenericPackager packager;
    ASCIIChannel channel;

    try {
        packager = new GenericPackager("packager/iso93ascii.xml");
        channel = new ASCIIChannel(hostname, portNumber, packager);

        ISOMUX isoMux = new ISOMUX(channel) {
            @Override
            protected String getKey(ISOMsg m) throws ISOException {
                return super.getKey(m);
            }
        };

        new Thread(isoMux).start();

        // Create ISO Message
        ISOMsg isoRequest = new ISOMsg(); 
        isoRequest.setMTI("1800");
        isoRequest.set(3, "123456");
        isoRequest.set(7, new SimpleDateFormat("yyyyMMdd").format(new Date()));
        isoRequest.set(11, "000001");
        isoRequest.set(12, new SimpleDateFormat("HHmmss").format(new Date()));
        isoRequest.set(13, new SimpleDateFormat("MMdd").format(new Date()));
        isoRequest.set(48, "Tutorial ISO 8583 Dengan Java");
        isoRequest.set(70, "001");

        ISORequest req = new ISORequest(isoRequest);
        isoMux.queue(req);

        ISOMsg isoReply = req.getResponse(50*1000);

        if (isoReply != null) {
            System.out.println("Req ["+new String(isoRequest.pack()) + "]");
            System.out.println("Res ["+new String(isoReply.pack()) + "]");
        }


        // print the DE list
        logISOMsg(isoRequest);

        // Get and print the output result
        byte[] data = isoRequest.pack();
        System.out.println("RESULT : " + new String(data));
    } catch (ISOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

    private static void logISOMsg(ISOMsg msg) {

    System.out.println("----ISO MESSAGE-----");
    try {
        System.out.println("  MTI : " + msg.getMTI());
        for (int i=1;i<=msg.getMaxField();i++) {
            if (msg.hasField(i)) {
                System.out.println("    Field-"+i+" : "+msg.getString(i));
            }
        }
    } catch (ISOException e) {
        e.printStackTrace();
    } finally {
        System.out.println("--------------------");
    }
}
}

and next, while I want to call that class in here :

public @ResponseBody ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String hostname = request.getParameter("hostname");
    int portNumber = Integer.parseInt(request.getParameter("portNumber"));

    System.out.println("handleRequest... : " + hostname + " : " + portNumber);

    BuildISO buildISO = new BuildISO();
    buildISO.sentISOMsg(hostname, portNumber);

    return null;
}

I got error like this :

SEVERE: Servlet.service() for servlet spring threw exception
java.lang.ClassNotFoundException: org.jpos.iso.ISOException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at org.sprint.controller.HandleController.handleRequest(HandleController.java:28)
    at org.sprint.controller.HandleController$$FastClassByCGLIB$$fc3d18c.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
    at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    at org.sprint.controller.HandleController$$EnhancerByCGLIB$$fbdc3830.handleRequest(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:722)

I have searched through StackOverflow's already asked questions, but have not found any of the situations in which the changes to the project were NONE. So I am feeling quite frustrated now because I have actually changed NOTHING and my project has stopped working. Help me please, any ideas would be grateful.

Allan
  • 33
  • 1
  • 3

2 Answers2

1

You should be sure that you have all jars in the CLASSPATH. In your case it is jpos.jar. And they all (with Spring) should be loaded withing the same classloader.

And one more advice: add -verbose option to the java (I guess Tomcat) to see from where your classes are loaded.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Sory, but i cant understand with "should be loaded withing the same classloader". What is it mean, sir? Should I register this jpos.jar (here, I use jpos-1.9.0.jar) in some properties? But, I don't know which is properties. Thank's for ur response. – Allan Jul 01 '14 at 08:29
  • There is just enough to place all your jars in the `WEB-INF/lib` – Artem Bilan Jul 01 '14 at 11:06
  • If I use pom for Maven, should I still place my jar in WEB-INF/lib sir? Thank's for ur response. – Allan Jul 02 '14 at 02:01
  • Yes, of course. `Maven` is just a tool to build and manage your project. But in the end you have an application, which you'll send to the customer. His application server (Tomcat) should have all jars, which you have used to build your app. That's why a tipical way to place the, all withing `WEB-INF/lib` of your app. – Artem Bilan Jul 02 '14 at 08:10
0

Please add the maven jpos dependency to you project.

<dependency>
    <groupId>org.jpos</groupId>
    <artifactId>jpos</artifactId>
    <version>1.9.4</version>
</dependency>

Choose any one of the repository available from maven Maven Repository Link

ganaraj
  • 420
  • 3
  • 13