Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HelloSipWorld extends SipServlet {
- private static String newAppNameFromCallServiceString = "";
- static {
- try {
- Annotation[] listaDeclaredAnnotations = HelloSipWorld.class.getPackage().getDeclaredAnnotations();
- Class<?> pClass = Class.forName("com.kurento.kmf.sip.package-info");
- Field field = Class.class.getDeclaredField("annotations");
- field.setAccessible(true);
- Map<Class<? extends Annotation>, Annotation> annotationsMap = (Map<Class<? extends Annotation>, Annotation>) field.get(pClass);
- for (Annotation anotattion : listaDeclaredAnnotations) {
- if (anotattion instanceof CallService) {
- System.out.println("Procesando anotacion CallService...");
- final CallService oldCallService = (CallService) annotationsMap.get(CallService.class);
- //assign to the temp var newAppNameFromCallServiceString the value from name of @CallService in order i can asign it when @SipApplication is procesed
- newAppNameFromCallServiceString = oldCallService.name();
- }
- }
- } catch (Exception xcp) {
- xcp.printStackTrace();
- }
- System.out.println("END static HelloSipWorld...");
- }
- @Override
- /**I am trying to use Reflection Api in order to assign a temporal value usign
- setApplicationName method from org.mobicents.as7.deployment.SIPWebContext wich is located in jboss-as7-mobicents-2.0.0.FINAL.jar
- */
- public void init(ServletConfig servletConfig) throws ServletException {
- System.out.println("Trying to initialize HelloSipWorld Servlet...");
- Object ctx = servletConfig;
- try {
- Field fWrapper = ctx.getClass().getDeclaredField("wrapper");
- fWrapper.setAccessible(true);
- Object ctx2 = fWrapper.get(ctx);
- Field fParent = Class.forName("org.apache.catalina.core.ContainerBase").getDeclaredField("parent");
- fParent.setAccessible(true);
- Object ctx3 = fParent.get(ctx2);
- //i am trying to access to setApplicationName method from class org.mobicents.as7.deployment.SIPWebContext wich is located in a jar provided by maven
- if (ctx3.getClass().getName().equals("org.mobicents.as7.deployment.SIPWebContext")) {
- //here the crash happens!
- // Caused by: java.lang.ClassNotFoundException:
- // org.mobicents.servlet.sip.ruby.SipRubyController from [Module
- // "org.mobicents.libs:main" from local module loader @67cc3210
- // (roots:
- // /home/alonso/mss-2.0.0.FINAL-jboss-as-7.1.2.Final/modules)]
- Method method = ctx3.getClass().getMethod("setApplicationName", new Class[] {});
- //this line is not executed!
- method.invoke(ctx3, new Object[] { newAppNameFromCallServiceString });
- }
- } catch (java.lang.Throwable xcp) {
- xcp.printStackTrace();
- }
- super.init(servletConfig);
- }
- //rest of the methods...
- }//end of HelloSipWorld
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement