使用Java访问Magento API:过程ххх不存在

时间:2010-06-15 15:33:31

标签: java web-services soap proxy magento

我需要构建Special Java Api来包装Magento Api。在与几个Magento漏洞挣扎之后,我终于能够登录并获得会话ID;但我打电话的任何方法都会导致我出错。错误是:

Procedure '*procedure name*' not present

我使用Eclipse build in in plugin和wsdl在我的本地服务器上生成了来自wsdl的Java代码: http://localhost/magento/index.php/api/v2_soap?wsdl=1

我使用的java代码示例:

    Mage_Api_Model_Server_V2_HandlerPortTypeProxy proxy = new Mage_Api_Model_Server_V2_HandlerPortTypeProxy(
            "http://localhost/magento/index.php/api/");
    String sessionId = proxy.login("magentobot", "123456");
    System.out.println("Session: " + sessionId);
    CatalogProductEntity[] products = proxy.catalogProductList(sessionId, new Filters(), "");

这是我得到的例外:

Session: 12abdaf054fb7100b6c5d84ab8cb8311
Exception in thread "main" AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
 faultSubcode: 
 faultString: Procedure 'catalogProductList' not present
 faultActor: 
 faultNode: 
 faultDetail: 
    {http://xml.apache.org/axis/}stackTrace:Procedure 'catalogProductList' not present
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at Magento.Mage_Api_Model_Server_V2_HandlerBindingStub.catalogProductList(Mage_Api_Model_Server_V2_HandlerBindingStub.java:3104)
    at Magento.Mage_Api_Model_Server_V2_HandlerPortTypeProxy.catalogProductList(Mage_Api_Model_Server_V2_HandlerPortTypeProxy.java:260)
    at Main2.main(Main2.java:14)

    {http://xml.apache.org/axis/}hostname:Dacer

以下是官方文档的链接:Magento product API 它表示该方法称为 catalog_product.list

API的PHP代码工作正常:

<?php
$proxy = new SoapClient('http://localhost/magento/index.php/api/?wsdl');
$sessionId = $proxy->login('magentobot', '123456');
$filters = array();
$products = $proxy->call($sessionId, 'product.list', array($filters));

var_dump($products);
?>

我会很乐意提供任何帮助。

1 个答案:

答案 0 :(得分:5)

我以前从未使用过java中的API,但是查看你的代码示例,你说你使用v2 WSDL(应该有更好的Java / .NET SOAP支持)生成代码,但在你的代码示例中你指的是v1网址

http://localhost/magento/index.php/api/

我认为您希望代码示例指向

http://magento1point4.dev/index.php/api/v2_soap

但是,再一次,不是一个大的Java(或SOAP,就此问题)的人,所以如果有一些明显的东西我会在这里失踪。