0

I have created a simple java service in kony app.When i try to run the Test with input parameter i got the following exception.

java.lang.ClassCastException: com.kony.sample.KonyServerConnection cannot be cast to com.konylabs.middleware.common.JavaService
    at com.konylabs.middleware.connectors.JavaConnector.execute(JavaConnector.java:142)
    at com.pat.tool.keditor.editors.JavaServiceDefinitionEditorPage.getJavaResponse(JavaServiceDefinitionEditorPage.java:1878)
    at com.pat.tool.keditor.editors.JavaServiceDefinitionEditorPage$InvokeJavaOperation.run(JavaServiceDefinitionEditorPage.java:1842)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

i followed this Link for reference

i have shared some of java code

 private static final String URL = "http://serverurl/sendEmail?";  


 public static String getServerPersponce(String entitiy,String mHeader){
        String responseBody = "";
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(URL);
        System.out.println("Requesting : " + httppost.getURI());

        try {
          StringEntity entity = new StringEntity(entitiy);

          if(mHeader != null && !mHeader.equalsIgnoreCase(""))
          httppost.addHeader("AuthToken" , mHeader);
          httppost.setEntity(entity);
          httppost.setHeader("Accept", "application/json");
          httppost.setHeader("Content-type", "application/json");
          HttpResponse response = httpclient.execute(httppost);
          HttpEntity entity1 = response.getEntity();
          InputStream stream = entity1.getContent();
           responseBody = getStringFromInputStream(stream);

            if (response.getStatusLine().getStatusCode() != 200) {
                // responseBody will have the error response
            }
          //responseBody = httpclient.execute(httppost, responseHandler);

          System.out.println("responseBody : " + responseBody);

        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          httpclient.getConnectionManager().shutdown();
        }
        return responseBody;
      }
    public static void main(String[] args) throws Exception {
        String data = "{\"CC\":[\"yuvarajag@gmail.com\"],\"Content\":\"sample string 2\",\"Subject\": \"sample string 1\",\"To\": [\"yuvarajag@gmail.com\",\"sakumarr@gmail.com\",]}";
        String result  = getServerPersponce(data, accessToken);
        System.out.println("Result "+result);
    } 

    // convert InputStream to String
        private static String getStringFromInputStream(InputStream is) {

            BufferedReader br = null;
            StringBuilder sb = new StringBuilder();

            String line;
            try {

                br = new BufferedReader(new InputStreamReader(is));
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                }

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            return sb.toString().trim();

        }

This java code is working fine. after creating a jar i included this jar to the Kony app.I am getting exception in kony java service integration.

Yuvaraja
  • 715
  • 6
  • 22

2 Answers2

1

In the code specified there is no implementation of com.konylabs.middleware.common.JavaService2 class. JavaService will work if you implement JavaService2 class in your class file and override its invoke meathod.

below is the sample:

public class <YOUR CLASS NAME> implements JavaService2 {
@Override
public Object invoke(String serviceId, Object[] arg1,
    DataControllerRequest arg2, DataControllerResponse arg3)
    throws Exception {
    // YOUR LOGIC
    return result;
}

}

0

Kony JavaConnector expects classes that implements JavaServer or JavaService2. Apparently com.kony.sample.KonyServerConnection does not implements them.

Awan Biru
  • 373
  • 2
  • 10