Search in sources :

Example 61 with GET

use of javax.ws.rs.GET in project zeppelin by apache.

the class NotebookRestApi method getCronJob.

/**
   * Get cron job REST API
   *
   * @param noteId ID of Note
   * @return JSON with status.OK
   * @throws IOException, IllegalArgumentException
   */
@GET
@Path("cron/{noteId}")
@ZeppelinApi
public Response getCronJob(@PathParam("noteId") String noteId) throws IOException, IllegalArgumentException {
    LOG.info("Get cron job note {}", noteId);
    Note note = notebook.getNote(noteId);
    checkIfNoteIsNotNull(note);
    checkIfUserCanRead(noteId, "Insufficient privileges you cannot get cron information");
    return new JsonResponse<>(Status.OK, note.getConfig().get("cron")).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) GET(javax.ws.rs.GET)

Example 62 with GET

use of javax.ws.rs.GET in project zeppelin by apache.

the class InterpreterRestApi method getMetaInfo.

/**
   * get the metainfo property value
   */
@GET
@Path("getmetainfos/{settingId}")
public Response getMetaInfo(@Context HttpServletRequest req, @PathParam("settingId") String settingId) {
    String propName = req.getParameter("propName");
    if (propName == null) {
        return new JsonResponse<>(Status.BAD_REQUEST).build();
    }
    String propValue = null;
    InterpreterSetting interpreterSetting = interpreterSettingManager.get(settingId);
    Map<String, String> infos = interpreterSetting.getInfos();
    if (infos != null) {
        propValue = infos.get(propName);
    }
    Map<String, String> respMap = new HashMap<>();
    respMap.put(propName, propValue);
    logger.debug("Get meta info");
    logger.debug("Interpretersetting Id: {}, property Name:{}, property value: {}", settingId, propName, propValue);
    return new JsonResponse<>(Status.OK, respMap).build();
}
Also used : HashMap(java.util.HashMap) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 63 with GET

use of javax.ws.rs.GET in project zookeeper by apache.

the class ZNodeResource method getZNodeListAsOctet.

@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getZNodeListAsOctet(@PathParam("path") String path) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    Stat stat = new Stat();
    byte[] data = zk.getData(path, false, stat);
    if (data == null) {
        return Response.status(Response.Status.NO_CONTENT).build();
    } else {
        return Response.status(Response.Status.OK).entity(data).build();
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZStat(org.apache.zookeeper.server.jersey.jaxb.ZStat) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 64 with GET

use of javax.ws.rs.GET in project Openfire by igniterealtime.

the class UserServiceLegacy method userSerivceRequest.

@GET
@Path("/userservice")
public Response userSerivceRequest() throws IOException {
    // Printwriter for writing out responses to browser
    PrintWriter out = response.getWriter();
    if (!plugin.getAllowedIPs().isEmpty()) {
        // Get client's IP address
        String ipAddress = request.getHeader("x-forwarded-for");
        if (ipAddress == null) {
            ipAddress = request.getHeader("X_FORWARDED_FOR");
            if (ipAddress == null) {
                ipAddress = request.getHeader("X-Forward-For");
                if (ipAddress == null) {
                    ipAddress = request.getRemoteAddr();
                }
            }
        }
        if (!plugin.getAllowedIPs().contains(ipAddress)) {
            Log.warn("User service rejected service to IP address: " + ipAddress);
            replyError("RequestNotAuthorised", response, out);
            return Response.status(200).build();
        }
    }
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String name = request.getParameter("name");
    String email = request.getParameter("email");
    String type = request.getParameter("type");
    String secret = request.getParameter("secret");
    String groupNames = request.getParameter("groups");
    String item_jid = request.getParameter("item_jid");
    String sub = request.getParameter("subscription");
    // Check that our plugin is enabled.
    if (!plugin.isEnabled()) {
        Log.warn("User service plugin is disabled: " + request.getQueryString());
        replyError("UserServiceDisabled", response, out);
        return Response.status(200).build();
    }
    // Check this request is authorised
    if (secret == null || !secret.equals(plugin.getSecret())) {
        Log.warn("An unauthorised user service request was received: " + request.getQueryString());
        replyError("RequestNotAuthorised", response, out);
        return Response.status(200).build();
    }
    // Some checking is required on the username
    if (username == null && !"grouplist".equals(type)) {
        replyError("IllegalArgumentException", response, out);
        return Response.status(200).build();
    }
    if ((type.equals("add_roster") || type.equals("update_roster") || type.equals("delete_roster")) && (item_jid == null || !(sub == null || sub.equals("-1") || sub.equals("0") || sub.equals("1") || sub.equals("2") || sub.equals("3")))) {
        replyError("IllegalArgumentException", response, out);
        return Response.status(200).build();
    }
    // Check the request type and process accordingly
    try {
        if ("grouplist".equals(type)) {
            String message = "";
            for (String groupname : userServiceController.getAllGroups()) {
                message += "<groupname>" + groupname + "</groupname>";
            }
            replyMessage(message, response, out);
        } else {
            username = username.trim().toLowerCase();
            username = JID.escapeNode(username);
            username = Stringprep.nodeprep(username);
            if ("add".equals(type)) {
                userServiceController.createUser(username, password, name, email, groupNames);
                replyMessage("ok", response, out);
            } else if ("delete".equals(type)) {
                userServiceController.deleteUser(username);
                replyMessage("ok", response, out);
            } else if ("enable".equals(type)) {
                userServiceController.enableUser(username);
                replyMessage("ok", response, out);
            } else if ("disable".equals(type)) {
                userServiceController.disableUser(username);
                replyMessage("ok", response, out);
            } else if ("update".equals(type)) {
                userServiceController.updateUser(username, password, name, email, groupNames);
                replyMessage("ok", response, out);
            } else if ("add_roster".equals(type)) {
                userServiceController.addRosterItem(username, item_jid, name, sub, groupNames);
                replyMessage("ok", response, out);
            } else if ("update_roster".equals(type)) {
                userServiceController.updateRosterItem(username, item_jid, name, sub, groupNames);
                replyMessage("ok", response, out);
            } else if ("delete_roster".equals(type)) {
                userServiceController.deleteRosterItem(username, item_jid);
                replyMessage("ok", response, out);
            } else if ("usergrouplist".equals(type)) {
                String message = "";
                for (String groupname : userServiceController.getUserGroups(username)) {
                    message += "<groupname>" + groupname + "</groupname>";
                }
                replyMessage(message, response, out);
            } else {
                Log.warn("The userService servlet received an invalid request of type: " + type);
            // TODO Do something
            }
        }
    } catch (UserAlreadyExistsException e) {
        replyError("UserAlreadyExistsException", response, out);
    } catch (UserNotFoundException e) {
        replyError("UserNotFoundException", response, out);
    } catch (IllegalArgumentException e) {
        replyError("IllegalArgumentException", response, out);
    } catch (SharedGroupException e) {
        replyError("SharedGroupException", response, out);
    } catch (Exception e) {
        Log.error("Error: ", e);
        replyError(e.toString(), response, out);
    }
    return Response.status(200).build();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) PrintWriter(java.io.PrintWriter) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 65 with GET

use of javax.ws.rs.GET in project cassandra-mesos-deprecated by mesosphere.

the class HealthCheckController method cluster.

@GET
@Path("/cluster")
public Response cluster() {
    final ClusterHealthReport report = healthReportService.generateClusterHealthReport();
    boolean healthy = report.isHealthy();
    LOGGER.info("Cluster Health Report Generated. result: healthy = {}", healthy);
    if (healthy) {
        return Response.ok("{\"healthy\":true}", "application/json").build();
    } else {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ClusterHealthReport(io.mesosphere.mesos.frameworks.cassandra.scheduler.health.ClusterHealthReport) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1140 Path (javax.ws.rs.Path)902 Produces (javax.ws.rs.Produces)734 ApiOperation (io.swagger.annotations.ApiOperation)230 ApiResponses (io.swagger.annotations.ApiResponses)163 IOException (java.io.IOException)139 Response (javax.ws.rs.core.Response)116 WebApplicationException (javax.ws.rs.WebApplicationException)113 Timed (com.codahale.metrics.annotation.Timed)103 ArrayList (java.util.ArrayList)100 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)91 List (java.util.List)83 Map (java.util.Map)80 HashMap (java.util.HashMap)78 URI (java.net.URI)70 TimedResource (org.killbill.commons.metrics.TimedResource)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)57 ApiResponse (io.swagger.annotations.ApiResponse)52 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)39 Consumes (javax.ws.rs.Consumes)36