02-04-2016 04:04 AM
Hi,
I got error while accessing an audio URL, throwing an error.badfetch. But the prompt is available at the particular URL.
Here is the java code i used in dynamic voice element.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import org.w3c.dom.NodeList;
import com.audium.server.AudiumException;
import com.audium.server.proxy.VoiceElementInterface;
import com.audium.server.session.ActionElementData;
import com.audium.server.session.ElementAPI;
import com.audium.server.xml.ElementConfigException;
import com.audium.server.xml.VoiceElementConfig;
import com.audium.server.xml.VoiceElementConfig.AudioGroup;
import com.audium.server.xml.VoiceElementConfig.StaticAudio;
/**
* This class would be called if the voice element configuration is to be
* dynamically generated. Note that the interface to implement is named
* VoiceElementInterface for backwards compatibility purposes.
*/
public class Current_Balance implements VoiceElementInterface
{
/**
* This method is expected to assemble the completed voice element
* configuration. It receives the base configuration created by Audium
* Builder for Studio which this method can edit to represent the desired
* configuration. If no base configuration is defined in the Builder, the
* third argument to the method is null. ElementAPI is used to interface
* with the system such as creating variables.
*/
public VoiceElementConfig getConfig(String name, ElementAPI data, VoiceElementConfig defaults) throws AudiumException
{
//set up the Audio prompts for the initial audio
VoiceElementConfig.AudioGroup initialAudioGroup;
//If no audio exists yet, then create an initial audio group. Else add to existing.
if(defaults.getAudioGroup("initial_audio_group",1) == null)
{
initialAudioGroup = defaults.new AudioGroup("initial_audio_group", true);//true=allow bargein
}
else
{
initialAudioGroup = defaults.getAudioGroup("initial_audio_group",1);
}
try
{
property_fetch pf = new property_fetch();
String Max_Bal = pf.getivrconfigProp("MAX_BALANCE_LIMIT");
String Balance = (String) data.getSessionData("Balance");
String Lan = (String) data.getSessionData("Language");
data.addToLog("Audio Path-------------->", Lan);
get_amt_pmt(defaults,Balance,initialAudioGroup, data);
//data.getSessionData(Balance);
SimpleDateFormat sdf1 = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss");
Date date1 = new Date();
String Res_Time = sdf1.format(date1);
// dbtest(UCID, CLID, Req_Time, Res_Time, rtncode, data);
}
catch (NullPointerException e){
data.addToLog("Null Pointer Exception ---------->","Err");
}
// Alter defaults or create a new configuration and return.
defaults.setAudioGroup(initialAudioGroup);
return defaults;
}
private void get_amt_pmt(VoiceElementConfig defaults, String amount, VoiceElementConfig.AudioGroup initialAudioGroup, ElementAPI data) throws ElementConfigException
{
URL url = null;
String[] arr = null;
property_fetch pf = new property_fetch();
String ErrorAudio = pf.getivrconfigProp("ErrorPath");
try
{
String Lan = (String) data.getSessionData("Language");
data.addToLog("Audio Path-------------->", Lan);
if(Lan.equalsIgnoreCase("English"))
{
data.addToLog("Preffered Audio Path is---------->", Lan);
String EnglishURL = pf.getivrconfigProp("English_URL");
url = new URL(EnglishURL+amount+"");
}
else if(Lan.equalsIgnoreCase("Hindi"))
{
data.addToLog("Preffered Audio Path is----------->", Lan);
String HindiURL = pf.getivrconfigProp("Hindi_URL");
url = new URL(HindiURL+amount+"");
}
else if(Lan.equalsIgnoreCase("Bengali"))
{
data.addToLog("Preffered Audio Path is----------->", Lan);
String BengaliURL = pf.getivrconfigProp("Bengali_URL");
url = new URL(BengaliURL+amount+"");
}
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String file = "";
String line = null;
while ((line = br.readLine()) != null)
{
// System.out.println(line);
file += line;
}
arr = file.split(",");
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if(arr!=null)
{
for(int i=0;i<arr.length;i++)
{
data.addToLog("Array Value------------->",arr[i]);
}
for(int i = 0; i<arr.length; i++)
{
VoiceElementConfig.StaticAudio prompt1 = defaults.new StaticAudio(null, arr[i]);
prompt1.setUseDefaultAudioPath(false);
initialAudioGroup.addAudioItem(prompt1);
}
}
else
{
VoiceElementConfig.StaticAudio prompt1 = defaults.new StaticAudio(null, ErrorAudio);
initialAudioGroup.addAudioItem(prompt1);
}
}
}
Thanks in advance.
Solved! Go to Solution.
03-15-2016 10:30 AM
What is the URL for the audio file? Could we check that is is well formed?
03-15-2016 10:30 AM
What is the URL for the audio file? Could we check that is is well formed?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide