com.orange.ngsi.server.NgsiBaseController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ngsi-server Show documentation
Show all versions of ngsi-server Show documentation
NGSI v1 API server and client library
/*
* Copyright (C) 2015 Orange
*
* Licensed 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 com.orange.ngsi.server;
import com.orange.ngsi.ProtocolRegistry;
import com.orange.ngsi.exception.MissingRequestParameterException;
import com.orange.ngsi.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
/**
* Controller for the NGSI 9/10 requests
*/
public class NgsiBaseController {
private static Logger logger = LoggerFactory.getLogger(NgsiBaseController.class);
@Autowired
private NgsiValidation ngsiValidation;
@Autowired
private ProtocolRegistry protocolRegistry;
/*
* NGSI v1 API mapping
*/
@RequestMapping(value = "/notifyContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity notifyContextRequest(@RequestBody final NotifyContext notify, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkNotifyContext(notify);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(notifyContext(notify), HttpStatus.OK);
}
@RequestMapping(value = "/updateContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity updateContextRequest(@RequestBody final UpdateContext updateContext, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkUpdateContext(updateContext);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(updateContext(updateContext), HttpStatus.OK);
}
@RequestMapping(value = "/registerContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity registerContextRequest(@RequestBody final RegisterContext registerContext, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkRegisterContext(registerContext);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(registerContext(registerContext), HttpStatus.OK);
}
@RequestMapping(value = "/subscribeContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity subscribeContextRequest(@RequestBody final SubscribeContext subscribeContext, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkSubscribeContext(subscribeContext);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(subscribeContext(subscribeContext), HttpStatus.OK);
}
@RequestMapping(value = "/updateContextSubscription", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity updateContextSubscription(@RequestBody final UpdateContextSubscription updateContextSubscription, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkUpdateContextSubscription(updateContextSubscription);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(updateContextSubscription(updateContextSubscription), HttpStatus.OK);
}
@RequestMapping(value = "/unsubscribeContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity unsubscribeContextRequest(@RequestBody final UnsubscribeContext unsubscribeContext, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkUnsubscribeContext(unsubscribeContext);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(unsubscribeContext(unsubscribeContext), HttpStatus.OK);
}
@RequestMapping(value = "/queryContext", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
final public ResponseEntity queryContextRequest(@RequestBody final QueryContext queryContext, HttpServletRequest httpServletRequest) throws Exception {
ngsiValidation.checkQueryContext(queryContext);
registerIntoDispatcher(httpServletRequest);
return new ResponseEntity<>(queryContext(queryContext), HttpStatus.OK);
}
@ExceptionHandler({MissingRequestParameterException.class})
public ResponseEntity