Search in sources :

Example 56 with POST

use of javax.ws.rs.POST in project OpenAttestation by OpenAttestation.

the class RevokeTagCertificate method revokeCert.

@POST
public //@RequiresPermissions("tag_certificates:delete")         
void revokeCert(@QueryParam("certId") String certId) {
    log.debug("RPC: RevokeTagCertificate - Got request to revocation of certificate: {}", certId);
    setCertificateId(UUID.valueOf(certId));
    try (CertificateDAO dao = TagJdbi.certificateDao()) {
        CertificateLocator locator = new CertificateLocator();
        locator.id = certificateId;
        Certificate obj = dao.findById(certificateId);
        if (obj != null) {
            // tries jvm properties, environment variables, then mtwilson.properties;  you can set location of mtwilson.properties with -Dmtwilson.home=/path/to/dir
            org.apache.commons.configuration.Configuration conf = ConfigurationUtil.getConfiguration();
            ApiClient mtwilson = new ApiClient(conf);
            log.debug("RPC: RevokeTagCertificate - Sha1 of the certificate about to be revoked is {}.", obj.getSha1());
            dao.updateRevoked(certificateId, true);
            AssetTagCertRevokeRequest request = new AssetTagCertRevokeRequest();
            request.setSha1OfAssetCert(obj.getSha1().toByteArray());
            mtwilson.revokeAssetTagCertificate(request);
            //Global.mtwilson().revokeAssetTagCertificate(request);
            log.info("RPC: RevokeTagCertificate - Certificate with id {} has been revoked successfully.");
        } else {
            log.error("RPC: RevokeTagCertificate - Certificate with id {} does not exist.", certificateId);
            throw new RepositoryInvalidInputException(locator);
        }
    } catch (RepositoryException re) {
        throw re;
    } catch (Exception ex) {
        log.error("RPC: RevokeTagCertificate - Error during certificate revocation.", ex);
        throw new RepositoryException(ex);
    }
}
Also used : CertificateLocator(com.intel.mtwilson.datatypes.CertificateLocator) AssetTagCertRevokeRequest(com.intel.mtwilson.datatypes.AssetTagCertRevokeRequest) CertificateDAO(com.intel.mtwilson.tag.dao.jdbi.CertificateDAO) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) ApiClient(com.intel.mtwilson.ApiClient) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryInvalidInputException(com.intel.mtwilson.tag.repository.RepositoryInvalidInputException) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) WebApplicationException(javax.ws.rs.WebApplicationException) Certificate(com.intel.mtwilson.datatypes.Certificate) POST(javax.ws.rs.POST)

Example 57 with POST

use of javax.ws.rs.POST in project OpenAttestation by OpenAttestation.

the class AssetTagCert method importAssetTagCertificate.

/**
     * This REST API would be called by the tag provisioning service whenever a new asset tag certificate is generated for a host.
     * Initially we would stored this asset tag certificate in the DB without being mapped to any host. After the host is registered, then
     * the asset tag certificate would be mapped to it.
     * @param atagObj
     * @return 
     */
//@RolesAllowed({"AssetTagManagement"})
//    @RequiresPermissions({"tag_certificates:create","hosts:search"})
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String importAssetTagCertificate(AssetTagCertCreateRequest atagObj) {
    AssetTagCertBO object = new AssetTagCertBO();
    boolean result = object.importAssetTagCertificate(atagObj, null);
    return Boolean.toString(result);
}
Also used : AssetTagCertBO(com.intel.mtwilson.as.business.AssetTagCertBO) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 58 with POST

use of javax.ws.rs.POST in project newts by OpenNMS.

the class MeasurementsResource method getMeasurements.

@POST
@Path("/{resource}")
@Timed
public Collection<Collection<MeasurementDTO>> getMeasurements(ResultDescriptorDTO descriptorDTO, @PathParam("resource") Resource resource, @QueryParam("start") Optional<TimestampParam> start, @QueryParam("end") Optional<TimestampParam> end, @QueryParam("resolution") Optional<DurationParam> resolution, @QueryParam("context") Optional<String> contextId) {
    Optional<Timestamp> lower = Transform.toTimestamp(start);
    Optional<Timestamp> upper = Transform.toTimestamp(end);
    Optional<Duration> step = Transform.toDuration(resolution);
    Context context = contextId.isPresent() ? new Context(contextId.get()) : Context.DEFAULT_CONTEXT;
    LOG.debug("Retrieving measurements for resource {}, from {} to {} w/ resolution {} and w/ report {}", resource, lower, upper, step, descriptorDTO);
    ResultDescriptor rDescriptor = Transform.resultDescriptor(descriptorDTO);
    return Transform.measurementDTOs(m_repository.select(context, resource, lower, upper, rDescriptor, step));
}
Also used : Context(org.opennms.newts.api.Context) Duration(org.opennms.newts.api.Duration) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Timestamp(org.opennms.newts.api.Timestamp) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 59 with POST

use of javax.ws.rs.POST in project airpal by airbnb.

the class SessionResource method doLogin.

@POST
@Path("/login")
public void doLogin(@Context HttpServletRequest request, @Context HttpServletResponse response, @FormParam("username") String username, @FormParam("password") String password) throws IOException {
    Subject currentUser = SecurityUtils.getSubject();
    if (!currentUser.isAuthenticated()) {
        AuthenticationToken token = new UsernamePasswordToken(username, password);
        currentUser.login(token);
    }
    WebUtils.redirectToSavedRequest(request, response, "/app");
}
Also used : AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 60 with POST

use of javax.ws.rs.POST in project javaee7-samples by javaee-samples.

the class MyResource method postOctetStream.

@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
public Response postOctetStream(InputStream content) {
    try (Reader reader = new InputStreamReader(content)) {
        int totalsize = 0;
        int count = 0;
        final char[] buffer = new char[256];
        while ((count = reader.read(buffer)) != -1) {
            totalsize += count;
        }
        return Response.ok(totalsize).build();
    } catch (IOException e) {
        e.printStackTrace();
        return Response.serverError().build();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileReader(java.io.FileReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

POST (javax.ws.rs.POST)513 Path (javax.ws.rs.Path)360 Consumes (javax.ws.rs.Consumes)242 Produces (javax.ws.rs.Produces)222 ApiOperation (io.swagger.annotations.ApiOperation)133 ApiResponses (io.swagger.annotations.ApiResponses)107 IOException (java.io.IOException)74 URI (java.net.URI)63 WebApplicationException (javax.ws.rs.WebApplicationException)62 Timed (com.codahale.metrics.annotation.Timed)55 Response (javax.ws.rs.core.Response)50 TimedResource (org.killbill.commons.metrics.TimedResource)36 CallContext (org.killbill.billing.util.callcontext.CallContext)35 AuditEvent (org.graylog2.audit.jersey.AuditEvent)33 HashMap (java.util.HashMap)32 BadRequestException (co.cask.cdap.common.BadRequestException)24 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Account (org.killbill.billing.account.api.Account)22 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)20