Hi Vinod,
Adding the to what SajithAR said,
You can create new jaggery module [1] using Apache HTTP client [2] to do
your task. I think this is easies and cleanest way.

You would get the http stream from the http client request and then channel
the stream to response output stream. The chunking should be taken care by
httpClient and HttpServletResponse itself. Use java NIO channels for better
performance.

See sample Jaggery module which accesses HttpResponse in [3]

[1]
http://madhukaudantha.blogspot.com/2014/02/writing-hostobject-for-jaggery.html
[2] http://hc.apache.org/httpclient-3.x/tutorial.html
[3]
https://github.com/wso2/jaggery/blob/542105b0bc01ec229773f905fc8a7e87a4bb167e/components/hostobjects/org.jaggeryjs.hostobjects.web/src/main/java/org/jaggeryjs/hostobjects/web/ResponseHostObject.java

Cheers,
Ruwan

On Thu, Jul 9, 2015 at 4:19 PM, Vinod Kavinda <vi...@wso2.com> wrote:

> Hi Nirmal,
>
> print(httpClient.responseText); writes the response back.
>
> @Sajith I need to handle this from Jaggery side.
>
> On Thu, Jul 9, 2015 at 3:41 PM, Sajith Ariyarathna <sajit...@wso2.com>
> wrote:
>
>> Hi Vinod,
>>
>> Can you use Java in the scenario? If so, then you can implement this task
>> in Java and call that Java method inside your Jaggery code. I think
>> implementing this task using Java will be lot easier.
>>
>> Thanks.
>>
>>
>> On Thu, Jul 9, 2015 at 3:36 PM, Nirmal Fernando <nir...@wso2.com> wrote:
>>
>>> Where are you reading the chunked incoming data? I can't find it in the
>>> code you pasted.
>>>
>>> So, the data is chunked and you have to read the data correctly. Spec:
>>> http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
>>>
>>> On Thu, Jul 9, 2015 at 3:28 PM, Vinod Kavinda <vi...@wso2.com> wrote:
>>>
>>>> Hi,
>>>> Thanks Inshaf. But this won't solve my problem. I have already done the
>>>> downloading directly from browser, option. What I'm expecting is to get it
>>>> to backend and then pass back to browser.
>>>> This chunking is the problem.
>>>>
>>>> Regards,
>>>> Vinod
>>>>
>>>> On Thu, Jul 9, 2015 at 3:18 PM, Inshaf Mahath <ins...@wso2.com> wrote:
>>>>
>>>>> Hi Vinod,
>>>>>
>>>>> Since you are using Jaggery, you can use JavaScript to create and
>>>>> download a file. You can have a look on [1], but not sure whether it 
>>>>> aligns
>>>>> with your requirement.
>>>>>
>>>>> [1] -
>>>>> http://blog.eliacontini.info/post/79860720828/export-to-csv-using-javascript-and-the-download
>>>>>
>>>>> Thanks,
>>>>> Inshaf
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Jul 9, 2015 at 1:49 PM, Vinod Kavinda <vi...@wso2.com> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I'm trying to download a file from a given URL (File get downloaded
>>>>>> if we directly go to the link via browser), in a jaggery app.
>>>>>>
>>>>>> I need to get the file to the Jaggery backend and send it to the
>>>>>> browser so that file should get downloaded. I tried this by sending a get
>>>>>> request to the relevant URL, setting all the headers received from get
>>>>>> response to the jaggery response and printing the payload as shown below.
>>>>>>
>>>>>>         var httpClient = new XMLHttpRequest();
>>>>>>         httpClient.open('GET', url, true);
>>>>>>         httpClient.setRequestHeader('COOKIE',
>>>>>> session.get('MGT_SESSION'));
>>>>>>
>>>>>>          //copy header details
>>>>>>                         var contentType =
>>>>>> httpClient.getResponseHeader("Content-Type");
>>>>>>         var transferEncoding =
>>>>>> httpClient.getResponseHeader("Transfer-Encoding");
>>>>>>         var vary = httpClient.getResponseHeader("Vary");
>>>>>>         var date = httpClient.getResponseHeader("Date");
>>>>>>         var server = httpClient.getResponseHeader("Server");
>>>>>>         var contentDisposition =
>>>>>> httpClient.getResponseHeader("Content-Disposition");
>>>>>>
>>>>>>         response.addHeader('Content-Type', contentType);
>>>>>>         response.addHeader('Transfer-Encoding', transferEncoding);
>>>>>>         response.addHeader('Vary', vary);
>>>>>>         response.addHeader('Date', date);
>>>>>>         response.addHeader('Server', server);
>>>>>>         response.addHeader('Content-Disposition', contentDisposition);
>>>>>>
>>>>>>                         print(httpClient.responseText);
>>>>>>
>>>>>> A file get downloaded as expected. But is is a corrupted file with
>>>>>> less size than actual size of the file.
>>>>>>
>>>>>> I think the reason for this is the data is coming as chunked data
>>>>>> packets. The 'Transfer-Encoding' header value is 'chunked'.
>>>>>>
>>>>>> Any hint on resolving this is much appreciated.
>>>>>>
>>>>>> Thank You,
>>>>>> Vinod
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Vinod Kavinda
>>>>>> Software Engineer
>>>>>> *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.*
>>>>>> Mobile : +94 (0) 712 415544
>>>>>> Blog : http://soatechflicks.blogspot.com/
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Dev mailing list
>>>>>> Dev@wso2.org
>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Inshaf Mahath
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Vinod Kavinda
>>>> Software Engineer
>>>> *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.*
>>>> Mobile : +94 (0) 712 415544
>>>> Blog : http://soatechflicks.blogspot.com/
>>>>
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> Dev@wso2.org
>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>
>>>>
>>>
>>>
>>> --
>>>
>>> Thanks & regards,
>>> Nirmal
>>>
>>> Associate Technical Lead - Data Technologies Team, WSO2 Inc.
>>> Mobile: +94715779733
>>> Blog: http://nirmalfdo.blogspot.com/
>>>
>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev@wso2.org
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Sajith Ariyarathna
>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>> mobile: +94 77 6602284, +94 71 3951048
>>
>
>
>
> --
> Vinod Kavinda
> Software Engineer
> *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.*
> Mobile : +94 (0) 712 415544
> Blog : http://soatechflicks.blogspot.com/
>
>
> _______________________________________________
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 

*Ruwan Abeykoon*
*Architect,*
*WSO2, Inc. http://wso2.com <http://wso2.com/> *
*lean.enterprise.middleware.*

email: ruw...@wso2.com
phone:(+94) 777739736
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to