Вызов внешнего API REST с функции лямбды в JavaJAVA

Программисты JAVA общаются здесь
Anonymous
Вызов внешнего API REST с функции лямбды в Java

Сообщение Anonymous »

Я пытаюсь написать функцию Lambda, которая получает информацию из ввода Lex, и вызывает API REST, передавая эту информацию в качестве параметра, возвращает строку, которую я затем хочу отправить в Lex в качестве ответа. Он работает так же, как и ожидалось, когда запускается в Eclipse, но когда я загружаю JAR в Amazon Lambda, она не дает ошибки, но выходная строка NULL. < /P>

public class LambdaFunctionHandler implements RequestHandler {

@Override
public Object handleRequest(Map input, Context context) {

ValidationHook.LexRequest lexRequest= LexRequestFactory.createLexRequest(input);
String orgbotcommand = lexRequest.getCommand()+"%20"+lexRequest.getType()+"%20"+lexRequest.getNew_variable();
lexRequest.setOrgbotcommand(orgbotcommand);

try {
URL url = new URL("http://localhost:8080/mindtuit/execute? ... botcommand);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
lexRequest.setResponse(output);

}
System.out.println(lexRequest.getResponse());

conn.disconnect();

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

String content = String.format("command recieved by %s is %s,response is %s ",lexRequest.getBotName(),lexRequest.getOrgbotcommand(),lexRequest.getResponse());

Message message = new Message("PlainText",content);
DialogAction dialogAction = new DialogAction("Close", "Fulfilled", message );
System.out.println(dialogAction);

return new LexRespond(dialogAction);
}
< /code>

} < /p>

Подробнее здесь: https://stackoverflow.com/questions/488 ... on-in-java

Вернуться в «JAVA»