【问题标题】:Content-Disposition details extract from IBM Datapower gateway从 IBM Datapower 网关中提取的 Content-Disposition 详细信息
【发布时间】:2018-07-22 18:28:08
【问题描述】:

我想从 AS2 标头中的 Content-Disposition 中提取文件名,并将其分配给 IBM Datapower 网关中的变量。我们是否有 dp: 服务变量来提取它。

【问题讨论】:

    标签: header ibm-datapower


    【解决方案1】:

    我认为 DataPower 中并没有一个特定的变量,仅用于 AS2 消息的 Content-Disposition 标头的文件名。 但是,Content-Dispositon 标头应该是 HTTP 标头集的一部分,您可以通过 header-manifest 变量查询请求或响应。一旦有了,只需查询相关标头的值,在您的情况下为“Content-Disposition”。 您可以使用 XSLT 或 GatewayScript 执行此操作。 作为一个重载示例,不完全简化为您的用例,下面的 XSLT 遍历清单,然后使用 dp:http-request-header(...) 查询从 header-manifest 检索到的每个标头名称的值以获得个人价值观。获得 Content-Disposition 值后,您只需将“filename=...;”作为子字符串部分。 我希望这对于学习目的来说足够有趣并抓住这个想法?

    <xsl:stylesheet version="1.0" 
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
         xmlns:dp="http://www.datapower.com/extensions" 
         extension-element-prefixes="dp"> 
    <xsl:output omit-xml-declaration="yes" /> 
    
    <xsl:template match="/"> 
        <xsl:apply-templates select="dp:variable('var://service/header-manifest')/headers/header" /> 
    </xsl:template> 
    
    <xsl:template match="header"/> 
    
    <xsl:template match="header[. != 'xsl']"> 
        <property> 
            <xsl:attribute name="name"><xsl:value-of select="."/></xsl:attribute> 
            <xsl:value-of select="dp:http-request-header(.)"/> 
        </property><xsl:text>&#10;</xsl:text> 
    
        <xsl:variable name="input" select="dp:http-request-header(.)"/> 
        <xsl:message dp:priority="warning"><xsl:copy-of select="." />: <xsl:copy-of select="$input" /></xsl:message> 
    </xsl:template> 
    </xsl:stylesheet>
    

    【讨论】:

      【解决方案2】:

      AugustZ 的回答对 HTTP 标头很有用,但是当涉及到 AS2 的 Content-Disposition(文件名)时,您首先必须在 DataPower 的 AS2 合作伙伴设置中启用“保留文件名”,否则 DataPower 会删除信息。

      AS2 的 Content-Disposition 文件名不是 HTTP 标头,而是 MIME-标头,这就是为什么必须将它移到 HTTP 标头中才能获取它的原因。

      文件名也将被引用,因此以下 XSLT 将处理它:

      <!-- use xpath to get the value of Content-Disposition header. For example,
               Content-Disposition: attachment; filename="fname.txt"
               Content-Disposition: attachment; filename="fname.txt"; otherparam="xyz" 
               Content-Disposition: attachment; filename=fname.txt -->
      <xsl:variable name="cdisp" select="dp:request-header('Content-Disposition')"/>
      
      <!-- Match the value of filename, quoted or non-quoted. 
           For example, "fname.txt" or fname.txt -->
      <xsl:variable name="quoted-filename" select="regexp:match($cdisp, 'filename=(.+?)\s*(;|$)', 'i')[2]"/>
      
      <!-- strip all double quotes if the filename is double-quoted. $filename is the resulting filename -->
      <xsl:variable name="filename" select="translate($quoted-filename, '&quot;', '')"/>
      

      【讨论】:

      • 谢谢安德斯和奥古斯特.....会让你知道结果......
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多