我已经创建了一个REST适配器来尝试从我的API发送和接收数据。我可以通过定义参数来发出POST请求并获取数据,但如果我尝试将一个正文部分包含在post请求中,即使它是一个空白的有效字符串,POST请求也会超时。
以下是我收到的超时消息: (我已经尝试将超时时间更改为3600秒并将其保留,并且在一小时后仍然超时。)
{
"errors": [
"Invocation of procedure 'getCompanies' has timed out after 30 sec."
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}
java堆栈跟踪如下。我可以毫无问题地向同一个端点发出GET / POST请求。它实际上向我的API发出请求,然后我得到回复。使用正文发布POST不会触发我的终结点。任何帮助将不胜感激。
这是一个没有正文的工作POST:
function getCompanies() {
var input = {
method : 'post',
returnedContentType : 'json',
path : 'API/companies',
parameters: {
api_env : "dev",
api_recordtype": "company",
api_action": "GET",
api_accept": "json",
api_fields": "companyname,meta_universalid",
},
headers: {
contentType : 'application/json',
accept : 'application/json',
Authorization : 'Basic amFsbGVuOm5lbGxhMTIz'
},
};
return WL.Server.invokeHttp(input);
}
这是一个导致超时问题的POST :(无论我将什么作为正文内容,它都会超时,所以我尝试将其缩小为空白字符串并且它仍然超时。)
function getCompanies() {
var input = {
method : 'post',
returnedContentType : 'json',
path : 'API/companies',
parameters: {
api_env : "dev",
api_recordtype": "company",
api_action": "GET",
api_accept": "json",
api_fields": "companyname,meta_universalid",
},
headers: {
contentType : 'application/json',
accept : 'application/json',
Authorization : 'Basic amFsbGVuOm5lbGxhMTIz'
},
body: {
contentType : 'application/json',
content : '{}'
},
};
return WL.Server.invokeHttp(input);
}
这是我正在使用的适配器:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed Materials - Property of IBM
5725-I43 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<wl:adapter name="RESTAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">
<displayName>RESTAdapter</displayName>
<description>RESTAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>api.demo.com</domain>
<port>80</port>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>
<procedure name="getCompany"/>
<procedure name="getCompanies" />
</wl:adapter>
Java stacktrace。
[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project JacobsJQMApp]RESTAdapter/HttpRequestFWLSE0100E: parameters: [project JacobsJQMApp]
Http request failed: java.net.SocketTimeoutException: Read timed out
FWLSE0101E: Caused by: [project JacobsJQMApp]java.net.SocketTimeoutException: Read timed outjava.lang.RuntimeException: Http request failed: java.net.SocketTimeoutException: Read timed out
at com.worklight.adapters.http.HTTPConnectionManager.execute(HTTPConnectionManager.java:241)
at com.worklight.adapters.http.HttpClientContext.doExecute(HttpClientContext.java:178)
at com.worklight.adapters.http.HttpClientContext.execute(HttpClientContext.java:162)
at com.worklight.adapters.http.HTTP.execRequest(HTTP.java:144)
at com.worklight.adapters.http.HTTP.invoke(HTTP.java:133)
at com.worklight.integration.model.ProcedureInvoker.invokeProcedure(ProcedureInvoker.java:57)
at com.worklight.integration.model.Procedure.invoke(Procedure.java:166)
at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:169)
at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:38)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.worklight.integration.model.InvocationContext$DirectExecutorService.execute(InvocationContext.java:284)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at com.worklight.integration.model.InvocationContext.submit(InvocationContext.java:138)
at com.worklight.integration.model.InvocationContextManager.submitInvocation(InvocationContextManager.java:58)
at com.worklight.integration.services.impl.DataAccessServiceImpl.callProcedure(DataAccessServiceImpl.java:497)
at com.worklight.integration.services.impl.DataAccessServiceImpl.access$100(DataAccessServiceImpl.java:56)
at com.worklight.integration.services.impl.DataAccessServiceImpl$4.execute(DataAccessServiceImpl.java:392)
at com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:76)
at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeProcedureInternal(DataAccessServiceImpl.java:389)
at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeDynamicProcedure(DataAccessServiceImpl.java:456)
at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeDynamicProcedureWithEnclosingProcedureProperties(DataAccessServiceImpl.java:440)
at com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation.invokeDynamicProcedureWithEnclosingProcedureProperties(JavaScriptIntegrationLibraryImplementation.java:136)
at sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:52)
at org.mozilla.javascript.gen._integration_js_1._c_anonymous_10(/integration.js:95)
at org.mozilla.javascript.gen._integration_js_1.call(/integration.js)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
at org.mozilla.javascript.gen.C_3A_5CUsers_5Cjallen_5CVirtual_Machines_5Cworkspace_5CJacobsJQMApp_5Cadapters_5CRESTAdapter_RESTAdapter_impl_js_65._c_getCompanies_2(C%3A%5CUsers%5Cjallen%5CVirtual+Machines%5Cworkspace%5CJacobsJQMApp%5Cadapters%5CRESTAdapter/RESTAdapter-impl.js:48)
at org.mozilla.javascript.gen.C_3A_5CUsers_5Cjallen_5CVirtual_Machines_5Cworkspace_5CJacobsJQMApp_5Cadapters_5CRESTAdapter_RESTAdapter_impl_js_65.call(C%3A%5CUsers%5Cjallen%5CVirtual+Machines%5Cworkspace%5CJacobsJQMApp%5Cadapters%5CRESTAdapter/RESTAdapter-impl.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen.C_3A_5CUsers_5Cjallen_5CVirtual_Machines_5Cworkspace_5CJacobsJQMApp_5Cadapters_5CRESTAdapter_RESTAdapter_impl_js_65.call(C%3A%5CUsers%5Cjallen%5CVirtual+Machines%5Cworkspace%5CJacobsJQMApp%5Cadapters%5CRESTAdapter/RESTAdapter-impl.js)
at com.worklight.integration.js.JavaScriptManager.callFunction(JavaScriptManager.java:240)
at com.worklight.integration.js.JavaScriptManager.invokeFunction(JavaScriptManager.java:214)
at com.worklight.integration.js.JavaScriptManager.invokeFunction(JavaScriptManager.java:194)
at com.worklight.integration.services.impl.AdapterManagerImpl.invokeFunction(AdapterManagerImpl.java:104)
at com.worklight.integration.js.JavaScriptProcedureInvoker.invoke(JavaScriptProcedureInvoker.java:42)
at com.worklight.integration.model.ProcedureInvoker.invokeProcedure(ProcedureInvoker.java:57)
at com.worklight.integration.model.Procedure.invoke(Procedure.java:166)
at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:169)
at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:38)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at com.worklight.server.util.ProjectLocal$1RunnableWrapper.run(ProjectLocal.java:267)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:264)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at com.worklight.adapters.http.HTTPConnectionManager.execute(HTTPConnectionManager.java:239)
... 49 more
com.worklight.common.log.filters.ErrorFilter
答案 0 :(得分:0)
在Worklight适配器中创建的过程的默认“超时秒数”为30秒。这就是你30秒后超时的原因。 请修改您的超时时间如下:
<procedure name="getCompanies" requestTimeoutInSeconds="120" />