5757import sif3 .common .header .RequestHeaderConstants ;
5858import sif3 .common .header .ResponseHeaderConstants ;
5959import sif3 .common .interfaces .ChangesSinceProvider ;
60- import sif3 .common .interfaces .Provider ;
6160import sif3 .common .model .ACL .AccessRight ;
6261import sif3 .common .model .ACL .AccessType ;
6362import sif3 .common .model .AuthenticationInfo ;
9998import sif3 .infra .common .model .UpdateResponseType ;
10099import sif3 .infra .common .model .UpdateType ;
101100import sif3 .infra .common .model .UpdatesType ;
101+ import sif3 .infra .rest .provider .CoreProvider ;
102102import sif3 .infra .rest .resource .audit .AuditableResource ;
103103
104104/**
@@ -145,8 +145,9 @@ private enum EnvironmentQueryParams {solutionId, applicationKey, userToken, inst
145145 private MediaType responseMediaType = null ;
146146 private MediaType urlPostfixMimeType = null ;
147147 private AbstractSecurityService securityService = null ;
148+ private ServiceType serviceType = null ;
148149
149- public abstract EnvironmentManager getEnvironmentManager ();
150+ public abstract EnvironmentManager getEnvironmentManager ();
150151
151152 /**
152153 * The marshaller of the data model. The BaseResource class needs access in various places to the data model's marshaller functions.
@@ -196,6 +197,21 @@ public BaseResource(UriInfo uriInfo, HttpHeaders requestHeaders, Request request
196197 {
197198 setSifContext (new SIFContext (contextID ));
198199 }
200+
201+ // Extract serviceType from HTTP header. Pure convenience for the getServiceType() method.
202+ try
203+ {
204+ String serviceTypeStr = getSIFHeaderProperties ().getHeaderProperty (RequestHeaderConstants .HDR_SERVICE_TYPE );
205+ if (StringUtils .notEmpty (serviceTypeStr ))
206+ {
207+ serviceType = ServiceType .valueOf (serviceTypeStr .trim ().toUpperCase ());
208+ }
209+ }
210+ catch (IllegalArgumentException ex )
211+ {
212+ logger .warn ("An unknown vale for the HTTP Header 'serviceType' was provided. Valid values are: " +StringUtils .getNamesForEnum (ServiceType .class ));
213+ }
214+
199215 if (getAuthInfo () == null )
200216 {
201217 logger .error ("No authetication information found." );
@@ -222,6 +238,7 @@ public BaseResource(UriInfo uriInfo, HttpHeaders requestHeaders, Request request
222238 logger .debug ("URL Query Params : " + getQueryParameters ());
223239 logger .debug ("Zone ID : " + getSifZone ());
224240 logger .debug ("ContextID : " + getSifContext ());
241+ logger .debug ("Service Type : " + getServiceType ());
225242 logger .debug ("Security Service : " + ((getSecurityService () == null ) ? null : getSecurityService ().getClass ().getSimpleName ()));
226243 logger .debug ("Resource Init ok : " + allOK );
227244 }
@@ -280,7 +297,23 @@ public HeaderProperties getAllHTTPHeaderProperties()
280297 return this .allHTTPHdrProperties ;
281298 }
282299
283- /*
300+ /**
301+ * Returns the serviceType as given in the HTTP Header serviceType. This is a convenience method. If the service
302+ * type is not set (eg. infrastructure services, utility services) then null is returned.
303+ *
304+ * @return
305+ */
306+ public ServiceType getServiceType ()
307+ {
308+ return serviceType ;
309+ }
310+
311+ public void setServiceType (ServiceType serviceType )
312+ {
313+ this .serviceType = serviceType ;
314+ }
315+
316+ /*
284317 * If the request media type is not set it will try to get the media type from the URL Postfix. If that is not set either then XML is returned
285318 */
286319 public MediaType getRequestMediaType ()
@@ -714,7 +747,7 @@ protected String getChangesSinceMarker()
714747 * If the given provider implements the ChangesSinceProvider then a casted provider is returned otherwise
715748 * null is returned.
716749 */
717- protected ChangesSinceProvider getChangesSinceProvider (Provider provider )
750+ protected ChangesSinceProvider getChangesSinceProvider (CoreProvider provider )
718751 {
719752 if (ChangesSinceProvider .class .isAssignableFrom (provider .getClass ()))
720753 {
@@ -894,7 +927,7 @@ protected ErrorDetails validateInternalAuthToken(String userToken, String passwo
894927 {
895928 if ((getAuthInfo ().getSecurityServiceInfo () == null ) || StringUtils .isEmpty (getAuthInfo ().getSecurityServiceInfo ().getAuthenticationMethod ()))
896929 {
897- return new ErrorDetails (Status .UNAUTHORIZED .getStatusCode (), NOT_AUTHORIZED , "No Authentication Method set." , " Choose between Basic, SIF_HMACSHA256 or External Security as Authentication Method. Refer to SIF3 Specification for details." );
930+ return new ErrorDetails (Status .UNAUTHORIZED .getStatusCode (), NOT_AUTHORIZED , "No Authentication Method set. Choose between Basic, SIF_HMACSHA256 or External Security as Authentication Method. Refer to SIF3 Specification for details." , "Provider side check ." );
898931 }
899932
900933 if (getAuthInfo ().getSecurityServiceInfo ().getAuthenticationType () == AuthenticationType .Other )
@@ -1331,10 +1364,10 @@ protected void determineMediaTypes(MarshalFactory marshaller, UnmarshalFactory u
13311364
13321365 requestMediaType = validateAndExtractMimeType (unmarshaller , requestMediaType , urlPostfixMimeType , useDefaults );
13331366
1334- // set it to the value of the request if it is not set or wildcard
1367+ // set it to the value of the request if it is not set or wildcard. If request is not set (eg. for HTTP GET) use default of XML
13351368 if ((responseMediaType == null ) || (responseMediaType .isWildcardType ()))
13361369 {
1337- responseMediaType = requestMediaType ;
1370+ responseMediaType = requestMediaType == null ? MediaType . APPLICATION_XML_TYPE : requestMediaType ;
13381371 }
13391372
13401373 responseMediaType = validateAndExtractMimeType (marshaller , responseMediaType , urlPostfixMimeType , useDefaults );
0 commit comments