mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
pass handler name to java
This commit is contained in:
parent
11cf69bd80
commit
d9c986e97f
@ -118,10 +118,10 @@ class AwsInvokeLocal {
|
||||
|| this.serverless.service.provider.runtime
|
||||
|| 'nodejs4.3';
|
||||
const handler = this.options.functionObj.handler;
|
||||
const handlerPath = handler.split('.')[0];
|
||||
const handlerName = handler.split('.')[1];
|
||||
|
||||
if (runtime.startsWith('nodejs')) {
|
||||
const handlerPath = handler.split('.')[0];
|
||||
const handlerName = handler.split('.')[1];
|
||||
return this.invokeLocalNodeJs(
|
||||
handlerPath,
|
||||
handlerName,
|
||||
@ -130,6 +130,8 @@ class AwsInvokeLocal {
|
||||
}
|
||||
|
||||
if (runtime === 'python2.7' || runtime === 'python3.6') {
|
||||
const handlerPath = handler.split('.')[0];
|
||||
const handlerName = handler.split('.')[1];
|
||||
return this.invokeLocalPython(
|
||||
process.platform === 'win32' ? 'python.exe' : runtime,
|
||||
handlerPath,
|
||||
@ -139,9 +141,12 @@ class AwsInvokeLocal {
|
||||
}
|
||||
|
||||
if (runtime === 'java8') {
|
||||
const className = handler.split('::')[0];
|
||||
const handlerName = handler.split('::')[1] || 'handleRequest';
|
||||
return this.invokeLocalJava(
|
||||
'java',
|
||||
handler,
|
||||
className,
|
||||
handlerName,
|
||||
this.serverless.service.package.artifact,
|
||||
this.options.data,
|
||||
this.options.context);
|
||||
@ -177,11 +182,12 @@ class AwsInvokeLocal {
|
||||
});
|
||||
}
|
||||
|
||||
callJavaBridge(artifactPath, className, input) {
|
||||
callJavaBridge(artifactPath, className, handlerName, input) {
|
||||
return new BbPromise((resolve) => fs.statAsync(artifactPath).then(() => {
|
||||
const java = spawn('java', [
|
||||
`-DartifactPath=${artifactPath}`,
|
||||
`-DclassName=${className}`,
|
||||
`-DhandlerName=${handlerName}`,
|
||||
'-jar',
|
||||
path.join(__dirname, 'java', 'target', 'invoke-bridge-1.0.jar'),
|
||||
]);
|
||||
@ -201,7 +207,7 @@ class AwsInvokeLocal {
|
||||
}));
|
||||
}
|
||||
|
||||
invokeLocalJava(runtime, className, artifactPath, event, customContext) {
|
||||
invokeLocalJava(runtime, className, handlerName, artifactPath, event, customContext) {
|
||||
const timeout = Number(this.options.functionObj.timeout)
|
||||
|| Number(this.serverless.service.provider.timeout)
|
||||
|| 6;
|
||||
@ -220,7 +226,7 @@ class AwsInvokeLocal {
|
||||
const executablePath = path.join(javaBridgePath, 'target');
|
||||
|
||||
return new BbPromise(resolve => fs.statAsync(executablePath)
|
||||
.then(() => this.callJavaBridge(artifactPath, className, input))
|
||||
.then(() => this.callJavaBridge(artifactPath, className, handlerName, input))
|
||||
.then(resolve)
|
||||
.catch(() => {
|
||||
const mvn = spawn('mvn', [
|
||||
@ -235,7 +241,8 @@ class AwsInvokeLocal {
|
||||
mvn.stderr.on('data', (buf) => this.serverless.cli.consoleLog(`mvn - ${buf.toString()}`));
|
||||
mvn.stdin.end();
|
||||
|
||||
mvn.on('close', () => this.callJavaBridge(artifactPath, className, input).then(resolve));
|
||||
mvn.on('close', () => this.callJavaBridge(artifactPath, className, handlerName, input)
|
||||
.then(resolve));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@ -379,6 +379,7 @@ describe('AwsInvokeLocal', () => {
|
||||
expect(invokeLocalJavaStub.calledWithExactly(
|
||||
'java',
|
||||
'handler.hello',
|
||||
'handleRequest',
|
||||
undefined,
|
||||
{},
|
||||
undefined
|
||||
@ -588,6 +589,7 @@ describe('AwsInvokeLocal', () => {
|
||||
awsInvokeLocalMocked.callJavaBridge(
|
||||
__dirname,
|
||||
'com.serverless.Handler',
|
||||
'handleRequest',
|
||||
'{}'
|
||||
).then(() => {
|
||||
expect(writeChildStub.calledOnce).to.be.equal(true);
|
||||
@ -625,6 +627,7 @@ describe('AwsInvokeLocal', () => {
|
||||
awsInvokeLocal.invokeLocalJava(
|
||||
'java',
|
||||
'com.serverless.Handler',
|
||||
'handleRequest',
|
||||
__dirname,
|
||||
{}
|
||||
).then(() => {
|
||||
@ -632,6 +635,7 @@ describe('AwsInvokeLocal', () => {
|
||||
expect(callJavaBridgeStub.calledWithExactly(
|
||||
__dirname,
|
||||
'com.serverless.Handler',
|
||||
'handleRequest',
|
||||
JSON.stringify({
|
||||
event: {},
|
||||
context: {
|
||||
@ -694,6 +698,7 @@ describe('AwsInvokeLocal', () => {
|
||||
awsInvokeLocalMocked.invokeLocalJava(
|
||||
'java',
|
||||
'com.serverless.Handler',
|
||||
'handleRequest',
|
||||
__dirname,
|
||||
{}
|
||||
).then(() => {
|
||||
@ -701,6 +706,7 @@ describe('AwsInvokeLocal', () => {
|
||||
expect(callJavaBridgeMockedStub.calledWithExactly(
|
||||
__dirname,
|
||||
'com.serverless.Handler',
|
||||
'handleRequest',
|
||||
JSON.stringify({
|
||||
event: {},
|
||||
context: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user