Skip to content

Commit 56571eb

Browse files
author
Joerg Huber
committed
Added service type to sendEvent().
1 parent eaff69a commit 56571eb

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

SIF3InfraREST/SIF3REST/src/main/java/sif3/infra/rest/client/EventClient.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
import javax.ws.rs.core.MediaType;
2424
import javax.ws.rs.core.Response.Status;
2525

26+
import com.sun.jersey.api.client.ClientResponse;
27+
import com.sun.jersey.api.client.WebResource;
28+
import com.sun.jersey.api.client.WebResource.Builder;
29+
30+
import au.com.systemic.framework.utils.StringUtils;
2631
import sif3.common.CommonConstants;
2732
import sif3.common.conversion.MarshalFactory;
2833
import sif3.common.exception.ServiceInvokationException;
2934
import sif3.common.header.HeaderProperties;
3035
import sif3.common.header.HeaderValues;
3136
import sif3.common.header.HeaderValues.EventAction;
37+
import sif3.common.header.HeaderValues.ServiceType;
3238
import sif3.common.header.HeaderValues.UpdateType;
3339
import sif3.common.header.RequestHeaderConstants;
3440
import sif3.common.model.SIFContext;
@@ -38,11 +44,6 @@
3844
import sif3.infra.common.env.types.ConsumerEnvironment.ConnectorName;
3945
import sif3.infra.common.env.types.ProviderEnvironment;
4046
import sif3.infra.common.interfaces.ClientEnvironmentManager;
41-
import au.com.systemic.framework.utils.StringUtils;
42-
43-
import com.sun.jersey.api.client.ClientResponse;
44-
import com.sun.jersey.api.client.WebResource;
45-
import com.sun.jersey.api.client.WebResource.Builder;
4647

4748
/**
4849
* This class implements the function(s) required to publish REST SIF3 Events to a environment provider and/or broker. The event interface
@@ -112,14 +113,15 @@ public EventClient(ClientEnvironmentManager clientEnvMgr, MediaType requestMedia
112113
* @param event The event to be sent.
113114
* @param zone The zone for which this operation shall be invoked. Can be null which indicates the DEFAULT zone.
114115
* @param context The context for which this operation shall be invoked. Can be null which indicates the DEFAULT context.
116+
* @param serviceType The service type of the event (eg. OBJECT, FUNCTIONAL etc).
115117
* @param customHdrFields Custom HTTP header fields to be added to the request.
116118
*
117119
* @return BaseResponse Object holding appropriate values and results of the call. This call won't return any data model objects, just
118120
* status and/or an error message.
119121
*
120122
* @throws ServiceInvokationException Any underlying errors occurred such as failure to invoke actual web-service etc.
121123
*/
122-
public BaseResponse sendEvents(SIFEvent<?> event, SIFZone zone, SIFContext context, HeaderProperties customHdrFields) throws ServiceInvokationException
124+
public BaseResponse sendEvents(SIFEvent<?> event, SIFZone zone, SIFContext context, ServiceType serviceType, HeaderProperties customHdrFields) throws ServiceInvokationException
123125
{
124126
if (allOK) // Only send events if all is fine.
125127
{
@@ -143,15 +145,10 @@ public BaseResponse sendEvents(SIFEvent<?> event, SIFZone zone, SIFContext conte
143145
{
144146
// Don't set zone & context here. They are header parameters in the case of events.
145147
String payloadStr = getDataModelMarshaller().marshal(event.getSIFObjectList(), getRequestMediaType());
146-
147-
// if (logger.isDebugEnabled())
148-
// {
149-
// logger.debug("sendEvents: Payload to send:\n"+payloadStr);
150-
// }
151-
HeaderProperties headerProps = getEventHeaders(event.getEventAction(), event.getUpdateType(), event.getFingerprint(), zone, context, customHdrFields);
148+
HeaderProperties headerProps = getEventHeaders(event.getEventAction(), event.getUpdateType(), event.getFingerprint(), zone, context, serviceType, customHdrFields);
152149

153150
Builder builder = setRequestHeaderAndMediaTypes(service, headerProps, false, false, true);
154-
logger.debug("Send "+serviceName+" Event with payload size: "+payloadStr.length()+" to Zone = "+((zone == null) ? "default" : zone.getId())+" and Context = "+((context == null) ? "DEFAULT" : context.getId()));
151+
logger.debug("Send "+serviceName+" Event to Zone = "+((zone == null) ? "default" : zone.getId())+" and Context = "+((context == null) ? "DEFAULT" : context.getId()));
155152
ClientResponse response = builder.post(ClientResponse.class, payloadStr);
156153
logger.debug("Receive Event Response Status: "+response.getStatus());
157154

@@ -186,7 +183,7 @@ private ProviderEnvironment getProviderEnvironment()
186183
* @param context The context for this event. Can be null.
187184
* @return
188185
*/
189-
private HeaderProperties getEventHeaders(EventAction eventAction, UpdateType updateType, String fingerprint, SIFZone zone, SIFContext context, HeaderProperties overrideHdrFields)
186+
private HeaderProperties getEventHeaders(EventAction eventAction, UpdateType updateType, String fingerprint, SIFZone zone, SIFContext context, ServiceType serviceType, HeaderProperties overrideHdrFields)
190187
{
191188
// Set the override header fields
192189
HeaderProperties hdrProperties = (overrideHdrFields != null) ? new HeaderProperties(overrideHdrFields.getHeaderProperties()) : new HeaderProperties();
@@ -197,7 +194,7 @@ private HeaderProperties getEventHeaders(EventAction eventAction, UpdateType upd
197194
// Add event specific properties
198195
hdrProperties.setHeaderProperty(RequestHeaderConstants.HDR_MESSAGE_TYPE, HeaderValues.MessageType.EVENT.name());
199196
hdrProperties.setHeaderProperty(RequestHeaderConstants.HDR_EVENT_ACTION, eventAction.name());
200-
hdrProperties.setHeaderProperty(RequestHeaderConstants.HDR_SERVICE_TYPE, HeaderValues.ServiceType.OBJECT.name());
197+
hdrProperties.setHeaderProperty(RequestHeaderConstants.HDR_SERVICE_TYPE, serviceType.name());
201198
hdrProperties.setHeaderProperty(RequestHeaderConstants.HDR_SERVICE_NAME, serviceName);
202199

203200
if (eventAction == EventAction.UPDATE)

0 commit comments

Comments
 (0)