package com.ntlab.irisserver.resources; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import com.ntlab.irisserver.models.KeywordManager; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.IOException; @Component @Path("/keywords") public class KeywordsRest implements ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } @GET @Produces(MediaType.APPLICATION_JSON) public String[] getKeywords() throws IOException { String path; path = applicationContext.getResource("file:").getFile().getAbsolutePath() +"/apache-tomcat-9.0.10/webapps/iris/WEB-INF/classes/com/ntlab/irisserver/models/keywords.txt"; //path = "C:\\Users\\student\\Desktop\\IrisServer\\src\\main\\java\\com\\ntlab\\irisserver\\models\\keywords.txt"; KeywordManager km = KeywordManager.getInstance(); String[] keywords = km.getKeywords(path); return keywords; } }