Announcement Announcement Module
Collapse
No announcement yet.
Set Permissions prior to <file:inbound-adapter> poller execution Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Permissions prior to <file:inbound-adapter> poller execution

    I need to call script to set permissions on files prior to an adapter picking them up.

    I am thiking that the the trigger attribute referencing a bean that calls the script is a way....other ideas?

  • #2
    What 'trigger' attribute you are talking about?

    Also, the inbound adapter is invoked by the poller so its a separate process and i think you want to make sure that the file attributes are changes before files are polled, right?

    Anyway, there are couple of ways to do this. I also assume you have to call a script every time more files arrive right?

    Can you answer those questions and then we can see if we can propose a solution

    Comment


    • #3
      sorry - yes, poller trigger was what I was considering...havent used it before and yes, permissions should be set prior to polling....I suppose a TaskScheduler could run a.....

      Comment


      • #4
        Well, trigger would not work since its for when non of the pre-configured trigger options work (e.g., cron, fixed-rate etc.) and you want to write your own code.

        What you can do is configure advice on the poller. Just go though http://static.springsource.org/sprin...oint-namespace and scroll down to AOP Advice chains

        Comment


        • #5
          I am not sold on writing my own code...if I can call the script prior to polling using Spring/integration classes and configuration, I am game! No decisions have been made, but I am exploring the Advice advice :>) - does Spring have a shell script calling utility?

          Comment


          • #6
            Well when you use a word 'prior to polling' that is a text book use case for AOP since it defined concepts (advices) such as Before, After and Around. Did you expect to have something else?

            Also, more files will be added to the directory and how often do you want the script to be invoked (e.g., per each file polled?)

            Comment


            • #7
              I agree completely, it is the right solution, and quite powerful to boot...thanks for the guidance

              Comment


              • #8
                The return value is a bit of a mystery... Object... not sure what to return so I returned null but the messageHandler, which I assume is part of the Inbound-Adapter has a payload of NPE...


                <sprintoller id="permSetPoller" fixed-rate="30000" error-channel="errorChannel">
                <sprint:advice-chain >
                <bean id="permissionSetterAdvice" class="app.FilePermissionPollerAdvice"/>
                <ref bean="permissionSetterAdvice" />
                </sprint:advice-chain>
                </sprintoller>

                AbstractMessageHandler handleMessage ServiceActivator for [org.springframework.integration.handler.MethodInvo kingMessagePro
                cessor@869113] received message: [Payload=java.lang.NullPointerException][Headers={timestamp=1338476276555, id=7e52b1d0-eff9-4a07-879e-7ad3f0b40254, history=errorChannel}]
                May 31 10:57:56 [task-scheduler-10] DEBUG AbstractReplyProducingMessageHandler handleMessageInternal handler 'ServiceActivator for [org.springframework.integration.handler.M
                ethodInvokingMessageProcessor@869113]' produced no reply for request Message: [Payload=java.lang.NullPointerException][Headers={timestamp=1338476276555, id=7e52b1d0-eff9-4a07-87
                9e-7ad3f0b40254, history=errorChannel}]

                Comment


                • #9
                  Can you share your Advice implementation?

                  Comment


                  • #10
                    the advice is functioning with this top-level poller config:
                    <sprintoller id="permSetPoller" fixed-rate="30000" error-channel="errorChannel">
                    <sprint:advice-chain >
                    <bean id="permissionSetterAdvice" class="package.FilePermissionPollerAdvice"/> </sprint:advice-chain>
                    </sprintoller>

                    and this class and method - returning boolean (which I am not sure why yet, something to do with aop proxy in poller I assume....

                    public class FilePermissionPollerAdvice implements MethodInterceptor {

                    @Override
                    public Object invoke(MethodInvocation arg0) throws Throwable {
                    try{
                    new ShellCommandExecutor().call();
                    } catch(Exception e){
                    e.printStackTrace();
                    }
                    return true;
                    }

                    Where ShellExecutor call is:

                    public void call() {
                    ProcessBuilder pb = new ProcessBuilder(cmds);
                    pb.redirectErrorStream(true);
                    Process shell = null;
                    InputStream is = null;
                    try {
                    shell = pb.start();
                    is = shell.getInputStream(); // output from the command
                    int rc = shell.waitFor();
                    int c;
                    while ((c = is.read()) != -1) {
                    System.out.write(c);
                    }
                    } catch (IOException e) {

                    } catch (InterruptedException e) {
                    e.printStackTrace();
                    } finally {
                    try {
                    is.close();
                    } catch (Exception ignore) {
                    }
                    }
                    }
                    }
                    Last edited by jc_mccauley; May 31st, 2012, 01:34 PM.

                    Comment


                    • #11
                      oh, and trying two approaches - that is why the Runtime object call is commented in favor of a class to handl this...prob get same results...

                      Comment


                      • #12
                        I would recommend just using BEFORE Advice for this case. Otherwise, you need to let the method "proceed" and return its result.

                        By the way you can use [ CODE ] (without the spaces) instead of the angle brackets.

                        Comment


                        • #13
                          thanks for both - and your time

                          something like
                          Code:
                          @Before{"org.springframework.integration.endpoint.AbstractPollingEndpoint.doPol();"}

                          Comment


                          • #14
                            There's no need to go down to the level of the pointcut expression - just continue to use the advice-chain within your poller element as you did earlier. The difference is that the bean you include in that chain should just implement this interface:

                            Code:
                            public interface MethodBeforeAdvice extends BeforeAdvice {
                                void before(Method method, Object[] args, Object target) throws Throwable;
                            }

                            Comment


                            • #15
                              you'll have to forgive me as I have not worked with AOP before...

                              Now NOTHING is happening : no errors no log entries...etc...

                              "in" channel is direct.

                              Code:
                              	<sprint:poller id="permSetPoller" max-messages-per-poll="-1" fixed-rate="30000" error-channel="errorChannel">
                              		 <sprint:advice-chain >
                              			<bean id="permissionSetterAdvice" class="FilePermissionPollerAdvice"/>
                               			<ref bean="permissionSetterAdvice"  />
                              		</sprint:advice-chain>
                              	</sprint:poller>
                              
                              	<file:inbound-channel-adapter id="in"	channel="in" 
                              			directory="${pull.dir}" >
                              		<sprint:poller ref="permSetPoller" />
                              	</file:inbound-channel-adapter>
                              Class:
                              Code:
                              public class FilePermissionPollerAdvice implements MethodBeforeAdvice  {
                              
                              	private static Logger logger = Logger.getLogger(FilePermissionPollerAdvice.class);
                              
                              	@Override
                              	public void before(Method arg0, Object[] arg1, Object arg2)
                              			throws Throwable {
                              		logger.debug("  before: Set File Permissions on Inbound " );
                              		try{
                              			//Runtime.getRuntime().exec(cmds);
                              			new ShellCommandExecutor().call();
                              			
                              		} catch(Exception e){
                              			e.printStackTrace();
                              			logger.error("  ERROR OCCURRED SETTING File Permissions : " + e.getMessage());
                              		}
                              		return;
                              	}
                              }
                              Last edited by jc_mccauley; Jun 1st, 2012, 12:24 PM.

                              Comment

                              Working...
                              X