Resolve connection to influxDB in spring boot project

Viewed 953

I am trying to connect to an influxdb with my Spring Boot project which easily connects to a postgres db. This is my application-properties:

### Application server ###
server.port=8088

### DATABASE POSTGRES LOCAL ###
#spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://localhost:5432/xxxxres
spring.datasource.username=xxxx
spring.datasource.password=xxxx

### INFLUX ###
spring.influx.url=https://xxxxxx.it:66xx3
spring.influx.user=admin
spring.influx.password=xxx
spring.influx.database=xxx

I have created some REST calls that work with postgres but I can't do the same on influx. My doubt is in the connection to the influx db.

This is my Influx Entity:

@Measurement(name = "M_M_TEST")
public class MMEntity {

    @Column(name = "Time")
    private Integer time;

    @Column(name = "DUL5_L1_AUX_OTH_OTH_OTH.Active_Energy")
    private Integer DUL5_L1_AUX_OTH_OTH_OTH_Active_Energy;

    @Column(name = "DUL5_L1_AUX_OTH_OTH_OTH.Active_Power")
    private Integer DUL5_L1_AUX_OTH_OTH_OTH_Active_Power;
    }

This is my model:

    @Measurement(name = "M_M_TEST")
    public class MMModel { 
        private Integer time;
        private Integer DUL5_L1_AUX_OTH_OTH_OTH_Active_Energy;
        private Integer DUL5_L1_AUX_OTH_OTH_OTH_Active_Power;
    //GETTER & SETTER
        }

This is my Controller:

@Api(tags = { SwaggerTags.TAG_M_M_NAME })
@RequestMapping("/v1/basePath")
@RestController
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class MMController extends AbstractController{

    private static final Logger logger = LoggerFactory.getLogger(MMController.class);

    @Autowired
    MMService mMService;

    @ApiOperation(value = "Finds all values of MM")
    @GetMapping("/M-M/all")
    public List<MMModel> findAll() {
        final String METHOD_NAME = "findAll()";
        try {
            startLog(METHOD_NAME);
        final List<MonterotondoMarittimoEntity> result = monterotondoMarittimoService.findAll();

        final List<MonterotondoMarittimoModel> response = ModelMapUtils.createObject(result,
                MonterotondoMarittimoModel.class);
        endLog(METHOD_NAME, response);
        return response;
        } catch (final Exception e) {
            errorLog(METHOD_NAME, e);
            throw e;
        }
    }
}

And this is my Service:

@Service
public class MonterotondoMarittimoService extends AbstractService {

    @Autowired
    InfluxDB influxDB;

    @Value("${spring.influx.url}")
    private String influxDBUrl;

    @Value("${spring.influx.user}")
    private String userName;

    @Value("${spring.influx.password}")
    private String password;

    @Value("${spring.influx.database}")
    private String database;

    @Transactional
    public List<MMEntity> findAll() {
        final String METHOD_NAME = "findAll()";
        startLog(METHOD_NAME);
        List<MMEntity> result = new ArrayList<MMEntity>();
        final Query query = new Query("SELECT * FROM M_M LIMIT 10", database);
        QueryResult queryResult = influxDB.query(query);
        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
        result = resultMapper.toPOJO(queryResult, MMEntity.class);
        endLog(METHOD_NAME, result);
        return result;
    }
}

I want to get all the elements present in the table M_M with a findAll method. But When I execute the method with my Swagger I get 500 error with this log ("org.influxdb.InfluxDBIOException: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target") Is a class required to configure the connection to Influx?
What can I do to solve my problem? Please, help me.

0 Answers
Related