Force Jetty to make 301 redirect

I have Jetty application which is very big. I need to replace all 302 redirects to 301.

Can I force Jetty to always do 301 redirect when doing response.sendRedirect('someURL') ?

Answers


Hacks for jetty 6 and 8:

if (server.getClass().getPackage().getImplementationVersion().startsWith("8")) {
  try {
    // Force 302 redirect status code into 301 'permanent redirect'
    Field statusField = HttpGenerator.class.getDeclaredField("__status");
    statusField.setAccessible(true);
    Object[] statusMap = (Object[]) statusField.get(HttpStatus.class);
    statusMap[HttpStatus.MOVED_TEMPORARILY_302] = statusMap[HttpStatus.MOVED_PERMANENTLY_301];
  } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
} else if (server.getClass().getPackage().getImplementationVersion().startsWith("6")) {
  try {
    // Force 302 redirect status code into 301 'permanent redirect'
    Field statusField = HttpStatus.class
        .getDeclaredField("__responseLine");
    statusField.setAccessible(true);
    Buffer[] responseLine = (Buffer[]) statusField
        .get(HttpStatus.class);
    byte[] bytes = responseLine[302].toString().replace("302", "301")
        .getBytes();
    responseLine[302] = new ByteArrayBuffer(bytes, 0, bytes.length,
        Buffer.IMMUTABLE);
  } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
} else {
  throw new IllegalStateException("Jetty version "
      + server.getClass().getPackage().getImplementationVersion()
      + " not yet supported?");
}

Need Your Help

I have installed Magento ver. 1.9.2.4 on live server but unable to integrate payumoney in system/configuration/payment method

magento-1.9 payu payumoney

I have installed Magento version 1.9.2.4 and as per the PayUMoney documentation, I have pasted the "payu" folder into respective folder but still not able to see "payucheckout" tab in system/cofigu...

Conversion binary floating point to hex floating point

floating-point binary hex octal

For example I have 0 100 1110 sign exponent mantisa this is equal to 3.75. How to convert it to hexadecimal or octal form? I have searched really hard for few hours. Please help.