cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1019
Views
0
Helpful
1
Replies

Implement Restful web service client in Call Studio 10.5

vincent.zheng
Level 4
Level 4

The library I use is following:

http-client-4.5.10.jar
httpcore-4.4.12.jar
httpmime-4.5.10.jar

Here is my custom java code

package com.mycompany.cvp.webservice;

import java.io.File;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.audium.server.AudiumException;
import com.audium.server.action.context.ApplicationModifier;
import com.audium.server.session.ActionElementData;

public class ItspWebServiceClient extends ApplicationModifier {

    @Override
    public String getElementName() {
        return "RestWebServiceClient";
    }

    @Override
    public String getDisplayFolderName() {
        return "My Company Elements";
    }

    @Override
    public void doAction(String name, ActionElementData actionData) throws AudiumException {
        String urlLink = (String)actionData.getSessionData("SpeechURL");
        String filePath = actionData.getElementData("PolicyNumber", "filepath");
        String filename = actionData.getElementData("PolicyNumber", "filename");
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(urlLink + "/processFile");
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addBinaryBody("file", new File(filePath), ContentType.APPLICATION_OCTET_STREAM, filename);
        HttpEntity multipart = builder.build();
        httpPost.setEntity(multipart);

        CloseableHttpResponse response;
        try {
            response = client.execute(httpPost);
            HttpEntity responseEntity = response.getEntity();
            String result = EntityUtils.toString(responseEntity);
            actionData.addToLog("SpeechRecognition", result);
            client.close();
            actionData.setSessionData("return", result);
        } catch (Exception e) {
            throw new AudiumException("Speech Recogniation exception");
        }
        super.doAction(name, actionData);
    }
}

The above code is taking the audio files and call the web service to recognize what user said, and based on the string that return back to perform following action.

 

However, when I deploy the whole project to VXMLServer, it complains following:

Error with admin application update,12/12/2019 16:27:58.085,An error has occurred. The error was: java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest
java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest
                at java.lang.Class.getDeclaredConstructors0(Native Method)
                at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
                at java.lang.Class.getConstructor0(Class.java:2803)
                at java.lang.Class.newInstance(Class.java:345)
                at com.audium.server.controller.AudiumServerConfiguration.instantiateLocalElements(AudiumServerConfiguration.java:441)
                at com.audium.server.controller.AudiumServerConfiguration.<init>(AudiumServerConfiguration.java:216)
                at com.audium.server.controller.AudiumServerConfiguration.initialize(AudiumServerConfiguration.java:1049)
                at com.audium.server.controller.Admin.cmdUpdateApp(Admin.java:326)
                at com.audium.server.controller.Admin.executeCommand(Admin.java:244)
                at com.audium.server.controller.Admin.run(Admin.java:1520)
                at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpUriRequest
                at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
                at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
                ... 11 more

 In server side I already put all the jar file into common folder, what else I need to do?

1 Accepted Solution

Accepted Solutions

Quigath
Spotlight
Spotlight

What I do:

  1. compile my code files with java 1.8.151
  2. copy my java class files into /deploy/java/application/classes/[appName]/
  3. copy my java jar files into /deploy/java/application/lib/
    1. this includes all jars my library jars/code depend on
  4. Deploy project files out to the server

View solution in original post

1 Reply 1

Quigath
Spotlight
Spotlight

What I do:

  1. compile my code files with java 1.8.151
  2. copy my java class files into /deploy/java/application/classes/[appName]/
  3. copy my java jar files into /deploy/java/application/lib/
    1. this includes all jars my library jars/code depend on
  4. Deploy project files out to the server
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: