Creating service
This commit is contained in:
parent
2a7f872ef6
commit
2066677c75
|
@ -1,5 +1,56 @@
|
||||||
package org.gcube.common.software.service.rest;
|
package org.gcube.common.software.service.rest;
|
||||||
|
|
||||||
public class Software {
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.common.software.analyser.Analyser;
|
||||||
|
import org.gcube.common.software.analyser.AnalyserFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
@Path("software")
|
||||||
|
public class Software {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(Software.class);
|
||||||
|
|
||||||
|
public static final String APPLICATION_JSON_CHARSET_UTF_8 = "application/json;charset=UTF-8";
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes(APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
@Produces(APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 202, condition = "The provided json is formally correct.")
|
||||||
|
})
|
||||||
|
public Response create(String json) {
|
||||||
|
try {
|
||||||
|
Analyser analyser = AnalyserFactory.getAnalyser(json);
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
analyser.analyse();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error while analysing\n{}", json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
|
return Response.status(Status.ACCEPTED).build();
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new InternalServerErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<!DOCTYPE xml>
|
<!DOCTYPE xml>
|
||||||
<web-app>
|
<web-app>
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>org.gcube.gcat.ResourceInitializer</servlet-name>
|
<servlet-name>org.gcube.common.software.service.ResourceInitializer</servlet-name>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
2 <servlet-name>default</servlet-name>
|
2 <servlet-name>default</servlet-name>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
3 <url-pattern>/api-docs/*</url-pattern>
|
3 <url-pattern>/api-docs/*</url-pattern>
|
||||||
4 </servlet-mapping>
|
4 </servlet-mapping>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>org.gcube.gcat.ResourceInitializer</servlet-name>
|
<servlet-name>org.gcube.common.software.service.ResourceInitializer</servlet-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
</web-app>
|
</web-app>
|
Loading…
Reference in New Issue