Announcement Announcement Module
Collapse
No announcement yet.
How to read META-INF/MANIFEST.MF from an action? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to read META-INF/MANIFEST.MF from an action?

    I am trying to figure out the preferred way to read my war's manifest file from within an action in webflow. I am a little stuck because I don't have access to the servlet context inside a webflow action. Is there a way to inject this into an action as a Resource? I haven't been able to figure this out - any help much appreciated.

    Thanks!

  • #2
    in ur webflow action get servlet request object(from requestContext) and then using ServletContext read it.

    InputStream in = servletReq.getSession().getServletContext().getRes ourceAsStream("/META-INF/MANIFEST.MF");
    Manifest manifest = new Manifest(in);
    java.util.jar.Attributes attributes = manifest.getMainAttributes();
    System.out.println("in details..."+attributes.size());
    System.out.println("Built-By:"+attributes.getValue("Built-By"));

    Comment


    • #3
      That is all well and good, except for the fact that a webflow RequestContext is not linked to an HTTP request, and you cannot get the request object from it. Hence the point of my question. Your code will not work when passing in a flowRequestContext.

      Comment


      • #4
        Seems to me you should be able to get the request from externalContext.getNativeRequest(). ExternalContext is a special webflow EL variable. Maybe that's what you're looking for?

        Comment


        • #5
          Try this way to get HttpServletRequst

          see the methods in ExternalContext class. If your external system that has interacted with the webflow is Servlet, try something like this.

          ((ServletExternalContext)reqContext.getExternalCon text()).getRequest();

          If you are doing this in a Portlet, get portletRequest first and unwrap it to ServletRequest, then to HttpServletRequest.

          Comment


          • #6
            In my Spring Webflow app:
            context.getExternalContext() returns a
            Code:
            org.springframework.webflow.mvc.servlet.MvcExternalContext
            which extends
            Code:
            org.springframework.webflow.context.servlet.ServletExternalContext
            However, the method getRequest(), as in :
            Code:
            HttpServletRequest request = (MvcExternalContext)context.getExternalContext()).getRequest();
            is protected, so I still can't get the HttpServletRequest

            Comment


            • #7
              Use ExternalContext's getNativeRequest() method, and cast it to an HttpServletRequest.

              Comment


              • #8
                Thanks for all your help. I was able to do it like you suggested:
                Code:
                 try {
                
                                HttpServletRequest request = (HttpServletRequest)((MvcExternalContext)context.getExternalContext()).getNativeRequest();
                                InputStream in = request.getSession().getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF");
                                Manifest manifest = null;
                
                                manifest = new Manifest(in);
                                java.util.jar.Attributes atts = manifest.getMainAttributes();
                
                                version       = atts.getValue("Implementation-Version");
                                buildTime     = atts.getValue("Implementation-Build-Time");
                                artifactTitle = atts.getValue("Implementation-Title");
                
                            } catch (Exception e) {
                
                            }
                One caveat though, since I am using a MockRequestContext in my tests, I had to refactor my test code like this:
                Code:
                private void startFlowWithMvcMockedContext(MutableAttributeMap input) {
                        MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "testurl");
                        MockHttpServletResponse servletResponse = new MockHttpServletResponse();
                        MockServletContext servletContext = new MockServletContext();
                
                        FlowUrlHandler flowUrlHandler = new DefaultFlowUrlHandler();
                
                        MvcExternalContext servletExternalContext = new MvcExternalContext(
                        servletContext, servletRequest, servletResponse, flowUrlHandler);
                
                        MockRequestContext context = new MockRequestContext();
                        context.setExternalContext(servletExternalContext) ;
                
                        startFlow(input, context.getExternalContext());
                    }

                Comment


                • #9
                  I would recommend to use Manifests from jcabi-manifests. With this utility class you can read any attribute with just one line:

                  Code:
                  String value = Manifests.read("My-Attribute");

                  Comment

                  Working...
                  X