Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 将Netty中的DynamicChannel Buffer更改为String并返回到ChannelBuffer_Scala_Cordova_Netty_Finagle - Fatal编程技术网

Scala 将Netty中的DynamicChannel Buffer更改为String并返回到ChannelBuffer

Scala 将Netty中的DynamicChannel Buffer更改为String并返回到ChannelBuffer,scala,cordova,netty,finagle,Scala,Cordova,Netty,Finagle,我的web服务器是使用Twitter的Finagle库用Scala编写的,而Finagle库又依赖于Netty。因此,请求内容作为DynamicChannel缓冲区返回。如果我从终端使用curl将图像上传到服务器,如下所示: curl -T "abc.jpg" http://127.0.0.1:8080/test/image <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:

我的web服务器是使用Twitter的Finagle库用Scala编写的,而Finagle库又依赖于Netty。因此,请求内容作为DynamicChannel缓冲区返回。如果我从终端使用curl将图像上传到服务器,如下所示:

 curl -T "abc.jpg" http://127.0.0.1:8080/test/image
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
          <AuthHeader xmlns="http://www.testtesttest.co.za/">
            <LogonID>testtesttest</LogonID>
            <Password>testtesttest</Password>
          </AuthHeader>
        </soap:Header>
        <soap:Body>
          <uploadFile xmlns="http://www.testtesttest.co.za/">
            <FileDetails>
               <FileName>image.jpg</FileName>
              <FileContents>
                 {(Base64.encode(request.getContent())).toString(UTF_8)
              </FileContents>
            </FileDetails>
          </uploadFile>
        </soap:Body>
      </soap:Envelope>
然后,我可以使用如下所示的SOAP数据包读取图像并将其转发到后端Web服务器:

 curl -T "abc.jpg" http://127.0.0.1:8080/test/image
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
          <AuthHeader xmlns="http://www.testtesttest.co.za/">
            <LogonID>testtesttest</LogonID>
            <Password>testtesttest</Password>
          </AuthHeader>
        </soap:Header>
        <soap:Body>
          <uploadFile xmlns="http://www.testtesttest.co.za/">
            <FileDetails>
               <FileName>image.jpg</FileName>
              <FileContents>
                 {(Base64.encode(request.getContent())).toString(UTF_8)
              </FileContents>
            </FileDetails>
          </uploadFile>
        </soap:Body>
      </soap:Envelope>
这太差劲了,我知道我以后会提高,但现在我做到了。imageBody现在将图像内容作为字符串

现在,如果我将imageBody放回SOAP数据包中,我必须使用以下代码再次对其进行编码:

 val encoder = new BASE64Encoder();
 val encodedImage = encoder.encode(imageBody)
在这一点上,图像只是乱七八糟的。它的大小看起来不错,但我把字符串转换或编码搞砸了。对于第一个示例,我使用Netty的编码器,但是对于第二个示例,我使用标准java编码器。原因是Netty的编码器只能对ChannelBuffer类型的对象进行编码

我不想说得太大声,但我已经为此挣扎了一天多。非常感谢您提供的任何帮助。

因此,这项工作:

image --> [curl] ------> post1 -->  [your code] --> soap msg 1 --> [back-end]
这并不是:

image --> [phonegap] --> post2 -->  [your code] --> soap msg 2 --> [back-end]
为了可靠地解决这类问题,您需要了解在每个步骤中使用的编码

假设您可以使用相同的图像,您可以检查post1和post2中的原始编码内容并推断正在使用的编码吗?然后,当您理解这一点时,在解码和重新编码消息时将内容记录在代码中。通过这种方式,您可以确保soap msg1和soap msg2中的功能相同。

因此,这是可行的:

image --> [curl] ------> post1 -->  [your code] --> soap msg 1 --> [back-end]
这并不是:

image --> [phonegap] --> post2 -->  [your code] --> soap msg 2 --> [back-end]
为了可靠地解决这类问题,您需要了解在每个步骤中使用的编码


假设您可以使用相同的图像,您可以检查post1和post2中的原始编码内容并推断正在使用的编码吗?然后,当您理解这一点时,在解码和重新编码消息时将内容记录在代码中。这样,您可以确保soap msg1和soap msg2中的内容相同。

谢谢。我喜欢你布置的方式。这有点让人头脑清醒。PhoneGap的同一张照片看起来与curl的照片不太一样。我的猜测是PhoneGap在幕后做了一些压缩,但是是的,它可能也是编码。我一直在想是我写了很多信,但也许这不是问题所在。谢谢。我喜欢你布置的方式。这有点让人头脑清醒。PhoneGap的同一张照片看起来与curl的照片不太一样。我的猜测是PhoneGap在幕后做了一些压缩,但是是的,它可能也是编码。我一直在想是我写了很多东西,但也许这不是问题所在。