populating required fields only in the response of spring rest API - spring

I am using Spring to build sample rest web service.
This is my RequestMapping:
#RequestMapping(value ="/employees", method = RequestMethod.GET)
public Response getAllEmployees(#Context HttpServletRequest request) {
List<Employee> employees = null;
try {
employees = repository.findAll();
}catch(Throwable e) {
RestServiceException rsException = new RestServiceException();
rsException.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
throw rsException;
}
return Response.ok(employees, MediaType.APPLICATION_JSON).build();
}
When I am using this, response is populated as below:
{
"context": {
"headers": {
"Content-Type": [
{
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
}
]
},
"configuration": null,
"entity": [
{
"id": 1,
"name": "Bilbo Baggins",
"role": "burglar"
},
{
"id": 2,
"name": "Frodo Baggins",
"role": "thief"
}
],
"entityType": "java.util.ArrayList",
"entityAnnotations": [],
"entityStream": {
"closed": false,
"committed": false
},
"length": -1,
"language": null,
"location": null,
"date": null,
"lastModified": null,
"mediaType": {
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
},
"entityClass": "java.util.ArrayList",
"lengthLong": -1,
"allowedMethods": [],
"acceptableMediaTypes": [
{
"type": "*",
"subtype": "*",
"parameters": {},
"quality": 1000,
"wildcardType": true,
"wildcardSubtype": true
}
],
"committed": false,
"requestCookies": {},
"acceptableLanguages": [
"*"
],
"responseCookies": {},
"stringHeaders": {
"Content-Type": [
"application/json"
]
},
"entityTag": null,
"links": []
},
"status": 200,
"length": -1,
"language": null,
"location": null,
"date": null,
"lastModified": null,
"mediaType": {
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
},
"metadata": {
"Content-Type": [
{
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
}
]
},
"allowedMethods": [],
"statusInfo": "OK",
"cookies": {},
"stringHeaders": {
"Content-Type": [
"application/json"
]
},
"entityTag": null,
"entity": [
{
"id": 1,
"name": "Bilbo Baggins",
"role": "burglar"
},
{
"id": 2,
"name": "Frodo Baggins",
"role": "thief"
}
],
"links": [],
"headers": {
"Content-Type": [
{
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
}
]
}
}
But I want response to be populated as below:
[
{
"id": 1,
"name": "Bilbo Baggins",
"role": "burglar"
},
{
"id": 2,
"name": "Frodo Baggins",
"role": "thief"
}
]
Note : I don't want to change the return type of the method to List.(I want the return type as Response(javax.ws.rs.core.Response) object only).
Is there anyway to populate only the Employee_List in the response.

You are trying to use both JAX-RS and Spring MVC, I guess. With the Response, Spring MVC doesn't recognize the response entity and it serializes the object similar to other objects. If you are using Spring MVC, you want to be using ResponseEntity. You can refer to the below code snippet.
Change the method to return ResponseEntity rather.
#RequestMapping(value ="/employees", method = RequestMethod.GET)
public ResponseEntity getAllEmployees(#Context HttpServletRequest request) {
List<Employee> employees = null;
try {
employees = repository.findAll();
}catch(Throwable e) {
RestServiceException rsException = new RestServiceException();
rsException.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
throw rsException;
}
return ResponseEntity.ok(employees);
}

Related

Microsoft Graph Batch API concurrent request reduction to 4 where as outlook had 200 concurrent Requests

We use Outlook Batch API to send multiple Outlook REST requests in a single HTTP batch request. In Outlook Batch API, we make 200 requests in the same batch HTTP request and all the concurrent requests succeed. Whereas if we do the same in graph API, only 4 concurrent requests succeed as only 4 concurrent requests are supported in graph APIs (attached request and response).
We have the cases such as 10000 events creating at once(like users can add/remove 10000 items from a single user calendar).
So it would be of great help if the Graph APIs batch limit is set to be same as Outlook API(200 concurrent request).
Sample request:
{
"requests": [
{
"url": "/me/calendars",
"method": "POST",
"id": "1",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test1s"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "2",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test2"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "3",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test3"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "4",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test4"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "5",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test5s"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "6",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test6s"
}
},
{
"url": "/me/calendars",
"method": "POST",
"id": "7",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "test7s"
}
}
]
}
Response:
{
"responses": [
{
"id": "6",
"status": 429,
"headers": {
"Retry-After": "1",
"Cache-Control": "private",
"Content-Type": "application/json"
},
"body": {
"error": {
"code": "ApplicationThrottled",
"message": "Application is over its MailboxConcurrency limit.",
"innerError": {
"date": "2022-08-11T06:21:56",
"request-id": "e09afe6b-25d6-4cdc-93f5-0539d6e8b9c6",
"client-request-id": "efe22070-473c-28bd-d1bf-ad43bb9f753f"
}
}
}
},
{
"id": "7",
"status": 429,
"headers": {
"Retry-After": "1",
"Cache-Control": "private",
"Content-Type": "application/json"
},
"body": {
"error": {
"code": "ApplicationThrottled",
"message": "Application is over its MailboxConcurrency limit.",
"innerError": {
"date": "2022-08-11T06:21:56",
"request-id": "e09afe6b-25d6-4cdc-93f5-0539d6e8b9c6",
"client-request-id": "efe22070-473c-28bd-d1bf-ad43bb9f753f"
}
}
}
},
{
"id": "4",
"status": 429,
"headers": {
"Retry-After": "1",
"Cache-Control": "private",
"Content-Type": "application/json"
},
"body": {
"error": {
"code": "ApplicationThrottled",
"message": "Application is over its MailboxConcurrency limit.",
"innerError": {
"date": "2022-08-11T06:21:56",
"request-id": "e09afe6b-25d6-4cdc-93f5-0539d6e8b9c6",
"client-request-id": "efe22070-473c-28bd-d1bf-ad43bb9f753f"
}
}
}
},
{
"id": "5",
"status": 201,
"headers": {
"Location": x"https://outlook.office.com/api/v2.0/Users('xxxx')/Calendars('xxxx')",
"Cache-Control": "private",
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
},
"body": {
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xxxxx')/calendars/$entity",
"id": "xxx",
"name": "test5s",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "xxxxx",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "xxxx",
"address": "xxxx.onmicrosoft.com"
}
}
},
{
"id": "2",
"status": 201,
"headers": {
"Location": "https://outlook.office.com/api/v2.0/Users('xxxx')/Calendars('xxxx')",
"Cache-Control": "private",
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
},
"body": {
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xx')/calendars/$entity",
"id": "xxx",
"name": "test2",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "xxxxx",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "xxxx",
"address": "xxxxx.onmicrosoft.com"
}
}
},
{
"id": "3",
"status": 201,
"headers": {
"Location": "https://outlook.office.com/api/v2.0/Users('xxxx')/Calendars('xxxxx')",
"Cache-Control": "private",
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
},
"body": {
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xxx')/calendars/$entity",
"id": "x",
"name": "test3",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "xxxxxx==",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "xxxx",
"address": "xxxxxx.onmicrosoft.com"
}
}
},
{
"id": "1",
"status": 201,
"headers": {
"Location": "https://outlook.office.com/api/v2.0/Users('xxxx')/Calendars('xxxx')",
"Cache-Control": "private",
"OData-Version": "4.0",
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
},
"body": {
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xxxxx')/calendars/$entity",
"id": "xxxxxx",
"name": "test1s",
"color": "auto",
"hexColor": "",
"isDefaultCalendar": false,
"changeKey": "xxxxxxx",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "xxxx",
"address": "xxxxx.onmicrosoft.com"
}
}
}
]
}
There is a known issue with Batching as mentioned here:
and more in this :
For reference, please refer this:
https://learn.microsoft.com/en-us/graph/known-issues#json-batching
https://learn.microsoft.com/en-us/graph/throttling#throttling-and-batching

Laravel 5.5 echo unable to listen to channel

I am currently using laravel-echo along with with pusher to set up my channel and broadcast however there seems to be some issues creating the listener onto the channel.
There should be a message on the pusher dashboard indicating that the channel is being listened to when the page is entered but nothing is being displayed
Initializing Echo Listener
$(document).ready(function() {
try{
window.Echo.channel('chat-room')
.listen('scannedQR', (e) => {
console.log("event has been triggered");
alert('event has been triggered');
});
alert('success');
}
catch(e){
console.log(e);
alert(e);
}
}
Bootstrap
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Lover = "LOVER!";
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'key',
// cluster: 'mt1',
cluster:'ap1',
encrypted: true
});
Echo Object -> console.log(JSON.safeStringify(window.Echo));
{
"options": {
"broadcaster": "pusher",
"key": key,
"cluster": cluster,
"encrypted": true
},
"connector": {
"_defaultOptions": {
"auth": {
"headers": {
"X-CSRF-TOKEN": "oIywz9kkxhVbl109qOqXMy0NVrUCR5AZlYR5apPc"
}
},
"authEndpoint": "/broadcasting/auth",
"userAuthentication": {
"endpoint": "/broadcasting/user-auth",
"headers": {
"X-CSRF-TOKEN": "oIywz9kkxhVbl109qOqXMy0NVrUCR5AZlYR5apPc"
}
},
"broadcaster": "pusher",
"csrfToken": null,
"host": null,
"key": key,
"namespace": "App.Events",
"cluster": "ap1",
"encrypted": true
},
"pusher": {
"key": key,
"config": {
"activityTimeout": 120000,
"cluster": "ap1",
"httpPath": "/pusher",
"httpPort": 80,
"httpsPort": 443,
"pongTimeout": 30000,
"statsHost": "stats.pusher.com",
"unavailableTimeout": 10000,
"wsPath": "",
"wsPort": 80,
"wssPort": 443,
"enableStats": false,
"httpHost": "sockjs-ap1.pusher.com",
"useTLS": true,
"wsHost": "ws-ap1.pusher.com"
},
"channels": {
"channels": {}
},
"global_emitter": {
"callbacks": {
"_callbacks": {}
},
"global_callbacks": []
},
"sessionID": 299457458,
"timeline": {
"key": key,
"session": 299457458,
"events": [
{
"instances": 1,
"timestamp": 1660358957487
},
{
"state": "connecting",
"timestamp": 1660358957538
},
{
"cached": true,
"transport": "xhr_streaming",
"latency": 410,
"timestamp": 1660358957539
},
{
"cid": 1,
"transport": "xhr_streamings",
"timestamp": 1660358957539
},
{
"cid": 1,
"state": "initialized",
"timestamp": 1660358957539
},
{
"cid": 1,
"state": "connecting",
"timestamp": 1660358957541
},
{
"cid": 1,
"state": "open",
"timestamp": 1660358957974
},
{
"state": "connected",
"params": {
"socket_id": "17356.8786996"
},
"timestamp": 1660358957976
}
],
"options": {
"cluster": cluster,
"features": [
"ws"
],
"params": {},
"limit": 50,
"level": 6,
"version": "7.3.0"
},
"sent": 0,
"uniqueID": 1
},
"connection": {
"callbacks": {
"_callbacks": {
"_connected": [
{},
{}
],
"_message": [
{},
{}
],
"_connecting": [
{},
{}
],
"_disconnected": [
{},
{}
],
"_error": [
{}
]
}
},
"global_callbacks": [],
"state": "connected",
"connection": {
"callbacks": {
"_callbacks": {
"_tls_only": [
{}
],
"_refused": [
{}
],
"_backoff": [
{}
],
"_retry": [
{}
],
"_message": [
{}
],
"_ping": [
{}
],
"_activity": [
{}
],
"_error": [
{}
],
"_closed": [
{}
]
}
},
"global_callbacks": [],
"id": "17356.8786996",
"transport": {
"callbacks": {
"_callbacks": {
"_error": [
{}
],
"_closed": [
{},
{}
],
"_message": [
{}
],
"_activity": [
{}
]
}
},
"global_callbacks": [],
"hooks": {
"urls": {},
"handlesActivityChecks": false,
"supportsPing": true
},
"name": "xhr_streaming",
"priority": 1,
"key": key,
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
},
"state": "open",
"id": 1,
"socket": {
"hooks": {},
"session": "428/90n18c0a",
"location": {
"base": base,
"queryString": "?protocol=7&client=js&version=7.3.0"
},
"readyState": 1,
"stream": {
"callbacks": {
"_callbacks": {
"_chunk": [
{}
],
"_finished": [
{}
],
"_buffer_too_long": [
{}
]
}
},
"global_callbacks": [],
"hooks": {},
"method": "POST",
"url": url,
"position": 2188,
"xhr": {}
}
}
}
},
"key": key,
"options": {
"activityTimeout": 120000,
"pongTimeout": 30000,
"unavailableTimeout": 10000,
"useTLS": true
},
"usingTLS": true,
"errorCallbacks": {},
"connectionCallbacks": {},
"handshakeCallbacks": {},
"strategy": {
"strategy": {
"strategy": {
"trueBranch": {
"strategies": [
{
"strategies": [
{
"name": "ws",
"priority": 3,
"transport": {
"manager": {
"options": {
"lives": 2,
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"livesLeft": 2
},
"transport": {
"hooks": {
"urls": {},
"handlesActivityChecks": false,
"supportsPing": false
}
},
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "ws-ap1.pusher.com:80",
"hostTLS": "ws-ap1.pusher.com:443",
"httpPath": ""
}
}
],
"loop": true,
"failFast": false,
"timeout": 15000,
"timeoutLimit": 60000
},
{
"strategy": {
"trueBranch": {
"strategies": [
{
"trueBranch": {
"strategies": [
{
"strategies": [
{
"trueBranch": {
"name": "xhr_streaming",
"priority": 1,
"transport": {
"manager": {
"options": {
"lives": 2,
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"livesLeft": 2
},
"transport": {},
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
}
},
"falseBranch": {
"name": "xdr_streaming",
"priority": 1,
"transport": {
"transport": {
"hooks": {
"urls": {},
"handlesActivityChecks": false,
"supportsPing": true
}
},
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
}
}
}
],
"loop": true,
"failFast": false,
"timeout": 15000,
"timeoutLimit": 60000
},
{
"strategy": {
"strategies": [
{
"trueBranch": {
"name": "xhr_polling",
"priority": 1,
"transport": {
"hooks": {
"urls": {},
"handlesActivityChecks": false,
"supportsPing": true
}
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
}
},
"falseBranch": {
"name": "xdr_polling",
"priority": 1,
"transport": {
"hooks": {
"urls": {},
"handlesActivityChecks": false,
"supportsPing": true
}
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
}
}
}
],
"loop": true,
"failFast": false,
"timeout": 15000,
"timeoutLimit": 60000
},
"options": {
"delay": 4000
}
}
]
}
}
],
"loop": true,
"failFast": false,
"timeout": 15000,
"timeoutLimit": 60000
},
"falseBranch": {
"strategies": [
{
"name": "sockjs",
"priority": 1,
"transport": {
"hooks": {
"file": "sockjs",
"urls": {},
"handlesActivityChecks": true,
"supportsPing": false
}
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "sockjs-ap1.pusher.com:80",
"hostTLS": "sockjs-ap1.pusher.com:443",
"httpPath": "/pusher"
}
}
],
"loop": true,
"failFast": false,
"timeout": 15000,
"timeoutLimit": 60000
}
},
"options": {
"delay": 2000
}
}
]
}
}
},
"transports": {
"wss": {
"name": "wss",
"priority": 3,
"transport": {
"minPingDelay": 10000,
"maxPingDelay": 120000
},
"options": {
"key": key,
"useTLS": true,
"hostNonTLS": "ws-ap1.pusher.com:80",
"hostTLS": "ws-ap1.pusher.com:443",
"httpPath": ""
}
}
},
"ttl": 1800000,
"usingTLS": true
},
"runner": null,
"unavailableTimer": {
"timer": null
},
"activityTimeout": 120000,
"activityTimer": {
"timer": 5
},
"socket_id": "17356.8786996"
},
"user": {
"callbacks": {
"_callbacks": {}
},
"global_callbacks": [],
"signin_requested": false,
"user_data": null,
"serverToUserChannel": null
}
},
"channels": {}
}
}
Pusher Dashboard doesn't show that channel is being listened to
EDIT
It currently shows on the pusher dashboard that the channel is being listened to but laravel-echo doesn't catch the event on the front end

Logstash Indexing error “Index -1 out of bounds for length 0”

I want to use ELK stack to analyze some Kubernetes audit logs. They're sent to the Logstash webhook as JSON. Here's my config file :
input{
http {
port => 8888
codec => "json"
type => "json"
}
}
filter{
json {
source => "message"
}
}
output{
file {
path => "/home/ubuntu/logstash-kubernetes/audit.log"
}
elasticsearch{
hosts => "localhost:9200"
index => "kubernetes"
}
}
The output file is populated with good looking entries, I'm happy with it. But when it comes to exporting to Elasticsearch, I'm getting the following error :
elasticsearch - Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"kubernetes", :routing=>nil, :_type=>"_doc"}, #<LogStash::Event:0x71740f4b>], :response=>{"index"=>{"_index"=>"kubernetes", "_type"=>"_doc", "_id"=>"x6QKJHYBkIKyNOo2Q-z8", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse", "caused_by"=>{"type"=>"array_index_out_of_bounds_exception", "reason"=>"Index -1 out of bounds for length 0"}}}}}
It only happens for some entries. Let me show you an generated entry that was processed without error :
{
"_index": "kubernetes",
"_type": "_doc",
"_id": "xKQKJHYBkIKyNOo2POwJ",
"_version": 1,
"_score": 0,
"_source": {
"headers": {
"content_type": "application/json",
"request_method": "POST",
"accept_encoding": "gzip",
"request_path": "/",
"http_host": "****:8888",
"http_accept": "application/json, */*",
"content_length": "2813",
"http_version": "HTTP/1.1",
"http_user_agent": "Go-http-client/1.1"
},
"#version": "1",
"host": "****",
"apiVersion": "audit.k8s.io/v1",
"items": [
{
"requestObject": {
"type": "Normal",
"firstTimestamp": "2020-12-02T15:20:19Z",
"involvedObject": {
"namespace": "kube-system",
"name": "kube-scheduler",
"apiVersion": "v1",
"resourceVersion": "2573",
"uid": "0ebf0ea5-f8c0-475a-9c9e-57674edefe8d",
"kind": "Endpoints"
},
"message": "****1_938d6a87-bccb-4ea0-bd6b-31fc27e48b7a became leader",
"eventTime": null,
"source": {
"component": "default-scheduler"
},
"reason": "LeaderElection",
"count": 1,
"reportingInstance": "",
"apiVersion": "v1",
"reportingComponent": "",
"lastTimestamp": "2020-12-02T15:20:19Z",
"metadata": {
"name": "kube-scheduler.164cef6d1f3ed55e",
"namespace": "kube-system",
"creationTimestamp": null
},
"kind": "Event"
},
"requestURI": "/api/v1/namespaces/kube-system/events",
"responseStatus": {
"code": 201,
"metadata": {}
},
"user": {
"groups": [
"system:authenticated"
],
"username": "system:kube-scheduler"
},
"annotations": {
"authorization.k8s.io/reason": "RBAC: allowed by ClusterRoleBinding \"system:kube-scheduler\" of ClusterRole \"system:kube-scheduler\" to User \"system:kube-scheduler\"",
"authorization.k8s.io/decision": "allow"
},
"stageTimestamp": "2020-12-02T15:20:19.090835Z",
"userAgent": "kube-scheduler/v1.19.4 (linux/amd64) kubernetes/d360454/scheduler",
"objectRef": {
"namespace": "kube-system",
"name": "kube-scheduler.164cef6d1f3ed55e",
"apiVersion": "v1",
"resource": "events"
},
"responseObject": {
"type": "Normal",
"firstTimestamp": "2020-12-02T15:20:19Z",
"involvedObject": {
"namespace": "kube-system",
"name": "kube-scheduler",
"apiVersion": "v1",
"resourceVersion": "2573",
"uid": "0ebf0ea5-f8c0-475a-9c9e-57674edefe8d",
"kind": "Endpoints"
},
"message": "****1_938d6a87-bccb-4ea0-bd6b-31fc27e48b7a became leader",
"eventTime": null,
"source": {
"component": "default-scheduler"
},
"reason": "LeaderElection",
"count": 1,
"reportingInstance": "",
"apiVersion": "v1",
"reportingComponent": "",
"lastTimestamp": "2020-12-02T15:20:19Z",
"metadata": {
"name": "kube-scheduler.164cef6d1f3ed55e",
"namespace": "kube-system",
"creationTimestamp": "2020-12-02T15:20:19Z",
"managedFields": [
{
"operation": "Update",
"fieldsType": "FieldsV1",
"time": "2020-12-02T15:20:19Z",
"manager": "kube-scheduler",
"apiVersion": "v1",
"fieldsV1": {
"f:source": {
"f:component": {}
},
"f:lastTimestamp": {},
"f:reason": {},
"f:firstTimestamp": {},
"f:type": {},
"f:involvedObject": {
"f:kind": {},
"f:namespace": {},
"f:name": {},
"f:apiVersion": {},
"f:uid": {},
"f:resourceVersion": {}
},
"f:message": {},
"f:count": {}
}
}
],
"resourceVersion": "2576",
"selfLink": "/api/v1/namespaces/kube-system/events/kube-scheduler.164cef6d1f3ed55e",
"uid": "573e4082-7c38-473c-9116-a114be97a47d"
},
"kind": "Event"
},
"level": "RequestResponse",
"requestReceivedTimestamp": "2020-12-02T15:20:19.021481Z",
"auditID": "cf291b3f-f5fa-4e43-a177-adf9cbfc0197",
"sourceIPs": [
"****"
],
"stage": "ResponseComplete",
"verb": "create"
}
],
"#timestamp": "2020-12-02T15:20:19.094Z",
"type": "json",
"metadata": {},
"kind": "EventList"
}
}
And here's the JSON for that error happens :
{
"headers": {
"content_type": "application/json",
"request_method": "POST",
"accept_encoding": "gzip",
"request_path": "/",
"http_host": "****:8888",
"http_accept": "application/json, */*",
"content_length": "2668",
"http_version": "HTTP/1.1",
"http_user_agent": "Go-http-client/1.1"
},
"#version": "1",
"host": "****",
"apiVersion": "audit.k8s.io/v1",
"items": [
{
"requestObject": {
"metadata": {
"name": "kube-scheduler",
"namespace": "kube-system",
"creationTimestamp": "2020-12-02T14:36:33Z",
"annotations": {
"control-plane.alpha.kubernetes.io/leader": "{\"holderIdentity\":\"****38d6a87-bccb-4ea0-bd6b-31fc27e48b7a\",\"leaseDurationSeconds\":15,\"acquireTime\":\"2020-12-02T15:18:52Z\",\"renewTime\":\"2020-12-02T15:18:52Z\",\"leaderTransitions\":67}"
},
"managedFields": [
{
"operation": "Update",
"fieldsType": "FieldsV1",
"time": "2020-12-02T15:18:23Z",
"manager": "kube-scheduler",
"apiVersion": "v1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
".": {},
"f:control-plane.alpha.kubernetes.io/leader": {}
}
}
}
}
],
"resourceVersion": "2531",
"selfLink": "/api/v1/namespaces/kube-system/endpoints/kube-scheduler",
"uid": "0ebf0ea5-f8c0-475a-9c9e-57674edefe8d"
},
"apiVersion": "v1",
"kind": "Endpoints"
},
"requestURI": "/api/v1/namespaces/kube-system/endpoints/kube-scheduler?timeout=10s",
"responseStatus": {
"code": 200,
"metadata": {}
},
"user": {
"groups": [
"system:authenticated"
],
"username": "system:kube-scheduler"
},
"annotations": {
"authorization.k8s.io/reason": "RBAC: allowed by ClusterRoleBinding \"system:kube-scheduler\" of ClusterRole \"system:kube-scheduler\" to User \"system:kube-scheduler\"",
"authorization.k8s.io/decision": "allow"
},
"stageTimestamp": "2020-12-02T15:18:52.067347Z",
"userAgent": "kube-scheduler/v1.19.4 (linux/amd64) kubernetes/d360454/leader-election",
"objectRef": {
"namespace": "kube-system",
"name": "kube-scheduler",
"apiVersion": "v1",
"resourceVersion": "2531",
"uid": "0ebf0ea5-f8c0-475a-9c9e-57674edefe8d",
"resource": "endpoints"
},
"responseObject": {
"metadata": {
"name": "kube-scheduler",
"namespace": "kube-system",
"creationTimestamp": "2020-12-02T14:36:33Z",
"annotations": {
"control-plane.alpha.kubernetes.io/leader": "{\"holderIdentity\":\"****1_938d6a87-bccb-4ea0-bd6b-31fc27e48b7a\",\"leaseDurationSeconds\":15,\"acquireTime\":\"2020-12-02T15:18:52Z\",\"renewTime\":\"2020-12-02T15:18:52Z\",\"leaderTransitions\":67}"
},
"managedFields": [
{
"operation": "Update",
"fieldsType": "FieldsV1",
"time": "2020-12-02T15:18:52Z",
"manager": "kube-scheduler",
"apiVersion": "v1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
".": {},
"f:control-plane.alpha.kubernetes.io/leader": {}
}
}
}
}
],
"resourceVersion": "2542",
"selfLink": "/api/v1/namespaces/kube-system/endpoints/kube-scheduler",
"uid": "0ebf0ea5-f8c0-475a-9c9e-57674edefe8d"
},
"apiVersion": "v1",
"kind": "Endpoints"
},
"level": "RequestResponse",
"requestReceivedTimestamp": "2020-12-02T15:18:52.062449Z",
"auditID": "a45860c7-e0c9-4724-be2e-705a1b2955f4",
"sourceIPs": [
"****"
],
"stage": "ResponseComplete",
"verb": "update"
}
],
"#timestamp": "2020-12-02T15:20:22.001Z",
"type": "json",
"metadata": {},
"kind": "EventList"
}
(I removed some personnal data from the JSONs)
Both JSONs appears as valid. I noticed that the JSONs with responseStatus.code = 201 were correctly processed, and those with code = 200 were throwing this error.
I'm getting a bit mad so if anyone can help with that, I'd be very pleased !
The error is thrown on this line because subfields has a length of 0 and hence it is trying to access index -1, which is not allowed.
The method that splits the field names into pathsis called splitAndValidatePath and what it does is to split field names when it encounters . (i.e. a dot).
In your second document, you have two fields called "." (i.e. it is just a dot) and they are not really valid.
".": {},
If you remove them both, your document will be indexed correctly.
Another way of solving this is to disable indexing for the parent f:annotations object field and that will do the trick... provided, of course, you don't need to search for content within f:annotations.
I face same problem with fluentd.
As per #val suggestion. Fixed by below.
PUT /[index_name]/_mapping
{
"properties" : {
"metadata" : {
"properties" : {
"managedFields" : {
"properties" : {
"fieldsV1" : {
"properties" : {
"f:metadata" : {
"type" : "object",
"enabled": false
}
}
}
}
}
}
}
}
}

switch from WebSocket to RawSocket Transport

I am new to crossbar/autobahn framework and to network programming in general, recently at work we would like to experiment to move from WebSocket transport to RawSocket Transport with using MessagePackSerializer and do performance comparison. I am requesting to the framework developers to please guide me to convert following config to use raw socket. will using auth settings from ws section should work ?
{
"version": 2,
"workers": [
{
"type": "router",
"options": {
"pythonpath": ["../components"]
},
"realms": [
{
"name": "realm1",
"roles": [
{
"name": "system",
"authorizer": "com.XXXX.auth.authorize"
},
{
"name": "user",
"authorizer": "com.XXXX.auth.authorize"
},
{
"name": "service",
"authorizer": "com.XXXX.auth.authorize"
}
]
}
],
"transports": [
{
"type": "rawsocket",
"endpoint": {
"type": "unix",
"path": "/tmp/crossbar-socket"
}
},
{
"type": "web",
"endpoint": {
"type": "tcp",
"port": 8080
},
"paths": {
"status": {
"type": "resource",
"classname": "health_web_indicator.run",
"extra": {
"DVMT_VERSION": "2.0.1",
"HEALTHY_INDICATOR": ":) DVMT UP",
"UNHEALTHY_INDICATOR": ":( DVMT DOWN",
"MSSQL_DRIVER": "FreeTDS",
"MSSQL_SERVER": "XXXX.dv.local",
"MSSQL_PORT": "1515",
"MSSQL_DATABASE": "XXXX",
"MSSQL_USER": "XXXX",
"MSSQL_PASSWORD": "XXXX",
"SUPERVISOR_PROCESSES": ["XXXX", "XXXX", "XXXX", "XXXX", "XXXX"],
"SUPERVISOR_SERVER_SOCKET": "/crossbar/supervisord.sock"
}
},
"ws": {
"type": "websocket",
"auth": {
"anonymous": {
"type": "dynamic",
"authenticator": "com.XXXX.auth.authenticate"
},
"ticket": {
"type": "dynamic",
"authenticator": "com.XXXX.auth.authenticate"
}
},
"debug": true,
"options": {
"auto_ping_interval": 0,
"auto_ping_timeout": 60000,
"auto_ping_size": 4,
"compression": {
"deflate": {
"request_no_context_takeover": false,
"request_max_window_bits": 11,
"no_context_takeover": false,
"max_window_bits": 11,
"memory_level": 4
}
}
}
}
}
}
],
"components": [
{
"id": "auth",
"type": "class",
"classname": "auth.AuthComponent",
"realm": "realm1",
"role": "trusted",
"extra": {
"prefix": "com.XXXX.auth",
"system_role": "system",
"anonymous_role": "anonymous",
"mssql": {
"driver": "FreeTDS",
"server": "XXXX.dv.local",
"port": "1515",
"database": "XXXX",
"uid": "XXXX",
"pwd": "XXXX",
"autocommit": true
},
"heartbeat_rate": 30.0,
"ldap_api_url": "http://XXXX:80/rssapi/dvmsapi/admin/GetUserLdapGroups/{username}",
"enforce_cert_match": false,
"cert_sub_pattern": "[\\s_-]"
}
}
]
}
]
}
also will it be easy enough for you to please give me an example for using autobahnpython as a client for rawsocket transport. https://crossbar.io/docs/RawSocket-Transport/#example---connecting-transport

Google visualization - table data not rendered

I am struggling with google visualization api. I have defined following Spring controller that returns json representation of com.google.visualization.datasource.datatable.DataTable.
#RequestMapping(value = "/magento", method = RequestMethod.GET, headers = { "Accept=application/json" }, params = { "table" }, produces = "application/json; charset=utf-8")
public #ResponseBody
DataTable getMagentoCustomersTable() {
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
cd.add(new ColumnDescription("customerId", ValueType.TEXT,
"Customer Id"));
cd.add(new ColumnDescription("email", ValueType.TEXT, "Email"));
cd.add(new ColumnDescription("firstName", ValueType.TEXT, "First Name"));
cd.add(new ColumnDescription("lastName", ValueType.TEXT, "Last Name"));
data.addColumns(cd);
// Fill the data table.
try {
for (CustomerInterface customer : magentoService.getCustomers()
.getCustomers()) {
data.addRowFromValues(customer.getCustomerId(),
customer.getEmail(), customer.getFirstName(),
customer.getLastName());
}
} catch (TypeMismatchException e) {
System.out.println("Invalid type!");
}
return data;
}
Then I am using following ajax call to produce Table output
$.ajax({
url : "${pageContext.request.contextPath}/customer/magento.json",
data : {
table : null
},
dataType : 'json'
}).success(
function(response) {
// Create the data table.
var data = new google.visualization.DataTable(response);
// Set chart options
var options = {
'title' : 'Magento Customers',
'width' : 400,
'height' : 300
};
// Instantiate and draw our table, passing in some options.
var table = new google.visualization.Table(document
.getElementById('chart_div'));
table.draw(data, options);
});
Ajax call return valid json object with data. Table is created with expected number of rows, there is no error in processing js but all table rows are empty as well as column headers.
So my question is am I missing something? What could went wrong?
==EDIT==
Below you can see sample json returned from ajax call to client. When this json is passed to DataTable constructor it is created but I noticed that no columns are created in DataTable object whereas rows are.
{
"warnings": [],
"rows": [{
"customProperties": {},
"cells": [{
"value": {
"value": "1",
"type": "TEXT",
"null": false,
"objectToFormat": "1"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "lname1#gmail.com",
"type": "TEXT",
"null": false,
"objectToFormat": "lname1#gmail.com"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "fname1",
"type": "TEXT",
"null": false,
"objectToFormat": "fname1"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "lname1",
"type": "TEXT",
"null": false,
"objectToFormat": "lname1"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}]
}, {
"customProperties": {},
"cells": [{
"value": {
"value": "2",
"type": "TEXT",
"null": false,
"objectToFormat": "2"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "lname2#gmail.com",
"type": "TEXT",
"null": false,
"objectToFormat": "lname2#gmail.com"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "fname1",
"type": "TEXT",
"null": false,
"objectToFormat": "fname1"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}, {
"value": {
"value": "lname2",
"type": "TEXT",
"null": false,
"objectToFormat": "lname2"
},
"type": "TEXT",
"null": false,
"customProperties": {},
"formattedValue": null
}]
}],
"numberOfRows": 2,
"numberOfColumns": 4,
"columnDescriptions": [{
"id": "customerId",
"type": "TEXT",
"pattern": "",
"customProperties": {},
"label": "Customer Id"
}, {
"id": "email",
"type": "TEXT",
"pattern": "",
"customProperties": {},
"label": "Email"
}, {
"id": "firstName",
"type": "TEXT",
"pattern": "",
"customProperties": {},
"label": "First Name"
}, {
"id": "lastName",
"type": "TEXT",
"pattern": "",
"customProperties": {},
"label": "Last Name"
}],
"customProperties": {},
"localeForUserMessages": null
}

Resources