Results 1 to 10 of 10

Thread: HTTP GET to download ZIP file

  1. #1
    Join Date
    Aug 2012
    Posts
    7

    Default HTTP GET to download ZIP file

    I have a question,

    I can to configure spring-integration (or Spring Batch) to get a ZIP file and write the payload to a ZIP file?

    I want to use HTTP Client 4.1 to provide credentials (username and password)

    Thanks
    --Marino
    Last edited by mborra; Jan 18th, 2013 at 03:38 PM.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    Write a custom Service (invoked by a <service-activator/>) that writes to a ZipOutputStream. There's also a ZipInputStream for reading zips.

    I am not sure what relevance HTTP authentication has to this discussion.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Aug 2012
    Posts
    7

    Default

    Thank you for your relpy Gary,

    Quote Originally Posted by Gary Russell View Post
    Write a custom Service (invoked by a <service-activator/>) that writes to a ZipOutputStream. There's also a ZipInputStream for reading zips.
    As I wrote in the subject, in fact my first problem is to configure Spring Integration to execute HTTP GET to download a ZIP file and only after this, write the payload (zip file) to a file.

    With <service-activator/> i can get input-stream (payload) from <int-http:*inbound*/>

    I am not sure what relevance HTTP authentication has to this discussion.
    The authentication is required to perform the download.
    Last edited by mborra; Jan 18th, 2013 at 03:40 PM.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    You have to run the Spring Integration HTTP inbound gateway in a Web Container (e.g. Tomcat); the container handles the authentication and it has nothing to do with Spring Integration.

    If the zip file already exists, why do you need Spring Integration? Just return it as a static web resource.

    If you need to create the file dynamically based on the request, do as I said, and write a service to get the request from the gateway, process it, create the zip file and return it.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    645

    Default

    Hi!

    As I understand you need to invoke external service who returns you a ZIP.
    So, I recommend something like this:
    HTML Code:
    <bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
    		<property name="credentials">
    			<bean class="org.apache.commons.httpclient.UsernamePasswordCredentials"
    				  c:userName="username" c:password="password"/>
    		</property>
        </bean>
    
        <bean id="clientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"
    		  depends-on="messageSender"
              p:httpClient="#{messageSender.httpClient}"/>
    
    <http:outbound-gateway request-channel="getZipChannel" http-method="GET"
    						   expected-response-type="byte[]"
    						   url="http://host/ext-service?zipName={zipName}"
    						   request-factory="clientHttpRequestFactory">
        <http:uri-variable name="zipName" expression="payload"/>
    </http:outbound-gateway>
    Take care,
    Artem

  6. #6
    Join Date
    Aug 2012
    Posts
    7

    Default

    Hi,

    Quote Originally Posted by Cleric View Post
    Hi!

    As I understand you need to invoke external service who returns you a ZIP.
    Yes! This is my problem.

    So, I recommend something like this:
    HTML Code:
    <bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
    		<property name="credentials">
    			<bean class="org.apache.commons.httpclient.UsernamePasswordCredentials"
    				  c:userName="username" c:password="password"/>
    		</property>
        </bean>
    
        <bean id="clientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"
    		  depends-on="messageSender"
              p:httpClient="#{messageSender.httpClient}"/>
    
    <http:outbound-gateway request-channel="getZipChannel" http-method="GET"
    						   expected-response-type="byte[]"
    						   url="http://host/ext-service?zipName={zipName}"
    						   request-factory="clientHttpRequestFactory">
        <http:uri-variable name="zipName" expression="payload"/>
    </http:outbound-gateway>
    Thank you Cleric, this is a good starting point, I imagined a similar solution, but i don't know how I can schedule outbound-gateway at fixed (cron) time, and then I've discarded my solution.

    --Marino

  7. #7
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    Have a look at this section of the reference manual:
    http://static.springsource.org/sprin...espace-inbound

    You can define an inbound-channel-adapter with a cron-based poller that is upstream (e.g. its "channel" could be the "request-channel" of an outbound-gateway), and it can even include just an expression rather than ref+method if sufficient.

  8. #8
    Join Date
    Aug 2012
    Posts
    7

    Default

    Quote Originally Posted by Gary Russell View Post
    You have to run the Spring Integration HTTP inbound gateway in a Web Container (e.g. Tomcat); the container handles the authentication and it has nothing to do with Spring Integration.

    If the zip file already exists, why do you need Spring Integration? Just return it as a static web resource.
    My application is a stand-alone, I can not run it in a Web Container.

    I need Spring Integration for many other operations. Download the ZIP is just the first.

  9. #9
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    Sorry, your question was not clear to me; I thought you were talking about serving up a zip file to a client - as Mark and Cleric have pointed out, if your app is the client then you can use an http outbound adapter.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  10. #10
    Join Date
    Aug 2012
    Posts
    7

    Default

    Quote Originally Posted by Gary Russell View Post
    Sorry, your question was not clear to me;
    No problem! Sometimes it is not easy to be clear.

    I thought you were talking about serving up a zip file to a client - as Mark and Cleric have pointed out, if your app is the client then you can use an http outbound adapter.
    Thank you very much anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •