我一直在进行HTTP调用,它将返回一个Mp3Base64
对象。我已经获得授权,因此它肯定会到达API网关,但现在返回500。有人可以告诉我我要去哪里了吗?
executePost
方法在前端程序中创建http。我有一个名为Mp3Base64
的模型,其中只有一个字符串,我将它作为json发送。 ServiceCollectHttp
在AWS Lambda函数的后端程序中,以收集http并将Mp3Base64
发回。
最后,我在AWS Lambda函数中有一个ApplicationHandler
作为http定位目标。
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);
}
}