Announcement

Collapse
No announcement yet.

Custom web service class initialization failed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom web service class initialization failed

    Hi I have created a class for a Custom web service but I am getting the error below. In my service class name I have com.MirthCustomWebService.Main and for web service I have selected custom, is there anything else I need to do?


    [2016-03-24 09:14:36,711] ERROR (com.mirth.connect.connectors.ws.WebServiceReceive r:134): Custom web service class initialization failed
    java.lang.ClassNotFoundException: com.MirthCustomWebService.Main



    Code:
    package com.MirthCustomWebService;
    import com.mirth.connect.connectors.ws.AcceptMessage;
    import com.mirth.connect.connectors.ws.WebServiceReceiver;
    
    
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    import java.io.*;
    import javax.xml.bind.DatatypeConverter;
    
    
    public class Main {
    
        public static void main(String[] args) {
            try {
            char START_OF_BLOCK = '\u000b';
            char END_OF_BLOCK = '\u001c';
            StringBuilder HL7Msg = new StringBuilder();
            HL7Msg.append(START_OF_BLOCK);
            HL7Msg.append("MSH|jkfalsjfksadl|djfaksojfkal|djkafjdksal;fjksa");
            HL7Msg.append(END_OF_BLOCK);
            //System.out.println(HL7Msg.toString().indexOf(START_OF_BLOCK));
            //System.out.println(HL7Msg.toString().indexOf(END_OF_BLOCK));
                // System.out.println(validateHL7(HL7Msg.toString()));
            boolean b = validateHL7(HL7Msg.toString());
            if (b == true){
                // System.out.println(getPDFText("OrderRegABN.pdf"));
                String str =getPDFText("OrderRegABN.pdf");
                String encoded = DatatypeConverter.printBase64Binary(str.getBytes());
                System.out.println("encoded value is \t" + encoded);
    
            }
            else
            {
                System.out.println("Error");
    
            }
    
    
    
    
           } catch (IOException e) {
               e.printStackTrace();
            }
        }
        public static String getPDFText(String pdfFile) throws IOException {
            try {
                FileReader fr = new FileReader(pdfFile);
                BufferedReader br = new BufferedReader(fr);
                int c;
                StringBuilder response= new StringBuilder();
    
    
                while ((c = br.read()) != -1) {
                    //Since c is an integer, cast it to a char. If it isn't -1, it will be in the correct range of char.
                    response.append( (char)c ) ;
                }
    
    
                return response.toString();
    
    
            }catch(Exception e){
                e.printStackTrace();
                return "Error";
            }
        }
        public static  boolean validateHL7(String HL7Msg) {
            char START_OF_BLOCK = '\u000b';
            char END_OF_BLOCK = '\u001c';
    
            /*
            String HL7MsgEndBlock = HL7Msg.substring(Math.max(HL7Msg.length() - 2, 0));
            String HL7MsgStartBlock = HL7Msg.substring(0, 2);
            */
    
            if (HL7Msg.indexOf(valueOf(START_OF_BLOCK)) >= 0)
            {
                if (HL7Msg.indexOf(valueOf(END_OF_BLOCK)) >= 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
    
    
    
        public static String valueOf(char c) {
            String str1 = Character.toString(c);
            return  str1;
        }
    
    
        @WebService
        public class CustomAcceptMessage extends AcceptMessage {
    
            public CustomAcceptMessage(WebServiceReceiver webServiceReceiver) {
                super(webServiceReceiver);
    
    
            }
    
            @WebMethod(action = "sample_operation")
            public String operation(@WebParam(name = "param_name") String param) {
                // implement the web service operation here
                return param;
            }
    
            @WebMethod(action = "add")
            public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
                int k = i + j;
                return k;
            }
    
    
    
            @WebMethod(action = "HL7OrderMessage")
            public String HL7OrderMessage(@WebParam(name = "param_name") String param) {
    
                try {
    
                    boolean b =  validateHL7(param);
    
                    if (b == true)
                    {
                        String str = getPDFText("OrderRegABN.pdf");
                        String encoded = DatatypeConverter.printBase64Binary(str.getBytes());
                        return encoded;
                    }
                  else
                    {
                        return "Error";
    
                    }
    
    
                } catch (IOException e) {
                    e.printStackTrace();
                    return "Error";
                }
            }
        }
    
    }

  • #2
    The service class name is com.MirthCustomWebService.CustomAcceptMessage
    not com.MirthCustomWebService.Main

    Comment


    • #3
      You've defined your custom AcceptMessage extension as an inner class, so the reference might be something like com.MirthCustomWebService.Main$CustomAcceptMessage . But really you should move that to its own class file.
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment

      Working...
      X