web stats
Custom web service class initialization failed - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2016, 09:29 AM
tmcdevitt tmcdevitt is offline
OBX.3 Kenobi
 
Join Date: Oct 2014
Posts: 125
tmcdevitt is on a distinguished road
Smile 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";
            }
        }
    }

}
Reply With Quote
  #2  
Old 09-22-2016, 02:38 AM
byc844 byc844 is offline
What's HL7?
 
Join Date: Mar 2016
Posts: 4
byc844 is on a distinguished road
Default

The service class name is com.MirthCustomWebService.CustomAcceptMessage
not com.MirthCustomWebService.Main
Reply With Quote
  #3  
Old 09-22-2016, 08:37 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
custom web service

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation