Vtiger 7.2 query operations to REST API returning 500 errors - vtiger

I've recently upgraded from Vtiger 6 to 7.2 (a clean installation) and all my requests to the REST API that use the query operation are no longer working. It doesn't matter which module the request is for e.g. Contacts, Leads, Accounts. All other types of operations are working e.g. retrieve, describe, but a query such as select * from Contacts where email = 'foo#bar.com'; will fail with a 500 Internal Server Error returned from the Vtiger server.
Here's an example of my HTTP request (query param is left unencoded for readability):
https://crm.myendpoint.com/webservice.php?sessionName=[mysession]&operation=query&query=select * from Contacts where email = 'foo#bar.com';
The code I'm using to make my queries is completely unmodified from when I was using version 6 of Vtiger and the requests were working fine then. I've switched on debug logging on the server but there's no errors.
The server is receiving and processing the request though. At one point, it dumps the data to the log for the Contact that I'm querying (which all looks correct), and then here's the last few lines of the logging before it ends:
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Entering isPermitted(Contacts,DetailView,) method ...
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Entering getActionid(DetailView) method ...
Mon Jan 20 17:13:41 2020,292 [8010] INFO webservice - get Actionid DetailView
Mon Jan 20 17:13:41 2020,292 [8010] INFO webservice - action id selected is 4
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Exiting getActionid method ...
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Exiting isPermitted method ...
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Entering getColumnFields(Accounts) method ...
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - in getColumnFields Accounts
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Prepared sql query being executed : SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence
FROM vtiger_field WHERE tabid in (?)
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Prepared sql query parameters : [6]
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Entering getColumnFields(Accounts) method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - in getColumnFields Accounts
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Prepared sql query being executed : select 1 from vtiger_crmentity where crmid=? and deleted=0 and setype='Accounts'
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Prepared sql query parameters : [9637]
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG user - Entering Users() method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Entering getColumnFields(Users) method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - in getColumnFields Users
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG user - Exiting Users() method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Entering getColumnFields(Users) method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - in getColumnFields Users
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select 1 from vtiger_users where id=? and deleted=0 and status='Active'
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select groupname from vtiger_groups where groupid = ?
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select first_name from vtiger_users where id = ?
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]
I was thinking that this might be some kind of permission issue, but surely the server wouldn't return a 500 in that situation. In any case, I've tried running queries with 2 different users, both of which have an admin role.
This problem only happens with query operations, irrespective of the module being queried. Is there any way I can debug this further?

This fix got it working.
In summary, non-existent method getAllAccessibleTags being called at line 199 in include/Webservices/VtigerModuleOperation.php needs to be changed to getAllAccessible.

This bug was addressed by issue #1217 Fetch tag details of records for requests made via Webservices and the fix should be included in Vtiger 7.2.1 which has not yet been released at the time of writing. Here are the changes implemented in commits 7881fde4 and 072b5cee:
include/Webservices/VtigerModuleOperation.php [176]
$result = $this->pearDB->pquery($mysql_query, array());
+ $tableIdColumn = $meta->getIdColumn();
$error = $this->pearDB->hasFailedTransaction();
include/Webservices/VtigerModuleOperation.php [191]
- if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row["crmid"])){
+ if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row[$tableIdColumn])){
include/Webservices/VtigerModuleOperation.php [194]
- $output[] = DataTransform::sanitizeDataWithColumn($row,$meta);
+ $output[$row[$tableIdColumn]] = DataTransform::sanitizeDataWithColumn($row,$meta);
modules/Vtiger/models/Tag.php [302]
+
+ /**
+ * Function used to return tags for list for records
+ * #param <Array> $records - record ids
+ * #return <Array> tags
+ */
+ public static function getAllAccessibleTags($records) {
+ $tagsList = array();
+ if(count($records) == 0) return $tagsList;
+
+ $currentUser = Users_Record_Model::getCurrentUserModel();
+
+ $db = PearDatabase::getInstance();
+ $query = "SELECT tag,object_id FROM vtiger_freetags
+ INNER JOIN vtiger_freetagged_objects ON vtiger_freetags.id = vtiger_freetagged_objects.tag_id
+ WHERE (vtiger_freetagged_objects.tagger_id = ? OR vtiger_freetags.visibility='public')
+ AND vtiger_freetagged_objects.object_id IN
+ (" . generateQuestionMarks($records) . ")";
+ $params = array($currentUser->getId());
+ $params = array_merge($params, $records);
+
+ $result = $db->pquery($query , $params);
+ $num_rows = $db->num_rows($result);
+
+
+ for($i=0; $i<$num_rows; $i++) {
+ $tagName = decode_html($db->query_result($result, $i, 'tag'));
+ $record = decode_html($db->query_result($result, $i, 'object_id'));
+
+ if(empty($tagsList[$record])) {
+ $tagsList[$record] = $tagName;
+ } else {
+ $tagsList[$record] .= ','.$tagName;
+ }
+ }
+ return $tagsList;
+ }

Related

Creating a REST API from Lambda Function

I have a Java based Lambda function that is running correctly via the Lambda test event with the following JSON:
{
"married": "true",
"wages": "200000",
"homeInterest": "15000",
"propertyTaxes": "15000",
"stateTaxes": "13000",
"otherDeductions": "4000",
"postalCode": "11762"
}
I then created an API via the Amazon API Gateway. When I paste the same JSON as the body of the generated URL none of fields map correctly.
The Lambda handler is using POJOs for the request and response:
public class TaxHandler implements RequestHandler<TaxRequest, TaxResponse>{
public TaxResponse handleRequest(TaxRequest request, Context context){
When I test via the API gateway test I see the following info:
Execution log for request test-request
Tue Dec 19 02:01:16 UTC 2017 : Starting execution for request: test-invoke-request
Tue Dec 19 02:01:16 UTC 2017 : HTTP Method: POST, Resource Path: /TaxCalculation
Tue Dec 19 02:01:16 UTC 2017 : Method request path: {}
Tue Dec 19 02:01:16 UTC 2017 : Method request query string: {}
Tue Dec 19 02:01:16 UTC 2017 : Method request headers: {}
Tue Dec 19 02:01:16 UTC 2017 : Method request body before transformations: {
"married": "true",
"wages": "200000",
"homeInterest": "15000",
"propertyTaxes": "15000",
"stateTaxes": "13000",
"otherDeductions": "4000",
"postalCode": "11762"
}
Tue Dec 19 02:01:16 UTC 2017 : Endpoint request URI: https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:896795400074:function:TaxCalculation/invocations
Tue Dec 19 02:01:16 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=************************************************************************************************************************************************************************************************************************************************************************************************************************7fcbc9, X-Amz-Date=20171219T020116Z, x-amzn-apigateway-api-id=07yp3njqzk, X-Amz-Source-Arn=arn:aws:execute-api:us-east-1:896795400074:07yp3njqzk/null/POST/TaxCalculation, Accept=application/json, User-Agent=AmazonAPIGateway_07yp3njqzk, X-Amz-Security-Token= [TRUNCATED]
Tue Dec 19 02:01:16 UTC 2017 : Endpoint request body after transformations: {"resource":"/TaxCalculation","path":"/TaxCalculation","httpMethod":"POST","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"path":"/TaxCalculation","accountId":"xxxxxxxx","resourceId":"v8358d","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"cognitoIdentityId":null,"apiKey":"test-invoke-api-key","cognitoAuthenticationType":null,"userArn":"arn:aws:iam::xxxxx:user/tvfoodmaps_aws","apiKeyId":"test-invoke-api-key-id","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_144)","accountId":"896795400074","caller":"AIDAINMSXKH5AWAQ7NX36","sourceIp":"test-invoke-source-ip","accessKey":"ASIAIHXWW4BOHGXESRNQ","cognitoAuthenticationProvider":null,"user":"AIDAINMSXKH5AWAQ7NX36"},"resourcePath":"/TaxCalculation","httpMethod":"POST","apiId":"07yp3njqzk"},"body":"{\n \"married\": \"true\",\n \"wages\": \"200000\",\n \"homeInterest\": \"15000\",\n \"propertyTa [TRUNCATED]
Tue Dec 19 02:01:16 UTC 2017 : Sending request to https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:896795400074:function:TaxCalculation/invocations
Tue Dec 19 02:01:16 UTC 2017 : Received response. Integration latency: 30 ms
Tue Dec 19 02:01:16 UTC 2017 : Endpoint response body before transformations: {"savings":565.0,"owedTaxes17":-635.0,"owedTaxes18":-1200.0,"effectiveRate17":0.0,"effectiveRate18":0.0}
Tue Dec 19 02:01:16 UTC 2017 : Endpoint response headers: {X-Amz-Executed-Version=$LATEST, x-amzn-Remapped-Content-Length=0, Connection=keep-alive, x-amzn-RequestId=7f8a1b13-e460-11e7-84cf-d1c3e8d3eaf5, Content-Length=104, Date=Tue, 19 Dec 2017 02:01:16 GMT, X-Amzn-Trace-Id=root=1-5a3872ec-1b9d875d8cc2fded5c30da46;sampled=0, Content-Type=application/json}
Tue Dec 19 02:01:16 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response
Tue Dec 19 02:01:16 UTC 2017 : Method completed with status: 502
How can I further debug why the function is not executing the same when called via REST instead of directly via the Lambda tester? Note: I know the error talks about the response but the issue is that the first line of my code reading the fields that should be mapped to the pojo aren't working (again, only when using the API).
Looks like you have your integration with ANY and not returning the proxy response. Instead you are returning the JSON object response.
Similar problem discussed here,
https://forums.aws.amazon.com/thread.jspa?threadID=255561
And the solution to configure is documented here,
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-simple-proxy-for-lambda-output-format
Hope it helps.
You can include logging in your code so that they will be available in AWS CloudWatch to investigate the issue. Following libraries and approaches are recommended by AWS according to the documentation for Java.
Custom Appender for Log4j™ 2
LambdaLogger.log(): Example 2: Writing Logs Using LambdaLogger (Java)
System.out() and System.err()
Note: Also setup API Gateway logging so that it would be easier to trace any issue end to end.

AWS API Gateway Cannot GET / when function sleeped for long time

My current stack is AWS API Gateway --> AWS Lambda --> swagger-node + swagger-express-mw + aws-serverless-express.
So my Swagger API is hosted as one node.js Lambda Function and Invoked with aws_proxy from API Gateway. This works quite good. The only thing is that when the function sleeped for too long (cold start?) I get a Cannot GET / as Output from every URL I am calling first. From 2nd Request on, it runs very fast. Any ideas on that?
I don't think that it comes from API Gateway Integration Timeout as that are 30 seconds. The slowest invocation time of the function directly via lambda is around 2,5s and when it is called more often it is normally not more than 150ms. I also increased the Time of Lambda Timeout for that function to 10s so from there should also not come an error.
Logs from Test Request via API Gateway first Invocation
Response Body
Cannot GET /hello
Response Headers
{
"x-powered-by": "Express",
"x-content-type-options": "nosniff",
"content-type": "text/html; charset=utf-8",
"content-length": "18",
"date": "Sun, 19 Feb 2017 15:00:11 GMT",
"connection": "close",
"X-Amzn-Trace-Id": "<TRACE-ID>"
}
Logs
Execution log for request test-request
Sun Feb 19 15:00:07 UTC 2017 : Starting execution for request: test-invoke-request
Sun Feb 19 15:00:07 UTC 2017 : HTTP Method: GET, Resource Path: /hello
Sun Feb 19 15:00:07 UTC 2017 : Method request path: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request query string: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request headers: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request body before transformations:
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:<ACCOUNT-ID>:function:api/invocations
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=**************************************************************************************************************************************************************************************************************************************************************************************************************************4b0637, X-Amz-Date=20170219T150007Z, x-amzn-apigateway-api-id=965h04axki, Accept=application/json, User-Agent=AmazonAPIGateway_965h04axki, X-Amz-Security-Token=<SECURITY-TOKEN>
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request body after transformations: {"resource":"/hello","path":"/hello","httpMethod":"GET","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"<ACCOUNT-ID>","resourceId":"ll6gw8","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"<ACCOUNT-ID>","cognitoIdentityId":null,"caller":"<ACCOUNT-ID>","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"<ACCESS-ID>","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::<ACCOUNT-ID>:root","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_102)","user":"<ACCOUNT-ID>"},"resourcePath":"/hello","httpMethod":"GET","apiId":"965h04axki"},"body":null,"isBase64Encoded":false}
Sun Feb 19 15:00:11 UTC 2017 : Endpoint response body before transformations: {"statusCode":404,"body":"Cannot GET /hello\n","headers":{"x-powered-by":"Express","x-content-type-options":"nosniff","content-type":"text/html; charset=utf-8","content-length":"18","date":"Sun, 19 Feb 2017 15:00:11 GMT","connection":"close"},"isBase64Encoded":false}
Sun Feb 19 15:00:11 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=19f8554e-f6b4-11e6-8184-d3ccf0ccf643, Connection=keep-alive, Content-Length=267, Date=Sun, 19 Feb 2017 15:00:11 GMT, Content-Type=application/json}
Sun Feb 19 15:00:11 UTC 2017 : Method response body after transformations: Cannot GET /hello
Sun Feb 19 15:00:11 UTC 2017 : Method response headers: {x-powered-by=Express, x-content-type-options=nosniff, content-type=text/html; charset=utf-8, content-length=18, date=Sun, 19 Feb 2017 15:00:11 GMT, connection=close, X-Amzn-Trace-Id=Root=1-58a9b2f7-91fc7371e41d6ae9c2fbf64d}
Sun Feb 19 15:00:11 UTC 2017 : Successfully completed execution
Sun Feb 19 15:00:11 UTC 2017 : Method completed with status: 404
Logs from Test Request via API Gateway second Invocation
Response Body
"Hello, stranger!"
Response Headers
{
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"content-length": "18",
"etag": "W/\"12-E1p7iNXxJ4trMdmFBhlU9Q\"",
"date": "Mon, 13 Feb 2017 20:12:36 GMT",
"connection": "close",
"X-Amzn-Trace-Id": "<Trace-ID>"
}
Logs
Execution log for request test-request
Mon Feb 13 20:12:36 UTC 2017 : Starting execution for request: test-invoke-request
Mon Feb 13 20:12:36 UTC 2017 : HTTP Method: GET, Resource Path: /hello
Mon Feb 13 20:12:36 UTC 2017 : Method request path: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request query string: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request headers: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request body before transformations:
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:<LAMBDA-FUNCTION-ID>:function:api/invocations
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=*******************************************************************************************************************************************************************************************************************************************************************************************************************************************3e1b18, X-Amz-Date=20170213T201236Z, x-amzn-apigateway-api-id=965h04axki, X-Amz-Source-Arn=arn:aws:execute-api:eu-central-1:<ACCOUNT-ID>:965h04axki/null/GET/hello, Accept=application/json, User-Agent=AmazonAPIGateway_965h04axki, X-Amz-Security-Token=<TOKEN>
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request body after transformations: {"resource":"/hello","path":"/hello","httpMethod":"GET","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"<ACCOUNT-ID>","resourceId":"ll6gw8","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"<ACCOUNT-ID>","cognitoIdentityId":null,"caller":"427402682812","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"<ACCESS-KEY>","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::<ACCOUNT-ID>:root","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_102)","user":"<ACCOUNT-ID>"},"resourcePath":"/hello","httpMethod":"GET","apiId":"965h04axki"},"body":null,"isBase64Encoded":false}
Mon Feb 13 20:12:36 UTC 2017 : Endpoint response body before transformations: {"statusCode":200,"body":"\"Hello, stranger!\"","headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"application/json; charset=utf-8","content-length":"18","etag":"W/\"12-E1p7iNXxJ4trMdmFBhlU9Q\"","date":"Mon, 13 Feb 2017 20:12:36 GMT","connection":"close"},"isBase64Encoded":false}
Mon Feb 13 20:12:36 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=c3354327-f228-11e6-8c1d-ed11cc413770, Connection=keep-alive, Content-Length=315, Date=Mon, 13 Feb 2017 20:12:36 GMT, Content-Type=application/json}
Mon Feb 13 20:12:36 UTC 2017 : Method response body after transformations: "Hello, stranger!"
Mon Feb 13 20:12:36 UTC 2017 : Method response headers: {x-powered-by=Express, access-control-allow-origin=*, content-type=application/json; charset=utf-8, content-length=18, etag=W/"12-E1p7iNXxJ4trMdmFBhlU9Q", date=Mon, 13 Feb 2017 20:12:36 GMT, connection=close, X-Amzn-Trace-Id=Root=1-58a21334-8ea6c4b5944eebb873bc7d2e}
Mon Feb 13 20:12:36 UTC 2017 : Successfully completed execution
Mon Feb 13 20:12:36 UTC 2017 : Method completed with status: 200
I think the response "Cannot GET /" is coming from your Lambda function itself. Can you check API Gateway CW logs (or Test Invoke feature in console) to see what's different in the integration request and response in the first call?
I didn't see any real documentation about it (just this Medium post) but I also experienced the fact that a Lambda can be frozen until the first invocation, or in the case it's not called for a long time.
A solution is to schedule a regular invocation to wake up your lambda, with Amazon CloudWatch Events
I know that is an old question, but if you use TypeORM (or more in general, if you wrap all your Express middlewares within a .then() callback of a Promise), and you use context.callbackWaitsForEmptyEventLoop = false in your lambda handler, maybe this could help you: https://github.com/typeorm/typeorm/issues/5894
Long story short: avoid to set that flag to false, if possible, otherwise avoid to wrap the Express middlewares within the .then() callback and, for instance, initialize your db connection in the first Express middleware.

nginx / uwsgi with django 1.9.8 - Bad gateway 502 error with upstream prematurely closed connection while reading response header from upstream?

my nginx_app.conf -
server
{
listen 8000;
#server_name
access_log /var/log/tw-access.log;
error_log /var/log/tw-error.log;
root /var/www/djangoapp;
access_log on;
error_log on;
location /static/
{
alias /var/www/djangoapp/apptw/static/;
}
location /
{
uwsgi_pass 127.0.0.1:8800;
include uwsgi_params;
uwsgi_read_timeout 500;
}
}
and my uwsgi_app.ini -
# djangoapp_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /var/www/djangoapp
# Django's wsgi file
module = djangoapp.wsgi:application
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 5
# the socket (use the full path to be safe
socket = 127.0.0.1:8800
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
max-requests = 5000
uid = www-data
gid = www-data
enable-threads = true
buffer-size = 65535
when I am opening this with server-IP:8000 it is showing 502-bad Gateway and nginx error-file showing :-
upstream prematurely closed connection while reading response header from upstream,
client: 223.181.31.8, server: , request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8800", host: "server-IP:8000"
uwsgi logs :-
uwsgi logs :-
Sun Sep 18 01:35:19 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:38:49 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:38:49 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:47:03 2016 - SIGINT/SIGQUIT received...killing workers...
Sun Sep 18 13:47:04 2016 - worker 1 buried after 1 seconds
Sun Sep 18 13:47:04 2016 - worker 2 buried after 1 seconds
Sun Sep 18 13:47:04 2016 - worker 3 buried after 1 seconds
Sun Sep 18 13:47:04 2016 - worker 4 buried after 1 seconds
Sun Sep 18 13:47:04 2016 - worker 5 buried after 1 seconds
Sun Sep 18 13:47:04 2016 - goodbye to uWSGI.
Sun Sep 18 13:47:04 2016 - VACUUM: unix socket /run/uwsgi/app/tw/socket removed.
Sun Sep 18 13:47:05 2016 - *** Starting uWSGI 2.0.12-debian (64bit) on [Sun Sep 18 13:47:04 2016] ***
Sun Sep 18 13:47:05 2016 - compiled with version: 5.3.1 20160412 on 13 April 2016 08:36:06
Sun Sep 18 13:47:05 2016 - os: Linux-2.6.32-042stab113.17 #1 SMP Wed Feb 10 18:31:00 MSK 2016
Sun Sep 18 13:47:05 2016 - nodename: cot-stg-1
Sun Sep 18 13:47:05 2016 - machine: x86_64
Sun Sep 18 13:47:05 2016 - clock source: unix
Sun Sep 18 13:47:05 2016 - pcre jit disabled
Sun Sep 18 13:47:05 2016 - detected number of CPU cores: 4
Sun Sep 18 13:47:05 2016 - current working directory: /
Sun Sep 18 13:47:05 2016 - writing pidfile to /run/uwsgi/app/tw/pid
Sun Sep 18 13:47:05 2016 - detected binary path: /usr/bin/uwsgi-core
Sun Sep 18 13:47:05 2016 - setgid() to 33
Sun Sep 18 13:47:05 2016 - setuid() to 33
Sun Sep 18 13:47:05 2016 - chdir() to /var/www/django_app
Sun Sep 18 13:47:05 2016 - your processes number limit is 514923
Sun Sep 18 13:47:05 2016 - your memory page size is 4096 bytes
Sun Sep 18 13:47:05 2016 - detected max file descriptor number: 1024
Sun Sep 18 13:47:05 2016 - lock engine: pthread robust mutexes
Sun Sep 18 13:47:05 2016 - thunder lock: disabled (you can enable it with --thunder-lock)
Sun Sep 18 13:47:05 2016 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/tw/socket fd 3
Sun Sep 18 13:47:05 2016 - uwsgi socket 1 bound to TCP address 127.0.0.1:8800 fd 5
Sun Sep 18 13:47:05 2016 - your server socket listen backlog is limited to 100 connections
Sun Sep 18 13:47:05 2016 - your mercy for graceful operations on workers is 60 seconds
Sun Sep 18 13:47:05 2016 - mapped 805242 bytes (786 KB) for 5 cores
Sun Sep 18 13:47:05 2016 - *** Operational MODE: preforking ***
Sun Sep 18 13:47:05 2016 - *** no app loaded. going in full dynamic mode ***
Sun Sep 18 13:47:05 2016 - *** uWSGI is running in multiple interpreter mode ***
Sun Sep 18 13:47:05 2016 - !!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!
Sun Sep 18 13:47:05 2016 - no request plugin is loaded, you will not be able to manage requests.
Sun Sep 18 13:47:05 2016 - you may need to install the package for your language of choice, or simply load it with --plugin.
Sun Sep 18 13:47:05 2016 - !!!!!!!!!!! END OF WARNING !!!!!!!!!!
Sun Sep 18 13:47:05 2016 - spawned uWSGI master process (pid: 8733)
Sun Sep 18 13:47:05 2016 - spawned uWSGI worker 1 (pid: 8735, cores: 1)
Sun Sep 18 13:47:05 2016 - spawned uWSGI worker 2 (pid: 8736, cores: 1)
Sun Sep 18 13:47:05 2016 - spawned uWSGI worker 3 (pid: 8737, cores: 1)
Sun Sep 18 13:47:05 2016 - spawned uWSGI worker 4 (pid: 8738, cores: 1)
Sun Sep 18 13:47:05 2016 - spawned uWSGI worker 5 (pid: 8739, cores: 1)
Sun Sep 18 13:47:27 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:55:41 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:55:43 2016 - -- unavailable modifier requested: 0 --
Sun Sep 18 13:57:03 2016 - -- unavailable modifier requested: 0 --
What should I do? please suggest.
Thank you in advance...

CouchDB Error 500: function_clause error in HTTP request

When making a REST call to CouchDB, the request fails with unknown error 500. Any help would be much appreciated... thanks!
Here are the logs:
[Thu, 30 Oct 2014 20:47:50 GMT] [debug] [] 'GET' /settings/master-config? {1,1} from "10.48.XX.XXX"
Headers: [{'Authorization',"Basic XXX=, Basic XXX=="},
{'Connection',"Keep-Alive"},
{'Host',"127.0.0.1:5984"},
{'User-Agent',"Apache-HttpClient/4.2.2 (java 1.5)"},
{'X-Forwarded-For',"10.48.xx.xxx"},
{"X-Forwarded-Host","my.couchdb.server.com"},
{"X-Forwarded-Server","ip-10-48-xx-xxx.ec2.internal"},
{"X-Newrelic-Id","XXXX="},
{"X-NewRelic-Transaction","XXXXXXX"}]
[Thu, 30 Oct 2014 20:47:50 GMT] [debug] [] OAuth Params: []
[Thu, 30 Oct 2014 20:47:50 GMT] [error] [] function_clause error in HTTP request
[Thu, 30 Oct 2014 20:47:50 GMT] [info] [] Stacktrace: [{base64,b64d_ok,[eq]},
{base64,decode,2},
{base64,decode,1},
{couch_httpd_auth,basic_name_pw,1},
{couch_httpd_auth,
default_authentication_handler,1},
{couch_httpd,authenticate_request,2},
{couch_httpd,handle_request_int,5},
{mochiweb_http,headers,5}]
[Thu, 30 Oct 2014 20:47:50 GMT] [info] [] 10.48.XX.XXX - - GET /settings/master-config? 500
[Thu, 30 Oct 2014 20:47:50 GMT] [error] [] httpd 500 error response:
{"error":"unknown_error","reason":"function_clause"}
Your Authorization header looks weird: {'Authorization',"Basic XXX=, Basic XXX=="} - there should be only single Basic credentials token, not multiple ones.

How a device registers itself after adding a pass

When I add a pass in a device, I see on the console like this:
Mar 26 14:32:36 CamMobs-iPod4 passd[7128] <Warning>: Card has more than 10 locations. Capping.
Mar 26 14:32:38 CamMobs-iPod4 MobileSafari[7115] <Warning>: Warning: Attempt to dismiss from view controller <BrowserRootViewController: 0x1ed546a0> while a presentation or dismiss is in progress!
Mar 26 14:32:39 CamMobs-iPod4 backboardd[52] <Warning>: CoreAnimation: updates deferred for too long
Mar 26 14:32:39 CamMobs-iPod4 locationd[41] <Notice>: Location icon should now be in state 'Active'
Mar 26 14:32:50 CamMobs-iPod4 locationd[41] <Notice>: Location icon should now be in state 'Inactive'
Mar 26 14:32:52 CamMobs-iPod4 profiled[7122] <Notice>: (Note ) profiled: Idled.
Mar 26 14:32:52 CamMobs-iPod4 profiled[7122] <Notice>: (Note ) profiled: Service stopping.
Mar 26 14:33:31 CamMobs-iPod4 locationd[41] <Warning>: Launch Services: Registering unknown app identifier com.apple.PassKit failed
Mar 26 14:33:31 CamMobs-iPod4 locationd[41] <Warning>: Launch Services: Unable to find app identifier com.apple.PassKit
Mar 26 14:33:33 CamMobs-iPod4 configd[50] <Notice>: network changed: v4(en0:192.168.1.109) DNS Proxy
Mar 26 14:33:53 CamMobs-iPod4 backboardd[52] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0
.....
Why it tries to register to com.apple.PassKit ?
In my server, I use some codes in index.php like the following:
<?php
// Transfer Request URL into array
$request = explode("/", substr(#$_SERVER['REQUEST_URI'], 1));
//$request = explode("/", substr(#$_SERVER['REQUEST_URI'], 1));
print_r($_SERVER['REQUEST_URI']);
if (strtoupper($_SERVER['REQUEST_METHOD']) === "POST"
&& isset($_SERVER['HTTP_AUTHORIZATION'])
&& strpos($_SERVER['HTTP_AUTHORIZATION'], 'ApplePass') === 0
&& $request[2] === "devices"
&& $request[4] === "registrations") {
$auth_key = str_replace('ApplePass ', '', $_SERVER['HTTP_AUTHORIZATION']);
$device_id = $request[3];
$pass_id = $request[5];
$serial = $request[6];
echo $request[3];
//$device_id = $_POST[''];
echo $device_id;
echo $pass_id;
echo $serial ;
// Catch the JSON post and decode it
$dt = #file_get_contents('php://input');
// $dt = #file_get_contents('php://input');
//$device_token = json_decode($dt);
//$device_token = $device_token->pushToken;
$pushtoken=json_decode($dt)->pushToken;
if (!$device_token) die('No Token Found'); // Token wasn't found
$dbhost = 'localhost:8889';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'passesdb';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql'.mysql_error());
mysql_select_db($dbname);
mysql_query("SET NAMES UTF8");
mysql_query($sql,$conn);
$table = 'Devices';
$sql = mysql_query("insert into Devices values('$device_id','$pushtoken')");
mysql_query($sql);
exit;
}
?>
This is what a successful registration looks like in the console:
1. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Generating POST request with URL <https:/afr.passk.it/v1/devices/7864dc8fdcfe739273cf7362a0db2b35/registrations/pass.it.passk.developer3/1wqdDAqHydkRURA9YCjbq>
2. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Request contains header field <Authorization: ApplePass 5cdddad65324384efa39575a4cf22424>
3. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Request contains body dictionary {
pushToken = 0bbe54794500332b789a3ddb69827386d5c9aad1cb035c9f2725761d419950b2;
}
4. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Register task (for device 7864dc8fdcfe739273cf7362a0db2b35, pass type pass.it.passk.developer3, serial number 1wqdDAqHydkRURA9YCjbq; with web service url https://afr.passk.it/) got response with code 201
5. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Generating GET request with URL <https:/afr.passk.it/v1/devices/7864dc8fdcfe739273cf7362a0db2b35/registrations/pass.it.passk.developer3?passesUpdatedSince=1364287618>
6. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Generating GET request with URL <https:/afr.passk.it/v1/passes/pass.it.passk.developer3/1wqdDAqHydkRURA9YCjbq>
7. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Request contains header field <If-Modified-Since: Tue, 26 Mar 2013 07:35:33 GMT>
8. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Request contains header field <Authorization: ApplePass 5cdddad65324384efa39575a4cf22424>
9. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Get serial #s task (for device 7864dc8fdcfe739273cf7362a0db2b35, pass type pass.it.passk.developer3, last updated 1364287618; with web service url https://afr.passk.it/) got response with code 204
10. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Get serial numbers task completed with update tag (null), serial numbers (null)
11. Mar 26 17:00:05 iPhone5 passd[6262] <Warning>: Get pass task (pass type pass.it.passk.developer3, serial number 1wqdDAqHydkRURA9YCjbq, if-modified-since Tue, 26 Mar 2013 07:35:33 GMT; with web service url https://afr.passk.it/) got response with code 304
What you have posted above is only the last line of this process, (where passd has picked up that you have more than 10 locations in your pass.json).
If you examine the above you can see the flow of events that your web service needs to respond to:
Row 1: Device sends a POST request to:
https://webserviceURL/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}`
Row 2: POST request is sent with the header field:
Authorization: ApplePass {authenticationToken}
Row 3: POST body contains the JSON Dictionary:
{
pushToken = {pushToken};
}
Provided your rewrite rule is correct, your PHP code should analyse the URL and capture the deviceLibraryIdentifier and pushToken and store it in the database, linked to the pass record containing the serialNumber, authenticationToken and passTypeIdentifier.
Then Row 4: Your web service responds to the device with a 201 code to indicate that the registration was successful.
On Row 5: The device then generates a GET request to your web service to check if there is a newer versions pof passes for the same certificate:
https:/webserviceURL/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}?passesUpdatedSince={lastUpdateTag}
On Row 6, 7 and 8: The device generates a GET request to your web service to check if there is a newer version of this specific pass. It provides an If-Modified-Since header containing the date provided in the header of the last downloaded .pkpass bundle (Row 7), and provides another Authorization header containing Applepass {authenticationToken} (Row 8) so that your web service can validate the request against by checking the database record for the serialNumber.
https:/webserviceURL/v1/passes/{passTypeIdentifier}/{serialNumber}
Header: If-Modified-Since: {last modified date}
Header: Authorization: ApplePass {authenticationToken}
On Row 9: the web service responds with a 204 response, indicating that there are no serialNumbers for the passTypeIdentifier that require updating. Row 10 confirms this.
Finally, on Row 11, the device receives a 304 response from your web service, confirming that the pass it has just installed is the latest version of the pass.
The above outlines precisely what your web service will receive and the responses it needs to provide to successfully register a device.