camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Crivellaro <mcr...@optasportsdata.com>
Subject Re: FTP creating connections for every file name in the uri
Date Wed, 29 Sep 2010 11:17:57 GMT

Using interceptSendToEndpoint I've tried setting the header
Exchange.INTERCEPTED_ENDPOINT
to the new endpoint URI (without the fileName) and setting the filename as
Exchange.FILE_NAME.

However the enpoint parameters being used remain the original one.

this is the my interceptSendToEndpoint:



interceptSendToEndpoint("(ftp|sftp|ftps):.*").process(
   new Processor() {
      public void process(Exchange exchange) throws Exception {
         Logger logger = Logger.getLogger("Interceptor");
         try
         {
            String interceptedEndpoint =
exchange.getIn().getHeader(Exchange.INTERCEPTED_ENDPOINT, String.class);
            logger.info("Intercepted endpoint: " + interceptedEndpoint);
            URI endpointURI = new URI(interceptedEndpoint);
            String query = endpointURI.getQuery();
									
            Map paramsMap = new HashMap<String,String>();
            String params[] = query.split("&");

            for (String param : params) {
               String temp[] = param.split("=");
               paramsMap.put(temp[0], temp[1]);
            }
								    
            if(paramsMap.containsKey("fileName"))
            {
               String fileName = (String) paramsMap.get("fileName");
               logger.debug("fileName:" +  fileName);
								    	
								    	
               exchange.getIn().setHeader(Exchange.FILE_NAME, fileName);
               //TODO: remove the hack
               exchange.getIn().setHeader(Exchange.FILE_NAME, "test.xml");
               paramsMap.remove("fileName");
								    	
               StringBuilder amendedQuery = new StringBuilder();
               for(Object eachKey : paramsMap.keySet())
               {
                  if(amendedQuery.length() > 0)
                  {
                     amendedQuery.append("&");
                  }
                  amendedQuery.append(eachKey.toString());
                  amendedQuery.append("=");
                  amendedQuery.append(paramsMap.get(eachKey).toString());
               }
								    	
               logger.debug("new querystring:" + amendedQuery.toString());
								    	
               URI amendedEndpointURI = new URI(endpointURI.getScheme(), 
               endpointURI.getUserInfo(),
                  endpointURI.getHost(),
                  endpointURI.getPort(),
                  endpointURI.getPath(), 
                  amendedQuery.toString(),
                  endpointURI.getFragment());
								    	
               interceptedEndpoint = amendedEndpointURI.toString();
               logger.info("New endpoint: " + interceptedEndpoint);
               exchange.getIn().setHeader(Exchange.INTERCEPTED_ENDPOINT,
interceptedEndpoint);

            }
            else
            {
               logger.error("Cannot find parameter fileName.");
            }								    								
         }
         catch(Exception anException)
         {
            logger.error("Exception occurred:" + anException);
         }
      }
   }
);




-- 
View this message in context: http://camel.465427.n5.nabble.com/FTP-creating-connections-for-every-file-name-in-the-uri-tp478938p2999929.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message