Skip to content

Commit

Permalink
[#193] fixed responding to messages in JS client did not preserve the…
Browse files Browse the repository at this point in the history
… message "headers"

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Sep 7, 2022
1 parent 117bc2d commit 5eb16b7
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 72 deletions.
3 changes: 2 additions & 1 deletion javascript/lib/api/src/client/handles/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { ProtocolResponseValue } from '../request-factory/websocket-request-handler';
/* tslint:disable:bool-param-default no-identical-functions */
import { SubscribeRequest } from '../request-factory/websocket-request-sender';
import { ProtocolResponseValue } from '../request-factory/websocket-request-handler';

/**
* Handle to receive Events. To be able to subscribe to Events requestEvents() needs to be called first
Expand Down Expand Up @@ -136,6 +136,7 @@ export interface EventsHandle {
*
* @param thingId - The ID of the Thing the Feature belongs to.
* @param featureId - The ID of the Feature the Property belongs to.
* @param propertyPath - The path of the Feature Property.
* @param callback - The function that gets called for every Event.
* @param action - The action to listen for (eg. modify).
* @param subResources - Whether or not sub-resources of the Property should also trigger the callback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { AuthProvider, DittoURL } from '../../auth/auth-provider';
import { DefaultDittoProtocolEnvelope, DittoProtocolEnvelope, DittoProtocolResponse } from '../../model/ditto-protocol';
import { GenericResponse } from '../../model/response';
/* tslint:disable:no-duplicate-string */
import {
PromiseResponse,
RequestHandler,
ResilienceHandler,
ResilienceHandlerFactoryBuildStep,
WebSocketImplementationBuilderHandler,
WebSocketBindingMessage
WebSocketBindingMessage,
WebSocketImplementationBuilderHandler
} from './resilience/websocket-resilience-interfaces';
import { AuthProvider, DittoURL } from '../../auth/auth-provider';
import { DefaultDittoProtocolEnvelope, DittoProtocolEnvelope, DittoProtocolResponse } from '../../model/ditto-protocol';
import { GenericResponse } from '../../model/response';

/**
* A Factory for a WebSocketRequestSender.
Expand Down Expand Up @@ -245,6 +245,7 @@ abstract class Subscription {
action,
topic: message.topic,
path: message.path,
headers: message.headers,
value: message.value
});
}
Expand Down Expand Up @@ -314,6 +315,6 @@ export interface ProtocolResponseValue {
topic: string;
path: string;
action: string;
headers?: string;
headers?: { [key: string]: any };
value?: any;
}
4 changes: 2 additions & 2 deletions javascript/lib/api/src/model/ditto-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface DittoProtocolResponse {
path: string;
status: number;
headers: { [key: string]: any };
value: object;
value: any;

correlationId(): string | undefined;
}
Expand All @@ -86,7 +86,7 @@ class DefaultDittoProtocolResponse implements DittoProtocolResponse {
value: object;
status: number;

constructor(topic: string, headers: object, path: string, value: object, status: number) {
constructor(topic: string, headers: object, path: string, value: any, status: number) {
this.topic = topic;
this.headers = headers;
this.path = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { jest } from '@jest/globals';
import { ProtocolResponseValue } from '../../../src/client/request-factory/websocket-request-handler';
import { EventsHelper as H } from './events.helper';
import { Features } from '../../../src/model/things.model';
import { jest } from '@jest/globals';
import { EventsHelper as H } from './events.helper';

describe('WebSocket Commands Handle', () => {
jest.setTimeout(5000); // we need to tell jest, that it should also wait on promises ... default is 0 ms
Expand All @@ -35,6 +35,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -49,6 +50,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -63,6 +65,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/attributes`,
headers: {},
value: H.attributes
}
});
Expand All @@ -77,6 +80,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/attributes/${H.attributePath}`,
headers: {},
value: H.attribute
}
});
Expand All @@ -91,6 +95,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: '/features',
headers: {},
value: Features.toObject(H.features)
}
});
Expand All @@ -105,6 +110,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/features/${H.feature.id}`,
headers: {},
value: H.feature.toObject()
}
});
Expand All @@ -119,6 +125,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/definition`,
headers: {},
value: H.definition
}
});
Expand All @@ -133,6 +140,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/properties`,
headers: {},
value: H.properties
}
});
Expand All @@ -147,6 +155,7 @@ describe('WebSocket Commands Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/properties/${H.propertyPath}`,
headers: {},
value: H.property
}
});
Expand Down
13 changes: 11 additions & 2 deletions javascript/lib/api/tests/client/websocket/events.websocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { jest } from '@jest/globals';
import { ProtocolResponseValue } from '../../../src/client/request-factory/websocket-request-handler';
import { EventsHelper as H } from './events.helper';
import { Features } from '../../../src/model/things.model';
import { jest } from '@jest/globals';
import { EventsHelper as H } from './events.helper';

describe('WebSocket Events Handle', () => {
jest.setTimeout(5000); // we need to tell jest, that it should also wait on promises ... default is 0 ms
Expand All @@ -35,6 +35,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -49,6 +50,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -63,6 +65,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/attributes`,
headers: {},
value: H.attributes
}
});
Expand All @@ -77,6 +80,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/attributes/${H.attributePath}`,
headers: {},
value: H.attribute
}
});
Expand All @@ -91,6 +95,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: '/features',
headers: {},
value: Features.toObject(H.features)
}
});
Expand All @@ -105,6 +110,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/features/${H.feature.id}`,
headers: {},
value: H.feature.toObject()
}
});
Expand All @@ -119,6 +125,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/definition`,
headers: {},
value: H.definition
}
});
Expand All @@ -133,6 +140,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/properties`,
headers: {},
value: H.properties
}
});
Expand All @@ -147,6 +155,7 @@ describe('WebSocket Events Handle', () => {
topic,
action,
path: `/features/${H.feature.id}/properties/${H.propertyPath}`,
headers: {},
value: H.property
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { jest } from '@jest/globals';
/* tslint:disable:no-duplicate-string */
import { ProtocolResponseValue } from '../../../src/client/request-factory/websocket-request-handler';
import { EventsHelper as H } from './events.helper';
import { GenericResponse } from '../../../src/model/response';
import { jest } from '@jest/globals';
import { EventsHelper as H } from './events.helper';

const testWithoutResponse: (method: () => void, request: Request) => Promise<void> = (method: () => void, request: Request) => {
return new Promise<void>(resolve => {
Expand Down Expand Up @@ -171,6 +171,7 @@ describe('WebSocket Messages Handle', () => {
topic: standardTopic,
action: subject,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -186,6 +187,7 @@ describe('WebSocket Messages Handle', () => {
topic: standardTopic,
action: subject,
path: `/features/${H.feature.id}/outbox`,
headers: {},
value: H.thing.toObject()
}
});
Expand All @@ -201,6 +203,7 @@ describe('WebSocket Messages Handle', () => {
topic: standardTopic,
action: subject,
path: '/',
headers: {},
value: H.thing.toObject()
}
});
Expand Down

0 comments on commit 5eb16b7

Please sign in to comment.