Search in sources :

Example 51 with Path

use of javax.ws.rs.Path 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 52 with Path

use of javax.ws.rs.Path 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 53 with Path

use of javax.ws.rs.Path in project pinot by linkedin.

the class TableSizeResource method getTableSize.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/tables/{tableName}/size")
@ApiOperation(value = "Show table storage size", notes = "Lists size of all the segments of the table")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 404, message = "Table not found") })
public TableSizeInfo getTableSize(@ApiParam(value = "Table Name with type", required = true) @PathParam("tableName") String tableName, @ApiParam(value = "Provide detailed information", required = false) @DefaultValue("true") @QueryParam("detailed") boolean detailed) throws WebApplicationException {
    InstanceDataManager dataManager = (InstanceDataManager) serverInstance.getInstanceDataManager();
    if (dataManager == null) {
        throw new WebApplicationException("Invalid server initialization", Response.Status.INTERNAL_SERVER_ERROR);
    }
    TableDataManager tableDataManager = dataManager.getTableDataManager(tableName);
    if (tableDataManager == null) {
        throw new WebApplicationException("Table: " + tableName + " is not found", Response.Status.NOT_FOUND);
    }
    TableSizeInfo tableSizeInfo = new TableSizeInfo();
    tableSizeInfo.tableName = tableDataManager.getTableName();
    tableSizeInfo.diskSizeInBytes = 0L;
    ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments();
    try {
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            IndexSegment segment = segmentDataManager.getSegment();
            long segmentSizeBytes = segment.getDiskSizeBytes();
            if (detailed) {
                SegmentSizeInfo segmentSizeInfo = new SegmentSizeInfo(segment.getSegmentName(), segmentSizeBytes);
                tableSizeInfo.segments.add(segmentSizeInfo);
            }
            tableSizeInfo.diskSizeInBytes += segmentSizeBytes;
        }
    } finally {
        // executes fast so duration of holding segments is not a concern
        for (SegmentDataManager segmentDataManager : segmentDataManagers) {
            tableDataManager.releaseSegment(segmentDataManager);
        }
    }
    //invalid to use the segmentDataManagers below
    return tableSizeInfo;
}
Also used : SegmentDataManager(com.linkedin.pinot.core.data.manager.offline.SegmentDataManager) WebApplicationException(javax.ws.rs.WebApplicationException) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) TableDataManager(com.linkedin.pinot.core.data.manager.offline.TableDataManager) InstanceDataManager(com.linkedin.pinot.core.data.manager.offline.InstanceDataManager) SegmentSizeInfo(com.linkedin.pinot.common.restlet.resources.SegmentSizeInfo) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 54 with Path

use of javax.ws.rs.Path in project pinot by linkedin.

the class TablesResource method listTableSegments.

@GET
@Path("/tables/{tableName}/segments")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List table segments", notes = "List segments of table hosted on this server")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = TableSegments.class), @ApiResponse(code = 500, message = "Server initialization error", response = ErrorInfo.class) })
public TableSegments listTableSegments(@ApiParam(value = "Table name including type", required = true, example = "myTable_OFFLINE") @PathParam("tableName") String tableName) {
    TableDataManager tableDataManager = checkGetTableDataManager(tableName);
    ImmutableList<SegmentDataManager> segmentDataManagers = tableDataManager.acquireAllSegments();
    List<String> segments = new ArrayList<>(segmentDataManagers.size());
    for (SegmentDataManager segmentDataManager : segmentDataManagers) {
        segments.add(segmentDataManager.getSegmentName());
        tableDataManager.releaseSegment(segmentDataManager);
    }
    return new TableSegments(segments);
}
Also used : TableSegments(com.linkedin.pinot.common.restlet.resources.TableSegments) SegmentDataManager(com.linkedin.pinot.core.data.manager.offline.SegmentDataManager) TableDataManager(com.linkedin.pinot.core.data.manager.offline.TableDataManager) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 55 with Path

use of javax.ws.rs.Path in project killbill by killbill.

the class AccountResource method setEmailNotificationsForAccount.

@TimedResource
@PUT
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAIL_NOTIFICATIONS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Set account email notification")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response setEmailNotificationsForAccount(final InvoiceEmailJson json, @PathParam("accountId") final String accountIdString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
    verifyNonNullOrEmpty(json, "InvoiceEmailJson body should be specified");
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID accountId = UUID.fromString(accountIdString);
    final Account account = accountUserApi.getAccountById(accountId, callContext);
    final MutableAccountData mutableAccountData = account.toMutableAccountData();
    mutableAccountData.setIsNotifiedForInvoices(json.isNotifiedForInvoices());
    accountUserApi.updateAccount(accountId, mutableAccountData, callContext);
    return Response.status(Status.OK).build();
}
Also used : Account(org.killbill.billing.account.api.Account) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Path (javax.ws.rs.Path)6273 Produces (javax.ws.rs.Produces)3678 GET (javax.ws.rs.GET)3072 POST (javax.ws.rs.POST)1783 Consumes (javax.ws.rs.Consumes)1440 ApiOperation (io.swagger.annotations.ApiOperation)1213 ApiResponses (io.swagger.annotations.ApiResponses)997 PUT (javax.ws.rs.PUT)850 IOException (java.io.IOException)677 DELETE (javax.ws.rs.DELETE)662 ArrayList (java.util.ArrayList)591 WebApplicationException (javax.ws.rs.WebApplicationException)556 Response (javax.ws.rs.core.Response)540 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)490 HashMap (java.util.HashMap)394 Timed (com.codahale.metrics.annotation.Timed)383 URI (java.net.URI)374 List (java.util.List)287 Map (java.util.Map)259 NotFoundException (javax.ws.rs.NotFoundException)258