Layer7 API Management

 View Only
  • 1.  Converting a zip file into a binary code.

    Posted Jun 30, 2020 03:25 AM
    Hi,
    I have created a zip file through gzip assertion and now i want to convert that zip file into its Binary format. Please guide on if there is some way to convert it to binary.

    Thanks and Regards
    Amit


  • 2.  RE: Converting a zip file into a binary code.
    Best Answer

    Broadcom Employee
    Posted Jun 30, 2020 02:38 PM
    I assume you used the Encode/Decode Data assertion with the GZIP compress option. If so, the output from it is already in its binary format.

    The following policy shows this in action:

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
        <wsp:All wsp:Usage="Required">
            <L7p:CommentAssertion>
                <L7p:Comment stringValue="* Illustrate gzip"/>
            </L7p:CommentAssertion>
            <L7p:AuditAssertion>
                <L7p:SaveRequest booleanValue="true"/>
            </L7p:AuditAssertion>
            <L7p:SetVariable>
                <L7p:Base64Expression stringValue="LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KT3JpZ2luYWwgTWVzc2FnZToNClNlbnQ6IDA2LTMwLTIwMjAgMDM6MjUgQU0NCkZyb206IEFtaXQgUGF0cmENClN1YmplY3Q6IENvbnZlcnRpbmcgYSB6aXAgZmlsZSBpbnRvIGEgYmluYXJ5IGNvZGUuDQoNCkhpLA0KSSBoYXZlIGNyZWF0ZWQgYSB6aXAgZmlsZSB0aHJvdWdoIGd6aXAgYXNzZXJ0aW9uIGFuZCBub3cgaSB3YW50IHRvIGNvbnZlcnQgdGhhdCB6aXAgZmlsZSBpbnRvIGl0cyBCaW5hcnkgZm9ybWF0LiBQbGVhc2UgZ3VpZGUgb24gaWYgdGhlcmUgaXMgc29tZSB3YXkgdG8gY29udmVydCBpdCB0byBiaW5hcnkuDQoNClRoYW5rcyBhbmQgUmVnYXJkcw0KQW1pdA=="/>
                <L7p:ContentType stringValue="text/plain; charset=utf-8"/>
                <L7p:DataType variableDataType="message"/>
                <L7p:VariableToSet stringValue="msg"/>
            </L7p:SetVariable>
            <L7p:EncodeDecode>
                <L7p:SourceVariableName stringValue="msg"/>
                <L7p:TargetContentType stringValue="application/gzip; charset=utf-8"/>
                <L7p:TargetDataType variableDataType="message"/>
                <L7p:TargetVariableName stringValue="msg.gz"/>
                <L7p:TransformType transformType="GZIP"/>
            </L7p:EncodeDecode>
            <L7p:HardcodedResponse>
                <L7p:Base64ResponseBody stringValue="JHttc2cuZ3p9"/>
                <L7p:ResponseContentType stringValue="application/gzip; charset=UTF-8"/>
            </L7p:HardcodedResponse>
        </wsp:All>
    </wsp:Policy>


    When I hit that with curl and pipe it through zcat I get the original text:

    jay@macjo14-laptop ~ $ curl -s http://ssg94.l7tech.com:8080/test | zcat