Http возвращает 500 через API-шлюз - PullRequest
0 голосов
/ 14 октября 2019

Я работал над HTTP-вызовом, который вернет объект Mp3Base64. У меня работает авторизация, поэтому он определенно бьет по API Gateway, но теперь он возвращает 500. Кто-нибудь может сказать мне, где я ошибаюсь?

Метод executePost создает http в моей программе переднего плана. У меня есть модель с именем Mp3Base64, в которой есть только строка, которую я отправляю как json. ServiceCollectHttp находится в бэкэнд-программе в лямбда-функции AWS для сбора http и отправки Mp3Base64 обратно.

Наконец, у меня есть ApplicationHandler для целевого http в функции лямбда-AWS.

public String executePost(String targetURL, Mp3Base64 mp3Base64) throws IOException {

ObjectMapper mapper = new ObjectMapper();
String mp3Base64Json = mapper.writeValueAsString(mp3Base64);
URL obj = new URL(targetURL);
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
        "application/x-www-form-urlencoded");

connection.setRequestProperty("Content-Length",
        Integer.toString(mp3Base64Json.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");

connection.setUseCaches(false);
connection.setDoOutput(true);
//Add authorizer
connection.setRequestProperty("key","keyValue");

//Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes("base64=" + mp3Base64Json);
wr.flush();
wr.close();

//Get Response
int responseCode = connection.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + targetURL);
System.out.println("Post parameters : base64 =" + mp3Base64Json);
System.out.println("Response Code : " + responseCode);
InputStream is = connection.getInputStream();     
BufferedReader in = new BufferedReader(
        new InputStreamReader(connection.getInputStream()));
String inputLine
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();

//print result
System.out.println(response.toString());
return response.toString();
}

@Path("/default/AudibleTranscribe")
public class ServiceCollectHttp {

@POST
//Make it create a json 
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) 
//Attach the query parameter that has to be added
public Response getBase64(
@QueryParam("base64") String base64) throws JsonProcessingException {
System.out.println(base64);
ObjectMapper mapper = new ObjectMapper();
mapper.readValue(base64, Mp3Base64.class);
return Response.status(Response.Status.OK).entity(base64).build();
}

public class Mp3Base64 {

private String base64;
public String getBase64() {
return base64;
}

public void setBase64(String base64) {
this.base64 = base64
}
}

public class ApplicationHandler implements RequestStreamHandler {

private static final ResourceConfig jerseyApplication = new ResourceConfig()
    .packages("transcribe.back")
    .property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true)
    .property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true)
    .register(JacksonFeature.class);

private static final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
    = JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, 
Context context) throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...