2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.crud.service;
26 import org.apache.cxf.jaxrs.ext.PATCH;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aaiauth.auth.Auth;
30 import org.onap.crud.exception.CrudException;
31 import org.onap.crud.logging.CrudServiceMsgs;
32 import org.onap.crud.logging.LoggingUtil;
33 import org.onap.crud.util.CrudServiceConstants;
36 import java.security.cert.X509Certificate;
37 import java.util.HashMap;
38 import java.util.List;
40 import javax.security.auth.x500.X500Principal;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.ws.rs.Consumes;
43 import javax.ws.rs.DELETE;
44 import javax.ws.rs.Encoded;
45 import javax.ws.rs.GET;
46 import javax.ws.rs.POST;
47 import javax.ws.rs.PUT;
48 import javax.ws.rs.Path;
49 import javax.ws.rs.PathParam;
50 import javax.ws.rs.Produces;
51 import javax.ws.rs.core.Context;
52 import javax.ws.rs.core.HttpHeaders;
53 import javax.ws.rs.core.MediaType;
54 import javax.ws.rs.core.Response;
55 import javax.ws.rs.core.Response.Status;
56 import javax.ws.rs.core.UriInfo;
59 public class CrudAsyncRestService {
61 private CrudAsyncGraphDataService crudAsyncGraphDataService;
62 Logger logger = LoggerFactory.getInstance().getLogger(CrudAsyncRestService.class.getName());
63 Logger auditLogger = LoggerFactory.getInstance()
64 .getAuditLogger(CrudAsyncRestService.class.getName());
67 private String mediaType = MediaType.APPLICATION_JSON;
68 public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override";
70 public CrudAsyncRestService(CrudAsyncGraphDataService crudAsyncGraphDataService)
72 this.crudAsyncGraphDataService = crudAsyncGraphDataService;
73 this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE);
77 POST, GET, PUT, DELETE, PATCH
80 public void startup() {
85 @Path("/{version}/{type}/{id}")
86 @Consumes({MediaType.APPLICATION_JSON})
87 @Produces({MediaType.APPLICATION_JSON})
88 public Response getVertex(String content, @PathParam("version") String version,
89 @PathParam("type") String type,
90 @PathParam("id") String id, @PathParam("uri") @Encoded String uri,
91 @Context HttpHeaders headers,
92 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
93 LoggingUtil.initMdcContext(req, headers);
95 logger.debug("Incoming request..." + content);
96 Response response = null;
98 if (validateRequest(req, uri, content, Action.GET,
99 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
102 String result = crudAsyncGraphDataService.getVertex(version, id, type);
103 response = Response.status(Status.OK).entity(result).type(mediaType).build();
104 } catch (CrudException ce) {
105 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
106 } catch (Exception e) {
107 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
110 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
114 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
119 @Path("/{version}/{type}/")
120 @Consumes({MediaType.APPLICATION_JSON})
121 @Produces({MediaType.APPLICATION_JSON})
122 public Response getVertices(String content, @PathParam("version") String version,
123 @PathParam("type") String type,
124 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
125 @Context UriInfo uriInfo,
126 @Context HttpServletRequest req) {
128 LoggingUtil.initMdcContext(req, headers);
130 logger.debug("Incoming request..." + content);
131 Response response = null;
132 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
134 Map<String, String> filter = new HashMap<String, String>();
135 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
136 filter.put(e.getKey(), e.getValue().get(0));
140 String result = crudAsyncGraphDataService.getVertices(version, type, filter);
141 response = Response.status(Status.OK).entity(result).type(mediaType).build();
142 } catch (CrudException ce) {
143 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
144 } catch (Exception e) {
145 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
148 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
152 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
157 @Path("/relationships/{version}/{type}/{id}")
158 @Consumes({MediaType.APPLICATION_JSON})
159 @Produces({MediaType.APPLICATION_JSON})
160 public Response getEdge(String content, @PathParam("version") String version,
161 @PathParam("type") String type,
162 @PathParam("id") String id, @PathParam("uri") @Encoded String uri,
163 @Context HttpHeaders headers,
164 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
165 LoggingUtil.initMdcContext(req, headers);
167 logger.debug("Incoming request..." + content);
168 Response response = null;
170 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
174 String result = crudAsyncGraphDataService.getEdge(version, id, type);
175 response = Response.status(Status.OK).entity(result).type(mediaType).build();
176 } catch (CrudException ce) {
177 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
178 } catch (Exception e) {
179 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
182 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
186 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
191 @Path("/relationships/{version}/{type}/")
192 @Consumes({MediaType.APPLICATION_JSON})
193 @Produces({MediaType.APPLICATION_JSON})
194 public Response getEdges(String content, @PathParam("version") String version,
195 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
196 @Context HttpHeaders headers, @Context UriInfo uriInfo,
197 @Context HttpServletRequest req) {
199 LoggingUtil.initMdcContext(req, headers);
201 logger.debug("Incoming request..." + content);
202 Response response = null;
204 if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
206 Map<String, String> filter = new HashMap<String, String>();
207 for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
208 filter.put(e.getKey(), e.getValue().get(0));
212 String result = crudAsyncGraphDataService.getEdges(version, type, filter);
213 response = Response.status(Status.OK).entity(result).type(mediaType).build();
214 } catch (CrudException ce) {
215 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
216 } catch (Exception e) {
217 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
220 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
225 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
230 @Path("/relationships/{version}/{type}/{id}")
231 @Consumes({MediaType.APPLICATION_JSON})
232 @Produces({MediaType.APPLICATION_JSON})
233 public Response updateEdge(String content, @PathParam("version") String version,
234 @PathParam("type") String type, @PathParam("id") String id,
235 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
236 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
238 LoggingUtil.initMdcContext(req, headers);
240 logger.debug("Incoming request..." + content);
241 Response response = null;
243 if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
246 EdgePayload payload = EdgePayload.fromJson(content);
247 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
248 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
250 if (payload.getId() != null && !payload.getId().equals(id)) {
251 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
255 if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null
256 && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE)
257 .equalsIgnoreCase("PATCH")) {
258 result = crudAsyncGraphDataService.patchEdge(version, id, type, payload);
261 result = crudAsyncGraphDataService.updateEdge(version, id, type, payload);
264 response = Response.status(Status.OK).entity(result).type(mediaType).build();
265 } catch (CrudException ce) {
266 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
267 } catch (Exception e) {
268 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
271 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
276 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
281 @Path("/relationships/{version}/{type}/{id}")
282 @Consumes({"application/merge-patch+json"})
283 @Produces({MediaType.APPLICATION_JSON})
284 public Response patchEdge(String content, @PathParam("version") String version,
285 @PathParam("type") String type, @PathParam("id") String id,
286 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
287 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
289 LoggingUtil.initMdcContext(req, headers);
291 logger.debug("Incoming request..." + content);
292 Response response = null;
293 if (validateRequest(req, uri, content, Action.PATCH,
294 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
297 EdgePayload payload = EdgePayload.fromJson(content);
298 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
299 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
301 if (payload.getId() != null && !payload.getId().equals(id)) {
302 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
305 String result = crudAsyncGraphDataService.patchEdge(version, id, type, payload);
306 response = Response.status(Status.OK).entity(result).type(mediaType).build();
307 } catch (CrudException ce) {
308 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
309 } catch (Exception e) {
310 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
313 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
317 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
322 @Path("/{version}/{type}/{id}")
323 @Consumes({MediaType.APPLICATION_JSON})
324 @Produces({MediaType.APPLICATION_JSON})
325 public Response updateVertex(String content, @PathParam("version") String version,
326 @PathParam("type") String type, @PathParam("id") String id,
327 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
328 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
330 LoggingUtil.initMdcContext(req, headers);
332 logger.debug("Incoming request..." + content);
333 Response response = null;
335 if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
338 VertexPayload payload = VertexPayload.fromJson(content);
339 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
340 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
342 if (payload.getId() != null && !payload.getId().equals(id)) {
343 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
346 if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null
347 && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE)
348 .equalsIgnoreCase("PATCH")) {
349 result = crudAsyncGraphDataService.patchVertex(version, id, type, payload);
352 result = crudAsyncGraphDataService.updateVertex(version, id, type, payload);
354 response = Response.status(Status.OK).entity(result).type(mediaType).build();
355 } catch (CrudException ce) {
356 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
357 } catch (Exception e) {
358 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
361 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
365 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
370 @Path("/{version}/{type}/{id}")
371 @Consumes({"application/merge-patch+json"})
372 @Produces({MediaType.APPLICATION_JSON})
373 public Response patchVertex(String content, @PathParam("version") String version,
374 @PathParam("type") String type, @PathParam("id") String id,
375 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
376 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
378 LoggingUtil.initMdcContext(req, headers);
380 logger.debug("Incoming request..." + content);
381 Response response = null;
383 if (validateRequest(req, uri, content, Action.PATCH,
384 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
386 VertexPayload payload = VertexPayload.fromJson(content);
387 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
388 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
390 if (payload.getId() != null && !payload.getId().equals(id)) {
391 throw new CrudException("ID Mismatch", Status.BAD_REQUEST);
394 String result = crudAsyncGraphDataService.patchVertex(version, id, type, payload);
395 response = Response.status(Status.OK).entity(result).type(mediaType).build();
396 } catch (CrudException ce) {
397 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
398 } catch (Exception e) {
399 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
402 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
406 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
411 @Path("/{version}/{type}/")
412 @Consumes({MediaType.APPLICATION_JSON})
413 @Produces({MediaType.APPLICATION_JSON})
414 public Response addVertex(String content, @PathParam("version") String version,
415 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
416 @Context HttpHeaders headers, @Context UriInfo uriInfo,
417 @Context HttpServletRequest req) {
419 LoggingUtil.initMdcContext(req, headers);
421 logger.debug("Incoming request..." + content);
422 Response response = null;
424 if (validateRequest(req, uri, content, Action.POST,
425 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
428 VertexPayload payload = VertexPayload.fromJson(content);
429 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
430 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
432 if (payload.getId() != null) {
433 throw new CrudException("ID specified , use Http PUT to update Vertex",
437 if (payload.getType() != null && !payload.getType().equals(type)) {
438 throw new CrudException("Vertex Type mismatch", Status.BAD_REQUEST);
441 String result = crudAsyncGraphDataService.addVertex(version, type, payload);
442 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
443 } catch (CrudException ce) {
444 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
445 } catch (Exception e) {
446 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
449 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
453 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
459 @Consumes({MediaType.APPLICATION_JSON})
460 @Produces({MediaType.APPLICATION_JSON})
461 public Response addVertex(String content, @PathParam("version") String version,
462 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
463 @Context UriInfo uriInfo,
464 @Context HttpServletRequest req) {
466 LoggingUtil.initMdcContext(req, headers);
468 logger.debug("Incoming request..." + content);
469 Response response = null;
471 if (validateRequest(req, uri, content, Action.POST,
472 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
475 VertexPayload payload = VertexPayload.fromJson(content);
476 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
477 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
479 if (payload.getId() != null) {
480 throw new CrudException("ID specified , use Http PUT to update Vertex",
484 if (payload.getType() == null || payload.getType().isEmpty()) {
485 throw new CrudException("Missing Vertex Type ", Status.BAD_REQUEST);
487 String result = crudAsyncGraphDataService.addVertex(version, payload.getType(), payload);
488 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
489 } catch (CrudException ce) {
490 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
491 } catch (Exception e) {
492 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
495 response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON)
499 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
504 @Path("/relationships/{version}/{type}/")
505 @Consumes({MediaType.APPLICATION_JSON})
506 @Produces({MediaType.APPLICATION_JSON})
507 public Response addEdge(String content, @PathParam("version") String version,
508 @PathParam("type") String type, @PathParam("uri") @Encoded String uri,
509 @Context HttpHeaders headers, @Context UriInfo uriInfo,
510 @Context HttpServletRequest req) {
512 LoggingUtil.initMdcContext(req, headers);
514 logger.debug("Incoming request..." + content);
515 Response response = null;
517 if (validateRequest(req, uri, content, Action.POST,
518 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
522 EdgePayload payload = EdgePayload.fromJson(content);
523 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
524 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
526 if (payload.getId() != null) {
527 throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);
530 if (payload.getType() != null && !payload.getType().equals(type)) {
531 throw new CrudException("Edge Type mismatch", Status.BAD_REQUEST);
533 String result = crudAsyncGraphDataService.addEdge(version, type, payload);
534 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
535 } catch (CrudException ce) {
536 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
537 } catch (Exception e) {
538 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
541 response = Response.status(Status.FORBIDDEN).entity(content)
542 .type(MediaType.APPLICATION_JSON).build();
545 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
550 @Path("/relationships/{version}/")
551 @Consumes({MediaType.APPLICATION_JSON})
552 @Produces({MediaType.APPLICATION_JSON})
553 public Response addEdge(String content, @PathParam("version") String version,
554 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
555 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
557 LoggingUtil.initMdcContext(req, headers);
559 logger.debug("Incoming request..." + content);
560 Response response = null;
562 if (validateRequest(req, uri, content, Action.POST,
563 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
567 EdgePayload payload = EdgePayload.fromJson(content);
568 if (payload.getProperties() == null || payload.getProperties().isJsonNull()) {
569 throw new CrudException("Invalid request Payload", Status.BAD_REQUEST);
571 if (payload.getId() != null) {
572 throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST);
575 if (payload.getType() == null || payload.getType().isEmpty()) {
576 throw new CrudException("Missing Edge Type ", Status.BAD_REQUEST);
578 String result = crudAsyncGraphDataService.addEdge(version, payload.getType(), payload);
580 response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
581 } catch (CrudException ce) {
582 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
583 } catch (Exception e) {
584 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
587 response = Response.status(Status.FORBIDDEN).entity(content)
588 .type(MediaType.APPLICATION_JSON).build();
591 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
596 @Path("/{version}/{type}/{id}")
597 @Consumes({MediaType.APPLICATION_JSON})
598 @Produces({MediaType.APPLICATION_JSON})
599 public Response deleteVertex(String content, @PathParam("version") String version,
600 @PathParam("type") String type, @PathParam("id") String id,
601 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
602 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
604 LoggingUtil.initMdcContext(req, headers);
606 logger.debug("Incoming request..." + content);
607 Response response = null;
609 if (validateRequest(req, uri, content, Action.DELETE,
610 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
614 String result = crudAsyncGraphDataService.deleteVertex(version, id, type);
615 response = Response.status(Status.OK).entity(result).type(mediaType).build();
616 } catch (CrudException ce) {
617 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
618 } catch (Exception e) {
619 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
622 response = Response.status(Status.FORBIDDEN).entity(content)
623 .type(MediaType.APPLICATION_JSON).build();
626 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
631 @Path("/relationships/{version}/{type}/{id}")
632 @Consumes({MediaType.APPLICATION_JSON})
633 @Produces({MediaType.APPLICATION_JSON})
634 public Response deleteEdge(String content, @PathParam("version") String version,
635 @PathParam("type") String type, @PathParam("id") String id,
636 @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers,
637 @Context UriInfo uriInfo, @Context HttpServletRequest req) {
639 LoggingUtil.initMdcContext(req, headers);
641 logger.debug("Incoming request..." + content);
642 Response response = null;
643 if (validateRequest(req, uri, content, Action.DELETE,
644 CrudServiceConstants.CRD_AUTH_POLICY_NAME)) {
648 String result = crudAsyncGraphDataService.deleteEdge(version, id, type);
649 response = Response.status(Status.OK).entity(result).type(mediaType).build();
650 } catch (CrudException ce) {
651 response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build();
652 } catch (Exception e) {
653 response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
656 response = Response.status(Status.FORBIDDEN).entity(content)
657 .type(MediaType.APPLICATION_JSON).build();
660 LoggingUtil.logRestRequest(logger, auditLogger, req, response);
664 protected boolean validateRequest(HttpServletRequest req, String uri, String content,
665 Action action, String authPolicyFunctionName) {
667 String cipherSuite = (String) req.getAttribute("javax.servlet.request.cipher_suite");
668 String authUser = null;
669 if (cipherSuite != null) {
670 X509Certificate[] certChain = (X509Certificate[]) req
671 .getAttribute("javax.servlet.request.X509Certificate");
672 X509Certificate clientCert = certChain[0];
673 X500Principal subjectDn = clientCert.getSubjectX500Principal();
674 authUser = subjectDn.toString();
676 return this.auth.validateRequest(authUser.toLowerCase(), action.toString()
677 + ":" + authPolicyFunctionName);
678 } catch (Exception e) {
679 logResult(action, uri, e);
684 void logResult(Action op, String uri, Exception e) {
686 logger.error(CrudServiceMsgs.EXCEPTION_DURING_METHOD_CALL, op.toString(),
687 uri, e.getStackTrace().toString());
689 // Clear the MDC context so that no other transaction inadvertently
690 // uses our transaction id.