Search in sources :

Example 86 with Consumes

use of javax.ws.rs.Consumes in project OpenAM by OpenRock.

the class ConsumerResource method getRegistration.

/**
     * GET method for retrieving a specific Service Consumer instance
     * and obtaining corresponding metadata (consumer name, URI, secret).
     *
     * @param consID The comsumer ID 
     * @param sigmethod {@link String} to choose the signature algorithm
     * of interest (e.g. <PRE>?signature_method=RSA-SHA1</PRE> will return
     * the RSA public key of the service consumer).
     *
     * @return an HTTP response with URL encoded value of the service metadata.
     */
@GET
@Consumes(MediaType.TEXT_PLAIN)
public Response getRegistration(@PathParam(C_ID) String consID, @QueryParam(C_SIGNATURE_METHOD) String sigmethod) {
    OAuthResourceManager oauthResMgr = OAuthResourceManager.getInstance();
    try {
        String name = null;
        String icon = null;
        String ckey = context.getAbsolutePath().toString();
        Map<String, String> searchMap = new HashMap<String, String>();
        searchMap.put(CONSUMER_KEY, ckey);
        List<Consumer> consumers = oauthResMgr.searchConsumers(searchMap);
        if ((consumers == null) || consumers.isEmpty()) {
            throw new WebApplicationException(new Throwable("Consumer key is missing."), BAD_REQUEST);
        }
        Consumer consumer = consumers.get(0);
        String cs = null;
        if (sigmethod != null) {
            if (sigmethod.equalsIgnoreCase(RSA_SHA1.NAME)) {
                cs = URLEncoder.encode(consumer.getConsRsakey());
            } else {
                cs = URLEncoder.encode(consumer.getConsSecret());
            }
        }
        if (consumer.getConsName() != null) {
            name = URLEncoder.encode(consumer.getConsName());
        }
        String resp = C_KEY + "=" + URLEncoder.encode(ckey);
        if (name != null) {
            resp += "&" + C_NAME + "=" + name;
        }
        if (cs != null) {
            resp += "&" + C_SECRET + "=" + cs;
        }
        return Response.ok(resp, MediaType.TEXT_PLAIN).build();
    } catch (OAuthServiceException e) {
        Logger.getLogger(ConsumerResource.class.getName()).log(Level.SEVERE, null, e);
        throw new WebApplicationException(e);
    }
}
Also used : Consumer(com.sun.identity.oauth.service.models.Consumer) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 87 with Consumes

use of javax.ws.rs.Consumes in project opennms by OpenNMS.

the class KscRestService method addKscReport.

@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addKscReport(@Context final UriInfo uriInfo, final KscReport kscReport) {
    writeLock();
    try {
        LOG.debug("addKscReport: Adding KSC Report {}", kscReport);
        Report report = m_kscReportFactory.getReportByIndex(kscReport.getId());
        if (report != null) {
            throw getException(Status.CONFLICT, "Invalid request: Existing KSC report found with ID: {}.", Integer.toString(kscReport.getId()));
        }
        report = new Report();
        report.setId(kscReport.getId());
        report.setTitle(kscReport.getLabel());
        if (kscReport.getShowGraphtypeButton() != null) {
            report.setShowGraphtypeButton(kscReport.getShowGraphtypeButton());
        }
        if (kscReport.getShowTimespanButton() != null) {
            report.setShowTimespanButton(kscReport.getShowTimespanButton());
        }
        if (kscReport.getGraphsPerLine() != null) {
            report.setGraphsPerLine(kscReport.getGraphsPerLine());
        }
        if (kscReport.hasGraphs()) {
            for (KscGraph kscGraph : kscReport.getGraphs()) {
                final Graph graph = kscGraph.buildGraph();
                report.addGraph(graph);
            }
        }
        m_kscReportFactory.addReport(report);
        try {
            m_kscReportFactory.saveCurrent();
        } catch (final Exception e) {
            throw getException(Status.BAD_REQUEST, e.getMessage());
        }
        return Response.created(getRedirectUri(uriInfo, kscReport.getId())).build();
    } finally {
        writeUnlock();
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) ParseException(java.text.ParseException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 88 with Consumes

use of javax.ws.rs.Consumes in project opennms by OpenNMS.

the class MonitoringLocationsRestService method updateMonitoringLocation.

@PUT
@Path("{monitoringLocation}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateMonitoringLocation(@PathParam("monitoringLocation") String monitoringLocation, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocation);
        LOG.debug("updateMonitoringLocation: updating monitoring location {}", monitoringLocation);
        if (params.isEmpty())
            return Response.notModified().build();
        boolean modified = false;
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(def);
        wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                Object value = null;
                String stringValue = params.getFirst(key);
                value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateMonitoringLocation: monitoring location {} updated", monitoringLocation);
            m_monitoringLocationDao.save(def);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) StringIntervalPropertyEditor(org.opennms.netmgt.provision.persist.StringIntervalPropertyEditor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with Consumes

use of javax.ws.rs.Consumes in project opennms by OpenNMS.

the class NodeRestService method updateCategoryForNode.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response updateCategoryForNode(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("categoryName") final String categoryName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory category = getCategory(node, categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
        }
        LOG.debug("updateCategory: updating category {}", category);
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
        boolean updated = false;
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                updated = true;
            }
        }
        if (updated) {
            LOG.debug("updateCategory: category {} updated", category);
            m_categoryDao.saveOrUpdate(category);
        } else {
            LOG.debug("updateCategory: no fields updated in category {}", category);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 90 with Consumes

use of javax.ws.rs.Consumes in project opennms by OpenNMS.

the class AbstractDaoRestService method updateProperties.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{id}")
public Response updateProperties(@Context final UriInfo uriInfo, @PathParam("id") final K id, final MultivaluedMapImpl params) {
    writeLock();
    try {
        final T object = getDao().get(id);
        if (object == null) {
            return Response.status(Status.NOT_FOUND).build();
        }
        LOG.debug("update: updating object {}", object);
        RestUtils.setBeanProperties(object, params);
        LOG.debug("update: object {} updated", object);
        getDao().saveOrUpdate(object);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)1610 Path (javax.ws.rs.Path)1243 Produces (javax.ws.rs.Produces)1233 POST (javax.ws.rs.POST)917 ApiOperation (io.swagger.annotations.ApiOperation)508 ApiResponses (io.swagger.annotations.ApiResponses)445 PUT (javax.ws.rs.PUT)439 GET (javax.ws.rs.GET)224 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)215 URI (java.net.URI)207 IOException (java.io.IOException)160 ArrayList (java.util.ArrayList)142 WebApplicationException (javax.ws.rs.WebApplicationException)142 Response (javax.ws.rs.core.Response)140 Authorizable (org.apache.nifi.authorization.resource.Authorizable)100 DELETE (javax.ws.rs.DELETE)87 TimedResource (org.killbill.commons.metrics.TimedResource)84 CallContext (org.killbill.billing.util.callcontext.CallContext)83 Timed (com.codahale.metrics.annotation.Timed)78 HashMap (java.util.HashMap)78