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);
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations