use of jakarta.ws.rs.WebApplicationException in project OpenGrok by OpenGrok.
the class IndexerUtil method enableProjects.
/**
* Enable projects in the remote host application.
* <p>
* NOTE: performs a check if the projects are already enabled,
* before making the change request
*
* @param host the url to the remote host
* @throws ResponseProcessingException in case processing of a received HTTP response fails
* @throws ProcessingException in case the request processing or subsequent I/O operation fails
* @throws WebApplicationException in case the response status code of the response returned by the server is not successful
*/
public static void enableProjects(final String host) throws ResponseProcessingException, ProcessingException, WebApplicationException {
final Invocation.Builder request = ClientBuilder.newClient().target(host).path("api").path("v1").path("configuration").path("projectsEnabled").request().headers(getWebAppHeaders());
final String enabled = request.get(String.class);
if (!Boolean.parseBoolean(enabled)) {
final Response r = request.put(Entity.text(Boolean.TRUE.toString()));
if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
throw new WebApplicationException(String.format("Unable to enable projects: %s", r.getStatusInfo().getReasonPhrase()), r.getStatus());
}
}
}
use of jakarta.ws.rs.WebApplicationException in project OpenGrok by OpenGrok.
the class ProjectsController method get.
@GET
@Path("/{project}/property/{field}")
@Produces(MediaType.APPLICATION_JSON)
public Object get(@PathParam("project") String projectName, @PathParam("field") String field) throws IOException {
// Avoid classification as a taint bug.
projectName = Laundromat.launderInput(projectName);
field = Laundromat.launderInput(field);
Project project = env.getProjects().get(projectName);
if (project == null) {
throw new WebApplicationException("cannot find project " + projectName + " to get a property", Response.Status.BAD_REQUEST);
}
return ClassUtil.getFieldValue(project, field);
}
use of jakarta.ws.rs.WebApplicationException in project OpenGrok by OpenGrok.
the class SearchController method search.
@GET
@CorsEnable
@Produces(MediaType.APPLICATION_JSON)
public SearchResult search(@Context final HttpServletRequest req, @QueryParam(QueryParameters.FULL_SEARCH_PARAM) final String full, // Nearly QueryParameters.DEFS_SEARCH_PARAM
@QueryParam("def") final String def, // Akin to QueryBuilder.REFS_SEARCH_PARAM
@QueryParam("symbol") final String symbol, @QueryParam(QueryParameters.PATH_SEARCH_PARAM) final String path, @QueryParam(QueryParameters.HIST_SEARCH_PARAM) final String hist, @QueryParam(QueryParameters.TYPE_SEARCH_PARAM) final String type, @QueryParam("projects") final List<String> projects, // Akin to QueryParameters.COUNT_PARAM
@QueryParam("maxresults") @DefaultValue(MAX_RESULTS + "") final int maxResults, @QueryParam(QueryParameters.START_PARAM) @DefaultValue(0 + "") final int startDocIndex) {
try (SearchEngineWrapper engine = new SearchEngineWrapper(full, def, symbol, path, hist, type)) {
if (!engine.isValid()) {
throw new WebApplicationException("Invalid request", Response.Status.BAD_REQUEST);
}
Instant startTime = Instant.now();
suggester.onSearch(projects, engine.getQuery());
Map<String, List<SearchHit>> hits = engine.search(req, projects, startDocIndex, maxResults).stream().collect(Collectors.groupingBy(Hit::getPath, Collectors.mapping(h -> new SearchHit(h.getLine(), h.getLineno()), Collectors.toList())));
long duration = Duration.between(startTime, Instant.now()).toMillis();
int endDocument = startDocIndex + hits.size() - 1;
return new SearchResult(duration, engine.numResults, hits, startDocIndex, endDocument);
}
}
use of jakarta.ws.rs.WebApplicationException in project OpenGrok by OpenGrok.
the class SuggesterController method getSuggestions.
/**
* Returns suggestions based on the search criteria specified in {@code data}.
* @param data suggester form data
* @return list of suggestions and other related information
* @throws ParseException if the Lucene query created from {@code data} could not be parsed
*/
@GET
@Authorized
@CorsEnable
@Produces(MediaType.APPLICATION_JSON)
public Result getSuggestions(@Valid @BeanParam final SuggesterQueryData data) throws ParseException {
Instant start = Instant.now();
SuggesterData suggesterData = SuggesterQueryDataParser.parse(data);
if (suggesterData.getSuggesterQuery() == null) {
throw new ParseException("Could not determine suggester query");
}
SuggesterConfig config = env.getSuggesterConfig();
modifyDataBasedOnConfiguration(suggesterData, config);
if (!satisfiesConfiguration(suggesterData, config)) {
logger.log(Level.FINER, "Suggester request with data {0} does not satisfy configuration settings", data);
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Suggestions suggestions = suggester.getSuggestions(suggesterData.getProjects(), suggesterData.getSuggesterQuery(), suggesterData.getQuery());
Instant end = Instant.now();
long timeInMs = Duration.between(start, end).toMillis();
return new Result(suggestions.getItems(), suggesterData.getIdentifier(), suggesterData.getSuggesterQueryFieldText(), timeInMs, suggestions.isPartialResult());
}
Aggregations