001package com.box.sdk; 002 003import java.net.URL; 004 005/** 006 * Used to make HTTP requests containing JSON to the Box API. 007 * 008 * <p>This request type extends BoxAPIRequest to provide additional functionality for handling JSON strings. It 009 * automatically sets the appropriate "Content-Type" HTTP headers and allows the JSON in the request to be logged.</p> 010 */ 011public class BoxJSONRequest extends BoxAPIRequest { 012 private String json; 013 014 /** 015 * Constructs an authenticated BoxJSONRequest using a provided BoxAPIConnection. 016 * @param api an API connection for authenticating the request. 017 * @param url the URL of the request. 018 * @param method the HTTP method of the request. 019 */ 020 public BoxJSONRequest(BoxAPIConnection api, URL url, String method) { 021 super(api, url, method); 022 023 this.addHeader("Content-Type", "application/json"); 024 } 025 026 /** 027 * Sets the body of this request to a given JSON string. 028 * @param body the JSON string to use as the body. 029 */ 030 @Override 031 public void setBody(String body) { 032 super.setBody(body); 033 this.json = body; 034 } 035 036 @Override 037 protected String bodyToString() { 038 return this.json; 039 } 040}