Advertisement
aironman

static

Oct 31st, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. public class HelloSipWorld extends SipServlet {
  2.  
  3. private static String newAppNameFromCallServiceString = "";
  4.  
  5. static {
  6. try {
  7. Annotation[] listaDeclaredAnnotations = HelloSipWorld.class.getPackage().getDeclaredAnnotations();
  8. Class<?> pClass = Class.forName("com.kurento.kmf.sip.package-info");
  9. Field field = Class.class.getDeclaredField("annotations");
  10. field.setAccessible(true);
  11.  
  12. Map<Class<? extends Annotation>, Annotation> annotationsMap = (Map<Class<? extends Annotation>, Annotation>) field.get(pClass);
  13. for (Annotation anotattion : listaDeclaredAnnotations) {
  14.  
  15. if (anotattion instanceof CallService) {
  16. System.out.println("Procesando anotacion CallService...");
  17. final CallService oldCallService = (CallService) annotationsMap.get(CallService.class);
  18. //assign to the temp var newAppNameFromCallServiceString the value from name of @CallService in order i can asign it when @SipApplication is procesed
  19. newAppNameFromCallServiceString = oldCallService.name();
  20. }
  21.  
  22. }
  23.  
  24. } catch (Exception xcp) {
  25. xcp.printStackTrace();
  26. }
  27. System.out.println("END static HelloSipWorld...");
  28. }
  29.  
  30. @Override
  31. /**I am trying to use Reflection Api in order to assign a temporal value usign
  32. setApplicationName method from org.mobicents.as7.deployment.SIPWebContext wich is located in jboss-as7-mobicents-2.0.0.FINAL.jar
  33. */
  34. public void init(ServletConfig servletConfig) throws ServletException {
  35. System.out.println("Trying to initialize HelloSipWorld Servlet...");
  36. Object ctx = servletConfig;
  37.  
  38. try {
  39. Field fWrapper = ctx.getClass().getDeclaredField("wrapper");
  40. fWrapper.setAccessible(true);
  41. Object ctx2 = fWrapper.get(ctx);
  42. Field fParent = Class.forName("org.apache.catalina.core.ContainerBase").getDeclaredField("parent");
  43. fParent.setAccessible(true);
  44. Object ctx3 = fParent.get(ctx2);
  45. //i am trying to access to setApplicationName method from class org.mobicents.as7.deployment.SIPWebContext wich is located in a jar provided by maven
  46. if (ctx3.getClass().getName().equals("org.mobicents.as7.deployment.SIPWebContext")) {
  47.  
  48. //here the crash happens!
  49. // Caused by: java.lang.ClassNotFoundException:
  50. // org.mobicents.servlet.sip.ruby.SipRubyController from [Module
  51. // "org.mobicents.libs:main" from local module loader @67cc3210
  52. // (roots:
  53. // /home/alonso/mss-2.0.0.FINAL-jboss-as-7.1.2.Final/modules)]
  54. Method method = ctx3.getClass().getMethod("setApplicationName", new Class[] {});
  55. //this line is not executed!
  56. method.invoke(ctx3, new Object[] { newAppNameFromCallServiceString });
  57. }
  58. } catch (java.lang.Throwable xcp) {
  59. xcp.printStackTrace();
  60. }
  61. super.init(servletConfig);
  62. }
  63.  
  64. //rest of the methods...
  65. }//end of HelloSipWorld
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement