Java Code Examples for javax.ws.rs.core.MediaType.APPLICATION_JSON

The following are Jave code examples for showing how to use APPLICATION_JSON of the javax.ws.rs.core.MediaType class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: holon-examples   File: ProductEndpoint.java   Source Code and License Vote up 8 votes
@GET
@Path("/products/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getProduct(@PathParam("id") Long id) {
	return getProductStore().get(id).map(p -> Response.ok(p).build())
			.orElse(Response.status(Status.NOT_FOUND).build());
}
 
Example 2
Project: athena   File: OpenstackFloatingIpWebResource.java   Source Code and License Vote up 6 votes
/**
 * Update FloatingIP.
 *
 * @param id    FloatingIP identifier
 * @param input JSON data describing FloatingIP
 * @return 200 OK
 */
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateFloatingIp(@PathParam("id") String id, InputStream input) {
    checkNotNull(id);
    checkNotNull(input);

    try {
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input);

        OpenstackFloatingIP osFloatingIp =
                FLOATING_IP_CODEC.decode(floatingIpNode, this);

        OpenstackRoutingService routingService =
                getService(OpenstackRoutingService.class);

        routingService.updateFloatingIP(osFloatingIp);

        log.debug("REST API UPDATE floatingip called {}", id);

        return Response.status(Response.Status.OK).build();
    } catch (Exception e) {
        log.error("updateFloatingIp failed with {}", e.toString());

        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
                .build();
    }
}
 
Example 3
Project: microprofile-jwt-auth   File: ProviderInjectionEndpoint.java   Source Code and License Vote up 5 votes
@GET
@Path("/verifyInjectedCustomInteger")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomInteger(@QueryParam("value") Long value) {
    boolean pass = false;
    String msg;
    // iat
    Object test = customInteger.get();
    System.out.printf("+++ verifyInjectedCustomInteger, JsonNumber.class.CL: %s\n",
        JsonNumber.class.getClassLoader());
    System.out.printf("+++ customInteger.CL: %s\n",
        test.getClass().getClassLoader());
    Class[] ifaces = test.getClass().getInterfaces();
    for(Class iface : ifaces) {
        System.out.printf("%s: %s\n", iface, iface.getClassLoader());
    }
    JsonNumber customValue = JsonNumber.class.cast(test);
    if(customValue == null || customValue.isIntegral() == false) {
        msg = "customInteger value is null or not integral, FAIL";
    }
    else if(customValue.longValueExact() == value) {
        msg = "customInteger PASS";
        pass = true;
    }
    else {
        msg = String.format("customInteger: %d != %d", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
 
Example 4
Project: athena   File: PolicyWebResource.java   Source Code and License Vote up 5 votes
/**
 * Get all segment routing policies.
 * Returns an array of segment routing policies.
 *
 * @return status of OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPolicy() {
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    List<Policy> policies = srService.getPolicies();
    ObjectNode result = new ObjectMapper().createObjectNode();
    result.set("policy", new PolicyCodec().encode(policies, this));

    return ok(result.toString()).build();
}
 
Example 5
Project: rest-basic-tutorial   File: PeopleResource.java   Source Code and License Vote up 5 votes
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/posted")
public Response getPostedPeople(@DefaultValue("1") @QueryParam("maxPeople") int maxPeople) {

    return Response.ok(POSTED_PEOPLE.subList(0, Math.min(maxPeople, POSTED_PEOPLE.size())))
            .build();
}
 
Example 6
Project: ctsms   File: FileResource.java   Source Code and License Vote up 5 votes
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("staff")
public Page<FileOutVO> getStaffFiles(@Context UriInfo uriInfo)
		throws AuthenticationException, AuthorisationException, ServiceException {
	PSFUriPart psf;
	return new Page<FileOutVO>(WebUtil.getServiceLocator().getFileService().getFiles(auth, FileModule.STAFF_DOCUMENT, null, null, null, psf = new PSFUriPart(uriInfo)), psf);
}
 
Example 7
Project: graphiak   File: DashboardResource.java   Source Code and License Vote up 5 votes
@GET
@JSONP
@Path("/find")
@Produces({ MediaType.APPLICATION_JSON, TEXT_JAVASCRIPT })
public Response find() {
    final Map<String, List<String>> response = new HashMap<>();
    response.put("dashboards", Collections.emptyList());
    return Response.ok(response).build();
}
 
Example 8
Project: opencps-v2   File: PaymentConfigManagement.java   Source Code and License Vote up 5 votes
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "Get the PaymentConfig by primekey", response = PaymentConfigInputModel.class)
@ApiResponses(value = {
		@ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns detail of PaymentConfig", response = PaymentConfigInputModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access denied", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Not found", response = ExceptionModel.class),
		@ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal error", response = ExceptionModel.class) })

public Response getPaymentConfigDetail(@Context HttpServletRequest request, @Context HttpHeaders header,
		@Context Company company, @Context Locale locale, @Context User user,
		@Context ServiceContext serviceContext, @PathParam("id") long id);
 
Example 9
Project: elastic-job-cloud   File: CloudJobRestfulApi.java   Source Code and License Vote up 5 votes
/**
 * 查询作业详情.
 *
 * @param jobName 作业名称
 * @return 作业配置对象
 */
@GET
@Path("/jobs/{jobName}")
@Consumes(MediaType.APPLICATION_JSON)
public Response detail(@PathParam("jobName") final String jobName) {
    Optional<CloudJobConfiguration> jobConfig = configService.load(jobName);
    if (!jobConfig.isPresent()) {
        return Response.status(NOT_FOUND).build();
    }
    return Response.ok(jobConfig.get()).build();
}
 
Example 10
Project: FakeTwitterDetection   File: Login.java   Source Code and License Vote up 5 votes
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/login")
public String login() {
    if (sessionBean.isLogged() == true) {
        return "You are already logged in";
    } else {
        String url = loginClass.getAuthorizationURL();//send auth url
        sessionBean.setAuthorizationURL(url);
        return url;
    }
}
 
Example 11
Project: ctsms   File: StaffResource.java   Source Code and License Vote up 5 votes
@GET
@Produces({ MediaType.APPLICATION_JSON })
public Page<StaffOutVO> getStaffList(@Context UriInfo uriInfo)
		throws AuthenticationException, AuthorisationException, ServiceException {
	PSFUriPart psf;
	return new Page<StaffOutVO>(WebUtil.getServiceLocator().getStaffService()
			.getStaffList(auth, null, null, ResourceUtils.LIST_GRAPH_MAX_STAFF_INSTANCES, psf = new PSFUriPart(uriInfo)), psf);
}
 
Example 12
Project: redirector   File: OfflineRedirectorController.java   Source Code and License Vote up 5 votes
@POST
@Path("{serviceName}/getOfflinePendingChanges")
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces({MediaType.APPLICATION_JSON})
public Response uploadCoreBackup(
        @PathParam("serviceName") String serviceName,
        @FormDataParam("file") InputStream zipByteArray,
        @FormDataParam("file") FormDataContentDisposition fileDisposition) throws IOException, SerializerException {
    return Response.ok(offlineModeService.calculateOfflinePendingChanges(serviceName, zipByteArray)).build();
}
 
Example 13
Project: hadoop-oss   File: JerseyResource.java   Source Code and License Vote up 5 votes
@GET
@Path("{" + PATH + ":.*}")
@Produces({MediaType.APPLICATION_JSON})
public Response get(
    @PathParam(PATH) @DefaultValue("UNKNOWN_" + PATH) final String path,
    @QueryParam(OP) @DefaultValue("UNKNOWN_" + OP) final String op
    ) throws IOException {
  LOG.info("get: " + PATH + "=" + path + ", " + OP + "=" + op);

  final Map<String, Object> m = new TreeMap<String, Object>();
  m.put(PATH, path);
  m.put(OP, op);
  final String js = JSON.toString(m);
  return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
}
 
Example 14
Project: jwala   File: GroupServiceRest.java   Source Code and License Vote up 4 votes
@POST
@Consumes(MediaType.APPLICATION_JSON)
Response createGroup(final String aNewGroupName,
                     @BeanParam final AuthenticatedUser aUser);
 
Example 15
Project: elastic-job-cloud   File: CloudAppRestfulApi.java   Source Code and License Vote up 4 votes
/**
 * 更新应用配置.
 *
 * @param appConfig 应用配置
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void update(final CloudAppConfiguration appConfig) {
    appConfigService.update(appConfig);
}
 
Example 16
Project: verify-hub   File: EventSinkHubEventTestResource.java   Source Code and License Vote up 4 votes
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(StubEventSinkUrls.HUB_SUPPORT_EVENT_SINK_TEST_ID_PATH)
public EventSinkHubEvent getHubEvent(@PathParam(StubEventSinkUrls.HUB_SUPPORT_EVENT_SINK_TEST_ID_PARAM) String id) {
    return inMemoryEventSinkHubEventStore.getEventById(id);
}
 
Example 17
Project: pai   File: LauncherModule.java   Source Code and License Vote up 4 votes
@GET
@Path(WebStructure.LAUNCHER_STATUS_PATH)
@Produces({MediaType.APPLICATION_JSON})
public LauncherStatus getLauncherStatus() {
  return statusManager.getLauncherStatus();
}
 
Example 18
Project: redirector   File: PendingChangesController.java   Source Code and License Vote up 4 votes
@GET
@Path("{serviceName}/preview/distribution/")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getDistributionPendingPreview(@VerifyApplicationExists @PathParam("serviceName") final String serviceName){
    return Response.ok(getNextDistributionEntityViewService().getEntity(serviceName)).build();
}
 
Example 19
Project: docker-restful-java   File: AuthenticationController.java   Source Code and License Vote up 4 votes
/**
 * Method handling HTTP POST requests. The returned object will be sent
 * to the client as JSON Object.
 *
 * @return JSON Object containing user information.
 */
@Path("register/")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(User user) {
    LOGGER.info("#POST " + user.toString());
    Response response = null;
    Set<ConstraintViolation<Object>> constraintViolations =
            validator.validate(user);

    if (constraintViolations.size() > 0) {
        response = Error.badRequest(constraintViolations)
                .getResponse();
        LOGGER.warning("#POST " + response.toString());
    } else {
        // Set hashed password
        String hashed = BCrypt.hashpw(user.getPasswordHash(), BCrypt.gensalt());
        user.setPasswordHash(hashed);

        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            session.save(user);
            session.getTransaction().commit();

            URI builder = uriInfo.getAbsolutePathBuilder()
                    //.path(String.valueOf(p.getId()))
                    .build();

            response = Response
                    .created(builder)
                    .entity(user)
                    .build();
            LOGGER.info("#POST " + response.toString());
        } catch (Exception exception) {
            LOGGER.warning("#POST " + exception.getLocalizedMessage());
            response = Error.internalServer(exception)
                    .getResponse();
            session.getTransaction().rollback();
        }
    }

    return response;
}
 
Example 20
Project: drugviser   File: MedicineFacadeREST.java   Source Code and License Vote up 4 votes
@PUT
@Path("{id}")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public void edit(@PathParam("id") Long id, Medicine entity) {
    super.edit(entity);
}