Announcement Announcement Module
Collapse
No announcement yet.
HTTP GET to download ZIP file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 03:38 PM.

  • #2
    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.

    Comment


    • #3
      Thank you for your relpy Gary,

      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, 03:40 PM.

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment


          • #6
            Hi,

            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

            Comment


            • #7
              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.

              Comment


              • #8
                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.

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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.

                    Comment

                    Working...
                    X