List of usage examples for org.springframework.http MediaType APPLICATION_JSON_VALUE
String APPLICATION_JSON_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_JSON_VALUE.
Click Source Link
From source file:com.tess4j.rest.Tess4jV1.java
@RequestMapping(value = "ocr/v1/upload", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public Status doOcr(@RequestBody Image image) throws Exception { try {/*from w ww.j av a 2 s . c om*/ //FileUtils.writeByteArrayToFile(tmpFile, Base64.decodeBase64(image.getImage())); ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(image.getImage())); Tesseract tesseract = Tesseract.getInstance(); // JNA Interface Mapping String imageText = tesseract.doOCR(ImageIO.read(bis)); image.setText(imageText); repository.save(image); LOGGER.debug("OCR Result = " + imageText); } catch (Exception e) { LOGGER.error("TessearctException while converting/uploading image: ", e); throw new TesseractException(); } return new Status("success"); }
From source file:net.bluewizardhat.tfa.web.controller.UserController.java
@RequestMapping(value = "/currentUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map<String, String> currentUser(HttpSession session) { SessionData sessionData = SessionData.from(session); User user = sessionData.getUser();// www . j a v a2s .c o m if (user != null) { return authenticationSuccess(user); } return failure("not.logged.in").build(); }
From source file:com.redhat.coolstore.api_gateway.ApiGatewayRoute.java
@Override public void configure() throws Exception { JacksonDataFormat productFormatter = new ListJacksonDataFormat(); productFormatter.setUnmarshalType(Product.class); restConfiguration().component("servlet").bindingMode(RestBindingMode.auto).apiContextPath("/api-docs") .contextPath("/api").apiProperty("host", "") .apiProperty("api.title", "CoolStore Microservice API Gateway").apiProperty("api.version", "1.0.0") .apiProperty("api.description", "The API of the gateway which fronts the various backend microservices in the CoolStore") .apiProperty("api.contact.name", "Red Hat Developers") .apiProperty("api.contact.email", "developers@redhat.com") .apiProperty("api.contact.url", "https://developers.redhat.com"); rest("/products/").description("Product Catalog Service").produces(MediaType.APPLICATION_JSON_VALUE) // Handle CORS Pre-flight requests .options("/").route().id("productsOptions").end().endRest() .get("/").description("Get product catalog").outType(Product.class).route().id("productRoute") .setBody(simple("null")).removeHeaders("CamelHttp*") .setHeader(Exchange.HTTP_METHOD, HttpMethods.GET) .setHeader(Exchange.HTTP_URI, simple("http://catalog-service:8080/api/products")).hystrix() .id("Product Service").to("http4://DUMMY").onFallback().to("direct:productFallback").end().choice() .when(body().isNull()).to("direct:productFallback").end().unmarshal(productFormatter).split(body()) .parallelProcessing().enrich("direct:inventory", new InventoryEnricher()).end().endRest(); from("direct:productFallback").id("ProductFallbackRoute").transform() .constant(Collections .singletonList(new Product("0", "Unavailable Product", "Unavailable Product", 0, null))) .marshal().json(JsonLibrary.Jackson, List.class); from("direct:inventory").id("inventoryRoute").setHeader("itemId", simple("${body.itemId}")) .setBody(simple("null")).removeHeaders("CamelHttp*") .setHeader(Exchange.HTTP_METHOD, HttpMethods.GET) .setHeader(Exchange.HTTP_URI, simple("http://inventory-service:8080/api/availability/${header.itemId}")) .hystrix().id("Inventory Service").to("http4://DUMMY2").onFallback().to("direct:inventoryFallback") .end().choice().when(body().isNull()).to("direct:inventoryFallback").end() .setHeader("CamelJacksonUnmarshalType", simple(Inventory.class.getName())).unmarshal() .json(JsonLibrary.Jackson, Inventory.class); from("direct:inventoryFallback").id("inventoryFallbackRoute").transform() .constant(new Inventory("0", 0, "Local Store", "http://redhat.com")).marshal() .json(JsonLibrary.Jackson, Inventory.class); rest("/cart/").description("Personal Shopping Cart Service").produces(MediaType.APPLICATION_JSON_VALUE) // Handle CORS Preflight requests .options("/{cartId}").route().id("getCartOptionsRoute").end().endRest() .options("/checkout/{cartId}").route().id("checkoutCartOptionsRoute").end().endRest() .options("/{cartId}/{tmpId}").route().id("cartSetOptionsRoute").end().endRest() .options("/{cartId}/{itemId}/{quantity}").route().id("cartAddDeleteOptionsRoute").end().endRest() .post("/checkout/{cartId}").description("Finalize shopping cart and process payment").param() .name("cartId").type(RestParamType.path).description("The ID of the cart to process") .dataType("string").endParam().outType(ShoppingCart.class).route().id("checkoutRoute").hystrix() .id("Cart Service (Checkout Cart)").removeHeaders("CamelHttp*").setBody(simple("null")) .setHeader(Exchange.HTTP_METHOD, HttpMethods.POST) .setHeader(Exchange.HTTP_URI, simple("http://cart-service:8080/api/cart/checkout/${header.cartId}")) .to("http4://DUMMY").onFallback() // TODO: improve fallback .transform().constant(null).end() .setHeader("CamelJacksonUnmarshalType", simple(ShoppingCart.class.getName())).unmarshal() .json(JsonLibrary.Jackson, ShoppingCart.class).endRest() .get("/{cartId}").description("Get the current user's shopping cart content").param().name("cartId") .type(RestParamType.path).description("The ID of the cart to process").dataType("string").endParam() .outType(ShoppingCart.class).route().id("getCartRoute").hystrix().id("Cart Service (Get Cart)") .removeHeaders("CamelHttp*").setBody(simple("null")) .setHeader(Exchange.HTTP_METHOD, HttpMethods.GET) .setHeader(Exchange.HTTP_URI, simple("http://cart-service:8080/api/cart/${header.cartId}")) .to("http4://DUMMY").onFallback() // TODO: improve fallback .transform().constant(null).end() .setHeader("CamelJacksonUnmarshalType", simple(ShoppingCart.class.getName())).unmarshal() .json(JsonLibrary.Jackson, ShoppingCart.class).endRest() .delete("/{cartId}/{itemId}/{quantity}") .description("Delete items from current user's shopping cart").param().name("cartId") .type(RestParamType.path).description("The ID of the cart to process").dataType("string").endParam() .param().name("itemId").type(RestParamType.path).description("The ID of the item to delete") .dataType("string").endParam().param().name("quantity").type(RestParamType.path) .description("The number of items to delete").dataType("integer").endParam() .outType(ShoppingCart.class).route().id("deleteFromCartRoute").hystrix() .id("Cart Service (Delete Cart)").removeHeaders("CamelHttp*").setBody(simple("null")) .setHeader(Exchange.HTTP_METHOD, HttpMethods.DELETE) .setHeader(Exchange.HTTP_URI, simple( "http://cart-service:8080/api/cart/${header.cartId}/${header.itemId}/${header.quantity}")) .to("http4://DUMMY").onFallback() // TODO: improve fallback .transform().constant(null).end() .setHeader("CamelJacksonUnmarshalType", simple(ShoppingCart.class.getName())).unmarshal() .json(JsonLibrary.Jackson, ShoppingCart.class).endRest() .post("/{cartId}/{itemId}/{quantity}").description("Add items from current user's shopping cart") .param().name("cartId").type(RestParamType.path).description("The ID of the cart to process") .dataType("string").endParam().param().name("itemId").type(RestParamType.path) .description("The ID of the item to add").dataType("string").endParam().param().name("quantity") .type(RestParamType.path).description("The number of items to add").dataType("integer").endParam() .outType(ShoppingCart.class).route().id("addToCartRoute").hystrix().id("Cart Service (Add To Cart)") .removeHeaders("CamelHttp*").setBody(simple("null")) .setHeader(Exchange.HTTP_METHOD, HttpMethods.POST) .setHeader(Exchange.HTTP_URI, simple( "http://cart-service:8080/api/cart/${header.cartId}/${header.itemId}/${header.quantity}")) .to("http4://DUMMY").onFallback() // TODO: improve fallback .transform().constant(null).end() .setHeader("CamelJacksonUnmarshalType", simple(ShoppingCart.class.getName())).unmarshal() .json(JsonLibrary.Jackson, ShoppingCart.class).endRest() .post("/{cartId}/{tmpId}").description("Transfer temp shopping items to user's cart").param() .name("cartId").type(RestParamType.path).description("The ID of the cart to process") .dataType("string").endParam().param().name("tmpId").type(RestParamType.path) .description("The ID of the temp cart to transfer").dataType("string").endParam() .outType(ShoppingCart.class).route().id("setCartRoute").hystrix().id("Cart Service (Set Cart)") .removeHeaders("CamelHttp*").setBody(simple("null")) .setHeader(Exchange.HTTP_METHOD, HttpMethods.POST) .setHeader(Exchange.HTTP_URI, simple("http://cart-service:8080/api/cart/${header.cartId}/${header.tmpId}")) .to("http4://DUMMY").onFallback() // TODO: improve fallback .transform().constant(null).end() .setHeader("CamelJacksonUnmarshalType", simple(ShoppingCart.class.getName())).unmarshal() .json(JsonLibrary.Jackson, ShoppingCart.class).endRest(); }
From source file:be.ehb.restservermetdatabase.webservice.FriendshipController.java
@RequestMapping(value = "/destroy", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public int destroy(@RequestParam(value = "from_id", defaultValue = "0") int from_id, @RequestParam(value = "from_email", defaultValue = "") String from_mail, @RequestParam(value = "to_id", defaultValue = "0") int to_id, @RequestParam(value = "to_email", defaultValue = "") String to_mail) { if (from_id == 0) { if (from_mail.equals("")) { return 0; } else {/* w w w .j a va2 s.com*/ from_id = UserDao.getUserByEmail(from_mail).getId(); } } if (to_id == 0) { if (to_mail.equals("")) { return 0; } else { to_id = UserDao.getUserByEmail(to_mail).getId(); } } return FriendshipDao.deleteFriendhsip(from_id, to_id); }
From source file:com.logsniffer.web.controller.source.SourcesResourceController.java
@RequestMapping(value = "/sources/{logSource}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody//from ww w.j a v a 2 s . c o m LogSource<?> getSource(@PathVariable("logSource") final long logSourceId) throws ResourceNotFoundException { return getActiveSource(logSourceId); }
From source file:com.orange.ngsi.server.NgsiRestBaseController.java
@RequestMapping(method = RequestMethod.PUT, value = { "/contextEntities/{entityID}", "/contextEntities/{entityID}/attributes" }, consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) final public ResponseEntity<UpdateContextElementResponse> updateContextEntity(@PathVariable String entityID, @RequestBody UpdateContextElement updateContextElement, HttpServletRequest httpServletRequest) throws Exception { ngsiValidation.checkUpdateContextElement(updateContextElement); registerIntoDispatcher(httpServletRequest); return new ResponseEntity<>(updateContextElement(entityID, updateContextElement), HttpStatus.OK); }
From source file:org.mitre.oauth2.web.TokenAPI.java
@RequestMapping(value = "/access", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public String getAllAccessTokens(ModelMap m, Principal p) { Set<OAuth2AccessTokenEntity> allTokens = tokenService.getAllAccessTokensForUser(p.getName()); m.put(JsonEntityView.ENTITY, allTokens); return TokenApiView.VIEWNAME; }
From source file:curly.artifact.ArtifactResourceController.java
@RequestMapping(value = "/{id}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) public DeferredResult<HttpEntity<Artifact>> artifactResource(@PathVariable("id") String id) { log.trace("Querying single resource based on id {}", id); return defer(artifactService.findOne(id) .map(o -> o.<ResourceNotFoundException>orElseThrow(ResourceNotFoundException::new)) .map(ResponseEntity::ok));//from www . ja v a 2 s . co m }
From source file:org.openbaton.autoscaling.api.RestEventInterface.java
/** * Deactivates autoscaling for the passed NSR * * @param msg : NSR in payload to add for autoscaling */// w w w. j a v a2s .co m @RequestMapping(value = "RELEASE_RESOURCES_FINISH", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public void deactivate(@RequestBody String msg) throws NotFoundException { log.debug("========================"); log.debug("msg=" + msg); JsonParser jsonParser = new JsonParser(); JsonObject json = jsonParser.parse(msg).getAsJsonObject(); Gson mapper = new GsonBuilder().create(); Action action = mapper.fromJson(json.get("action"), Action.class); log.debug("ACTION=" + action); NetworkServiceRecord nsr = mapper.fromJson(json.get("payload"), NetworkServiceRecord.class); log.debug("NSR=" + nsr); elasticityManagement.deactivate(nsr.getId()); }
From source file:com.jci.job.apis.ApiClientController.java
/** * Get Supplier Details scheduler.// ww w.j a va 2 s.co m * * @param plant the plant * @param erp the erp * @param region the region * @return the supp details */ @RequestMapping(value = "/getSuppDetails", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = { MediaType.APPLICATION_JSON_VALUE }) public String getSuppDetails(@RequestParam("plant") String plant, @RequestParam("erp") String erp, @RequestParam("region") String region) { String response = service.getSuppDetails(plant, erp, region); return response; }