我正在尝试处理来自 Java SOAP 服务的 SWA 响应。在该 SWA 响应中,二进制附件连同一些 MIME header 附加到 XML 的末尾。我不能将 WSO2 用于依赖性要求限制。
如有任何帮助,我们将不胜感激!
// Input
------=_Part_42_539586119.1332526191981
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <03B4708A9544C182C43E51D9ADA1E456>
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body> ... TRUNCATED XML SOAP RESPONSE ... </soapenv:Body></soapenv:Envelope>
------=_Part_42_539586119.1332526191981
Content-Type: image/png
Content-Transfer-Encoding: binary
Content-Id: <D637B1257E3E5EEA06AF0E45494F8448>
BINARY DATA GOES HERE
// End of input
//拆分响应的脚本 + 像父类 SoapClient 一样返回 StdObj + 对文件做一些事情
namespace Project;
class SoapClient extends \SoapClient
{
public function __call ($function_name, $arguments)
{
// have the parent do a soap call, catch the lastResponse() if an error
// occurred (eg has an attachment) and parse it out.
try {
$r = parent::__call($function_name, $arguments);
return $r;
} catch (\Exception $e) {
// Assumption: When this is sent, it means that a file is being sent
// because SimpleXML can't process it.
if ($e->getMessage() == "looks like we got no XML document") {
$response = parent::__getLastResponse();
$partString = "/(------=_[a-zA-Z0-9_\\.]+)/";
$outputArr = preg_split($partString, $response);
// $outputAtt[0] -- empty and is the first MIME Part Header
// $outputArr[1] -- Mime Header + XML (The SOAP Response)
// $outputArr[n+1] -- additional files w/ MIME headers
if (array_key_exists(1, $outputArr)) {
// remove the first 5 lines (4 MIME Header lines) + 1 Blank
// line
$data = implode("\n",
array_slice(explode("\n", $outputArr[1]), 5));
/// Simple XML Object ... appears to be an empty SimpleXMLElement though ... >:-(
$xml = simplexml_load_string($data, null, null, "http://schemas.xmlsoap.org/soap/envelope/");
} else {
// OK Maybe this doesn't actually contain the XML... throw
// the original exception.
throw new \SoapFault($e->getMessage(), $e->getCode(),
$e->getPrevious());
}
} else {
throw new \SoapFault($e->getMessage(), $e->getCode(),
$e->getPrevious());
}
}
}
}
最佳答案
使用 MIME parser为了这。从那里开始非常简单:
require_once('MimeMailParser.class.php');
class SwADownloadSoapClient extends SoapClient
{
const ATTACHMENT_DIR = '/path/to/saved/attachments/';
public function __doRequest(
$request, $location, $action, $version, $one_way=0
) {
// Issue the SOAP request as SoapClient would normall
$sResult = parent::__doRequest(
$request, $location, $action, $version, $one_way);
// Handle and parse MIME-encoded messages
// @note We're not doing much inspection
// of the XML payload against the attachments ATM
// so not sure how greatly this lives up to the spec
$sResult = $this->_parseMimeMessage($sResult);
$oParser = new MimeMailParser();
$oParser->setText($sResult);
// Save the attachments
$aAttachments = $oParser->getAttachments();
foreach($aAttachments as $oAttachment) {
$sFile = $oAttachment->filename;
if($rFp = fopen(self::ATTACHMENT_DIR . $sFile, 'w')) {
while($sBytes = $attachment->read())
fwrite($rFp, $sBytes);
fclose($rFp);
}
}
}
}
如果你想更恰本地实现the spec ,您需要将 MIME 附件与 SOAP XML 进行匹配。
关于PHP - 扩展 SoapClient 以处理 SWA(带附件的 SOAP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9844470/
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。
我有一个要在我的Rails3项目中使用的数组扩展方法。它应该住在哪里?我有一个应用程序/类,我最初把它放在(array_extensions.rb)中,在我的config/application.rb中我加载路径:config.autoload_paths+=%W(#{Rails.root}/应用程序/类)。但是,当我转到railsconsole时,未加载扩展。是否有一个预定义的位置可以放置我的Rails3扩展方法?或者,一种预先定义的方式来添加它们?我知道Rails有自己的数组扩展方法。我应该将我的添加到active_support/core_ext/array/conversion
我对图像处理完全陌生。我对JPEG内部是什么以及它是如何工作一无所知。我想知道,是否可以在某处找到执行以下简单操作的ruby代码:打开jpeg文件。遍历每个像素并将其颜色设置为fx绿色。将结果写入另一个文件。我对如何使用ruby-vips库实现这一点特别感兴趣https://github.com/ender672/ruby-vips我的目标-学习如何使用ruby-vips执行基本的图像处理操作(Gamma校正、亮度、色调……)任何指向比“helloworld”更复杂的工作示例的链接——比如ruby-vips的github页面上的链接,我们将不胜感激!如果有ruby-
我有一个super简单的脚本,它几乎包含了FayeWebSocketGitHub页面上用于处理关闭连接的内容:ws=Faye::WebSocket::Client.new(url,nil,:headers=>headers)ws.on:opendo|event|p[:open]#sendpingcommand#sendtestcommand#ws.send({command:'test'}.to_json)endws.on:messagedo|event|#hereistheentrypointfordatacomingfromtheserver.pJSON.parse(event.d
我想编写一个ruby脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"
这个问题有两个部分。在RubyProgrammingLanguage一书中,有一个使用模块扩展字符串对象和类的示例(第8.1.1节)。第一个问题。为什么如果您使用新方法扩展类,然后创建该类的对象/实例,则无法访问该方法?irb(main):001:0>moduleGreeter;defciao;"Ciao!";end;end=>nilirb(main):002:0>String.extend(Greeter)=>Stringirb(main):003:0>String.ciao=>"Ciao!"irb(main):004:0>x="foobar"=>"foobar"irb(main):
我正在尝试解析网页,但有时会收到404错误。这是我用来获取网页的代码:result=Net::HTTP::getURI.parse(URI.escape(url))如何测试result是否为404错误代码? 最佳答案 像这样重写你的代码:uri=URI.parse(url)result=Net::HTTP.start(uri.host,uri.port){|http|http.get(uri.path)}putsresult.codeputsresult.body这将打印状态码和正文。