//we can then re-initalize them with this same info
try {
if (file.getName().equals(ResteasyExtension.FILTER_DISPATCHER)) {
FieldInfo field = new FieldInfo(file.getConstPool(), FIELD_NAME, FILTER_FIELD_TYPE);
field.setAccessFlags(Modifier.PUBLIC);
file.addField(field);
field = new FieldInfo(file.getConstPool(), PARAMETER_FIELD_NAME, SET_TYPE);
field.setAccessFlags(Modifier.PUBLIC);
file.addField(field);
for (final MethodInfo method : (List<MethodInfo>) file.getMethods()) {
if (method.getName().equals("init") &&
method.getDescriptor().equals("(Ljavax/servlet/FilterConfig;)V")) {
final Bytecode b = new Bytecode(file.getConstPool());
b.addAload(0);
b.addAload(1);
b.addPutfield(ResteasyExtension.FILTER_DISPATCHER, FIELD_NAME, FILTER_FIELD_TYPE);
b.addAload(1);
b.addInvokeinterface("javax/servlet/FilterConfig", "getServletContext", "()Ljavax/servlet/ServletContext;", 1);
b.addAload(0);
b.addGetfield(ResteasyExtension.FILTER_DISPATCHER, PARAMETER_FIELD_NAME, SET_TYPE);
b.addInvokestatic(CONTEXT_PARAMS, "init", INIT_METHOD_DESC);
b.addAload(0);
b.add(Opcode.SWAP);
b.addPutfield(ResteasyExtension.FILTER_DISPATCHER, PARAMETER_FIELD_NAME, SET_TYPE);
method.getCodeAttribute().iterator().insert(b.get());
method.getCodeAttribute().computeMaxStack();
} else if(method.getName().equals("<init>")) {
//no idea why this is needed
method.getCodeAttribute().setMaxStack(1);
}
}
return true;
} else if (file.getName().equals(ResteasyExtension.SERVLET_DISPATCHER)) {
FieldInfo field = new FieldInfo(file.getConstPool(), FIELD_NAME, SERVLET_FIELD_TYPE);
field.setAccessFlags(Modifier.PUBLIC);
file.addField(field);
field = new FieldInfo(file.getConstPool(), PARAMETER_FIELD_NAME, SET_TYPE);
field.setAccessFlags(Modifier.PUBLIC);
file.addField(field);
for (final MethodInfo method : (List<MethodInfo>) file.getMethods()) {
if (method.getName().equals("init") &&
method.getDescriptor().equals("(Ljavax/servlet/ServletConfig;)V")) {
final Bytecode b = new Bytecode(file.getConstPool());