Server returned unexpected status code: 500 - with java11 template
s22saeid opened this issue · 0 comments
I've deployed a function using java11 templates and tried to add external dependencies according to the example in https://blog.alexellis.io/java-comes-to-openfaas/. When I invoked the function I got the following error:
Server returned unexpected status code: 500 -
Current Behaviour
Server returned unexpected status code: 500 -
my build.gradle is :
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'distribution'}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
compile 'com.openfaas:model:0.1.1'
compile 'com.openfaas:entrypoint:0.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okio:okio:1.14.1'}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
flatDir {
dirs '../libs' }}
jar {
manifest {
attributes 'Implementation-Title': 'OpenFaaS Function',
'Implementation-Version': '1.0' }}
distributions {
main {
contents {
from jar
into('lib') {
from(project.configurations.runtime) }}}}
uploadArchives {
repositories {
flatDir {
dirs 'repos' } }}
my handler is:
package com.openfaas.function;
import com.openfaas.model.IHandler;
import com.openfaas.model.IResponse;
import com.openfaas.model.IRequest;
import com.openfaas.model.Response;
import okhttp3.OkHttpClient;
public class Handler extends com.openfaas.model.AbstractHandler{
public IResponse Handle(IRequest req) {
IResponse res = new Response();
try {
OkHttpClient client = new OkHttpClient();
okhttp3.Request request = new okhttp3.Request.Builder()
.url(req.getBody())
.build();
okhttp3.Response response = client.newCall(request).execute();
String ret = response.body().string();
res.setBody(ret);
} catch(Exception e) {
e.printStackTrace();
res.setBody(e.toString());
}
return res;
}
}
I extended the timouts for the function but the error is still there.
the yaml file is:
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
hello-java11:
lang: java11
handler: ./hello-java11
image: ----/hello-java11:latest
environment:
read_timeout: "1m5s"
write_timeout: "1m5s"
exec_timeout: "1m5s"}
Before adding external dependencies I can invoke it successfully, so I think may be the issue is with the dependencies. Any idea for how to solve it is appreciated.
Thanks.