code: public static HttpResponse put(String urlStr, String body, Map<String, String> headers) throws IOException {
          URL url = new URL(urlStr);
          HttpURLConnection urlConnection = (HttpURLConnection) url
                  .openConnection();
          urlConnection.addRequestProperty("Accept", "application/json");
  
          urlConnection.setRequestMethod("PUT");
          if(headers != null && headers.size() > 0){
              for(Entry<String, String> entry : headers.entrySet()){
                  urlConnection.addRequestProperty(entry.getKey(), entry.getValue());
              }
          }
  
          if (body != null && body.length() > 0)
              urlConnection.addRequestProperty("Content-Length",
                      Integer.toString(body.length()));
          else
              urlConnection.addRequestProperty("Content-Length", "0");
          urlConnection.setDoOutput(true);
  
          OutputStream out = urlConnection.getOutputStream();
          if (body != null && body.length() > 0)
              ByteStreams.copy(
                      new ByteArrayInputStream(body.getBytes()), out);
  
          BufferedReader in = null;
          try {
              int errorCode = urlConnection.getResponseCode();
              if ((errorCode <= 202) && (errorCode >= 200)) {
                  in = new BufferedReader(new InputStreamReader(
                          urlConnection.getInputStream()));
              } else {
                  InputStream error = urlConnection.getErrorStream();
                  if (error != null) {
                      in = new BufferedReader(new InputStreamReader(error));
                  }
              }
  
              String json = null;
              if (in != null) {
                  json = CharStreams.toString(in);
              }
              return new HttpResponse(errorCode, json);
          } finally {
              if(in != null){
                  in.close();
              }
          }
  
      }
docs: Invoke REST Service using PUT method.
  
  It accepts the JSON message.
  
  @param urlStr
  the REST Service URL String.
  @param body
  the Http Body String.
  @param headers
  the Http header Map.
  @return
  the HttpResponse.
  @throws IOException