示例#1
0
  public static void main(String argv[]) {
    String queuecf = null;
    String requestq = null;
    if (argv.length == 2) {
      queuecf = argv[0];
      requestq = argv[1];
    } else {
      System.out.println("Invalid arguments. Should be: ");
      System.out.println("java QLender factory request_queue");
      System.exit(0);
    }

    QLender lender = new QLender(queuecf, requestq);

    try {
      // Run until enter is pressed
      BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("QLender application started");
      System.out.println("Press enter to quit application");
      stdin.readLine();
      lender.exit();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
示例#2
0
  // callRestfulApi - Calls restful API and returns results as a string
  public String callRestfulApi(
      String addr, HttpServletRequest request, HttpServletResponse response) {
    if (localCookie) CookieHandler.setDefault(cm);

    try {
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      URL url = new URL(API_ROOT + addr);
      URLConnection urlConnection = url.openConnection();
      String cookieVal = getBrowserInfiniteCookie(request);
      if (cookieVal != null) {
        urlConnection.addRequestProperty("Cookie", "infinitecookie=" + cookieVal);
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.setRequestProperty("Accept-Charset", "UTF-8");
      }
      IOUtils.copy(urlConnection.getInputStream(), output);
      String newCookie = getConnectionInfiniteCookie(urlConnection);
      if (newCookie != null && response != null) {
        setBrowserInfiniteCookie(response, newCookie, request.getServerPort());
      }
      return output.toString();
    } catch (IOException e) {
      System.out.println(e.getMessage());
      return null;
    }
  } // TESTED
示例#3
0
 private static void enter4quit(QLender lender) {
   try {
     // Run until enter is pressed
     BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
     System.out.println("QLender application started");
     System.out.println("Press enter to quit application");
     stdin.readLine();
     lender.exit();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }