-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from christophd/issue/359/cloud-events
fix(#359): Improve Cloud events send/receive
- Loading branch information
Showing
7 changed files
with
201 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...eps/yaks-knative/src/main/java/org/citrusframework/yaks/knative/ce/CloudEventMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citrusframework.yaks.knative.ce; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.consol.citrus.http.message.HttpMessage; | ||
|
||
/** | ||
* @author Christoph Deppisch | ||
*/ | ||
public class CloudEventMessage extends HttpMessage { | ||
|
||
private final Map<CloudEvent.Attribute, Object> attributes = new HashMap<>(); | ||
|
||
public CloudEventMessage eventId(String id) { | ||
return setAttribute(CloudEvent.Attribute.ID, id); | ||
} | ||
|
||
public Object getEventId() { | ||
return getAttribute(CloudEvent.Attribute.ID); | ||
} | ||
|
||
public CloudEventMessage eventType(String type) { | ||
return setAttribute(CloudEvent.Attribute.TYPE, type); | ||
} | ||
|
||
public Object getEventType() { | ||
return getAttribute(CloudEvent.Attribute.TYPE); | ||
} | ||
|
||
public CloudEventMessage specVersion(String version) { | ||
return setAttribute(CloudEvent.Attribute.SPEC_VERSION, version); | ||
} | ||
|
||
public Object getSpecVersion() { | ||
return getAttribute(CloudEvent.Attribute.SPEC_VERSION); | ||
} | ||
|
||
public CloudEventMessage source(String source) { | ||
return setAttribute(CloudEvent.Attribute.SOURCE, source); | ||
} | ||
|
||
public Object getSource() { | ||
return getAttribute(CloudEvent.Attribute.SOURCE); | ||
} | ||
|
||
public CloudEventMessage subject(String subject) { | ||
return setAttribute(CloudEvent.Attribute.SUBJECT, subject); | ||
} | ||
|
||
public Object getSubject() { | ||
return getAttribute(CloudEvent.Attribute.SUBJECT); | ||
} | ||
|
||
public CloudEventMessage time(String time) { | ||
return setAttribute(CloudEvent.Attribute.TIME, time); | ||
} | ||
|
||
public Object getTime() { | ||
return getAttribute(CloudEvent.Attribute.TIME); | ||
} | ||
|
||
public CloudEventMessage dataSchema(String schema) { | ||
return setAttribute(CloudEvent.Attribute.DATA_SCHEMA, schema); | ||
} | ||
|
||
public Object getDataSchema() { | ||
return getAttribute(CloudEvent.Attribute.DATA_SCHEMA); | ||
} | ||
|
||
public Object getAttribute(CloudEvent.Attribute attribute) { | ||
return attributes.get(attribute); | ||
} | ||
|
||
public CloudEventMessage setAttribute(CloudEvent.Attribute attribute, Object value) { | ||
attributes.put(attribute, value); | ||
header(attribute.http(), value); | ||
return this; | ||
} | ||
|
||
public static CloudEventMessage fromEvent(CloudEvent event) { | ||
CloudEventMessage message = new CloudEventMessage(); | ||
|
||
event.attributes().stream() | ||
.filter(CloudEvent.Attribute::hasDefaultValue) | ||
.forEach(a -> message.setAttribute(a, a.defaultValue())); | ||
|
||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters