Hi,

Whoops, my file attachment didn't work.

Here's the class, inline in this message:

public class ZipComponent extends OutBinding {

  private static final Log log = LogFactory.getLog(ZipComponent.class);

  private FileMarshaler marshaler = new DefaultFileMarshaler();

  public FileMarshaler getMarshaler() {
    return marshaler;
  }

  public void setMarshaler(FileMarshaler marshaler) {
    this.marshaler = marshaler;
  }

  protected void process(MessageExchange messageExchange,
NormalizedMessage message) throws MessagingException {
    try {
      String filename = getMarshaler().getOutputName(messageExchange,
message);
      if (log.isDebugEnabled()) {
        log.debug("ZIP processing file [" + filename + "]");
      }
      StreamSource source = (StreamSource) message.getContent();
      StreamSourceInputSource inputSource = new
StreamSourceInputSource(source);
      if (isZipFilename(filename)) {
        handleZipStream(inputSource);
      }
      else {
        sendFile(inputSource.getInputStream(), filename);
      }
      done(messageExchange);
    }
    catch (Exception ex) {
      throw new MessagingException(ex);
    }
  }

  private void handleZipStream(InputStreamSource inputStreamSource) {
    new ZipInputStreamTemplate(inputStreamSource).execute(new
ZipInputStreamCallback() {
      public Object doWithZipEntry(ZipInputStream zipInputStream,
ZipEntry zipEntry) throws Exception {
        if (isZipFilename(zipEntry.getName())) {
          handleZipStream(new
InputStreamInputStreamSource(zipInputStream));
        }
        else {
          if (log.isDebugEnabled()) {
            log.debug("ZIP sending file [" + zipEntry.getName());
          }
          sendFile(zipInputStream, zipEntry.getName());
        }
        return null;
      }
    });
  }

  private void sendFile(InputStream inputStream, String name) throws
IOException, JBIException {
    InOnly exchange = getExchangeFactory().createInOnlyExchange();
    NormalizedMessage message = exchange.createMessage();
    exchange.setInMessage(message);
    getMarshaler().readMessage(exchange, message, new
NonClosingInputStream(inputStream), name);
    getDeliveryChannel().sendSync(exchange);
  }

  private boolean isZipFilename(String filename) {
    return filename.toLowerCase().endsWith(".zip");
  }

}


John Hurst
Wellington, New Zealand

-----Original Message-----
From: HURST, John B [mailto:[EMAIL PROTECTED] 
Sent: Monday, 5 December 2005 12:35
To: [email protected]
Subject: RE: [servicemix-user] Files binding: processing non-XML files

Hi,

I attach ZipComponent.java as an example.

Note: I am NOT an expert on message flows in ServiceMix, so it's very
possible I've messed something up in my interpretation of how to set up
message exchanges.  I've only tested this code with straight-through
flow at this stage.  But it works for me!

In addition to reading the examples on the web site and in the code
distribution, I would encourage you to study the code for some of the
components themselves.  It is not particularly hard to write components,
and the provided ones give you some great starting points.

John Hurst
Wellington, New Zealand

-----Original Message-----
From: Said Eloudrhiri [mailto:[EMAIL PROTECTED] 
Sent: Monday, 5 December 2005 11:40
To: [email protected]
Subject: Re: [servicemix-user] Files binding: processing non-XML files

Hi John,

Thanks for your post.

Of course, we will be very interested to have a look on your component.

In our position, we would like to build an SOA/ESB infrastructure with 
OpenSource software and for this reason why we are evaluating Mule and 
ServiceMix solutions.

Of course, ServiceMix appears very nice but we estimate that examples 
providing in the web site are not very dedicated to ServiceMix's
newbies.

Regards,

Said


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

Reply via email to