logger.debug("Incoming request..." + content);
Response response = null;
- Map<String, String> params = new HashMap<String, String>();
- for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
- params.put(e.getKey(), e.getValue().get(0));
- }
+ Map<String, String> params = addParams ( uriInfo, false, type, version );
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
String propertiesKey = CrudProperties.get(CrudServiceConstants.CRD_COLLECTION_PROPERTIES_KEY);
-
- Map<String, String> filter = new HashMap<String, String>();
-
- for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
- if (!e.getKey().equals(propertiesKey)) {
- filter.put(e.getKey(), e.getValue().get(0));
- }
- }
+ Map<String, String> filter = addParams ( uriInfo, true, type, version );
HashSet<String> properties;
if (uriInfo.getQueryParameters().containsKey(propertiesKey)) {
logger.debug("Incoming request..." + content);
Response response = null;
- Map<String, String> params = new HashMap<String, String>();
- for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
- params.put(e.getKey(), e.getValue().get(0));
- }
+ Map<String, String> params = addParams ( uriInfo, false, type, version );
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
logger.debug("Incoming request..." + content);
Response response = null;
-
-
- Map<String, String> filter = new HashMap<String, String>();
- for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
- filter.put(e.getKey(), e.getValue().get(0));
- }
+ Map<String, String> filter = addParams ( uriInfo, true, type, version );
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
return false;
}
- String sourceOfTruth = null;
- if (headers.getRequestHeaders().containsKey("X-FromAppId")) {
- sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
- }
+ validateRequestHeader(headers);
+
+ return isValid;
+ }
+
+ public void validateRequestHeader(HttpHeaders headers) throws CrudException {
+ String sourceOfTruth = null;
+ if (headers.getRequestHeaders().containsKey("X-FromAppId")) {
+ sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
+ }
- if (sourceOfTruth == null || sourceOfTruth.trim() == "") {
- throw new CrudException("Invalid request, Missing X-FromAppId header", Status.BAD_REQUEST);
- }
+ if (sourceOfTruth == null || sourceOfTruth.trim() == "") {
+ throw new CrudException("Invalid request, Missing X-FromAppId header", Status.BAD_REQUEST);
+ }
+
+ String transId = null;
+ if (headers.getRequestHeaders().containsKey("X-TransactionId")) {
+ transId = headers.getRequestHeaders().getFirst("X-TransactionId");
+ }
- return isValid;
+ if (transId == null || transId.trim() == "") {
+ throw new CrudException("Invalid request, Missing X-TransactionId header", Status.BAD_REQUEST);
+ }
}
void logResult(Action op, String uri, Exception e) {
// uses our transaction id.
MDC.clear();
}
+
+ private Map<String, String> addParams ( UriInfo info, boolean filter, String type, String version ) {
+ String propertiesKey = CrudProperties.get ( CrudServiceConstants.CRD_COLLECTION_PROPERTIES_KEY );
+ Map<String, String> params = new HashMap<String, String> ();
+ params.put ( CrudServiceConstants.CRD_RESERVED_VERSION, version );
+ params.put ( CrudServiceConstants.CRD_RESERVED_NODE_TYPE, type );
+ if (filter) {
+ for (Map.Entry<String, List<String>> e : info.getQueryParameters ().entrySet ()) {
+ if (!e.getKey ().equals ( propertiesKey )) {
+ params.put ( e.getKey (), e.getValue ().get ( 0 ) );
+ }
+ }
+ } else {
+ for (Map.Entry<String, List<String>> e : info.getQueryParameters ().entrySet ()) {
+ params.put ( e.getKey (), e.getValue ().get ( 0 ) );
+ }
+ }
+ return params;
+ }
}