Web Service - PHP Zend ( Blank Page - No Errors ) - php

I made a simple version of my code. It gives no errors, but it simply doesn't work.
(I have Soap enabled for PHP)
Class With Function: (Metodo.php)
class Teste {
/*
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
}
Server: (Server.php)
<?php
require_once('Metodo.php');
if($_SERVER['QUERY_STRING'] == "wsdl") {
try {
require_once('Zend/Soap/AutoDiscover.php');
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('Teste');
$wsdl->handle();
}catch(exception $e) {
echo $e->getMessage();
}
} else {
$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);
require_once('Zend/Soap/Server.php');
$server = new SoapServer($wsdl_url);
$server->setClass('Teste');
$server->handle();
}
?>
Client: (Client.php)
<?php
require_once('Zend/Soap/Client.php');
$wsdl_url = "http://localhost:8090/WebService/Server.php?wsdl";
$client = new Zend_Soap_Client($wsdl_url);
try {
echo $client->SayHello();
echo ":)";
} catch (SoapFault $e) {
echo $e->getMessage();
}
?>
It just prints ":)", no errors, but it won't call the method SayHello().
If anyone would PLEASE help me, I would be so thankful. Really.
Thank you so much.

A few things:
$server = new SoapServer($wsdl_url);
should be:
$server = new Zend_Soap_Server($wsdl_url);
it may work without, but since you required in the Zend Soap Server class on the line before, you may as well use it.
In Server.php:
$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);
make sure that this URL includes the right port (as you are using port 8090). I can't remember off the top of my head if HTTP_HOST does or not.
And then most importantly, in your class:
/*
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
should be:
/**
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
note the extra * at the start of the comment. The auto discovery classes work using PHPDoc blocks, which must start with /** in order to be valid. (Easy to miss!)
If it still doesn't work after these changes, make absolutely sure that PHP has not cached your bad WSDL file (PHP caches WSDL files by default). The easiest way to do this is to remove any files that start with 'wsdl' from your /tmp/ folder (or equivalent on your system). After making these changes I got the right output using your code.

There should be an error being logged someplace. Check the server and PHP logs. There are also some 'trace/debug' settings for the SOAP client. You might get more info back on last call/response with those enabled.
With out more info here are some observations:
non standard function name. In ZF camelCase is the norm.
non standard port, not sure why but might be related
Have you tried with the a browser to access the WSDL? Does it resolve?
freenodes' #zftalk channel (IRC) can be a good resource as well. Please post back here if you do find an answer there.

Related

Magento Integration With T-Hub

am setting up a sand box for a T-Hub Integration with Magento and quickbooks. I've set my life site up locally using WAMP server, and now Its on to trying to tie that local Magento site into T-hub.
The first error that I received stated the
"Connection to Magento store failed. Service authentication failure - Notice: Undefined index: httponly in c:\wamp\www\testsite\appcode\core\mage\Core\Model\Session\Abtract\Varien.php on line 98."
After some searching I found the the general consensus on that one was I had to put an ssl on my local server, done, that problem's gone. Now I'm get a general error message that simply says "Connection to Magento Failed"
I used the test page that atandra included with their files which returned this:
<RESPONSE Version="4.1">
<Envelope>
<Command>GETORDERS</Command>
<StatusCode>9001</StatusCode>
<StatusMessage>
Service authentication failure - Warning: array_key_exists() expects parameter 2 to be array, string given in C:\wamp\www\adamsarms\app\code\core\Mage\Captcha\Model\Observer.php on line 166
</StatusMessage>
<Provider>Magento</Provider>
</Envelope>
</RESPONSE>
Which kicks back to this is the php file:
public function checkUserLoginBackend($observer)
{
$formId = 'backend_login';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
$loginParams = Mage::app()->getRequest()->getPost('login', array());
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
if ($captchaModel->isRequired($login)) {
if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
$captchaModel->logAttempt($login);
Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
}
}
$captchaModel->logAttempt($login);
return $this;
}
This line is the one it directly points to:
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
I'm not sure which direction I need to go to fix this error to make t-hub start talking to magento proper, I've included everything that I've got, if someone needs more information please let me know, I just need a better understanding of what might be causing this error to possibly find a path to fixing it.
This is an issue with a Legacy codebase with the T-Hub extension. It was created for PHP 5.3 & Magento versions 1.4 & below. They really should update this thing since people are using it.
The companies official response is this: http://support4.atandra.com/index.php?/Knowledgebase/Article/View/92/4/magento-array_key_exists-error
Which is horrible because it relies on overriding core files.
What's going on is Mage_Captcha_Model_Observer has an event checkUserLoginBackend() that gets fired. This expects the POST info for 'login' to be a certain format. This is something that has changed over the years since legacy code does not have it in this format.
This is a really hacky fix. But it's better than overriding core magento files.
Change the CheckUser() function of Mage/Thub/Model/Run/Run.php to this (I've removed some of their comments):
public function CheckUser()
{
try {
$username = $this->RequestParams['USERID'];
$password = $this->RequestParams['PASSWORD'];
//here we just set the POST to our specified format..
//which is what the observer model thinks it should be
Mage::app()->getRequest()->setPost('login', array(
'username' => $username,
'password' => $password
));
$user = Mage::getSingleton('admin/user');
$userRole = Mage::getSingleton('admin/role');
if ($user->authenticate($username, $password)) {
$loadRole = $userRole->load($user->getRoles($user));
} else {
print($this->xmlErrorResponse($this->RequestParams['COMMAND'], '9000',
'Order download service authentication failure - Login/Password supplied did not match', $this->STORE_NAME, ''));
exit;
}
} catch (Exception $e) {
$this->Msg[] = "Critical Error CheckUser (Exception e)=" . $e->getMessage(); //BB 11Nov2014
print($this->xmlErrorResponse($this->RequestParams['COMMAND'], '9001',
'Service authentication failure - ' . " " . $e->getMessage(), $this->STORE_NAME, ''));
// End - <TIBB> 13Dec2011
exit;
}
}
Another alternative is to extend the Mage_Captcha_Model_Observer class with your own version that removes those array checks in checkUserLoginBackend().

Difficulty navigating SOAP client WSDL with PHP functions

I am experimenting with a public SOAP API in preparation for testing an internal SOAP API that we are working on at work. I am running into problems dealing with automatically associating method names with parameter names.
More specifically I am testing against http://www.webservicex.net/stockquote.asmx?WSDL and what I am trying to do is write a function I can use in Behat so that our QA people can easily create new scenarios specifying new functions (as they are created) without me writing a new function every time.
To do this I built a function wrapper for SoapClient::__soapCall(). I have been able to get calls to specific functions to work such as this:
<?php
public function iGetAQuoteFor($symbol) {
$response = $this->client->GetQuote(array('symbol' => $symbol));
$quote = simplexml_load_string($response->GetQuoteResult)->Stock;
echo "Quote:\n" . print_r($quote, true) . "\n";
}
?>
So obviously I need to identify the parameter I am sending to the SOAP service for it to be effective. But to do that I need to be able to map the function name to the option names. I have tried processing the WSDL with SimpleXML, but I am having a difficult time navigating the results of that. I have tried a bunch of different methods and made some headway when I used the SimpleXML function 'children' and specified the 'wsdl' namespace. But what I get below that isn't any better.
Here is my soap call function (written as a Behat context):
/**
* Calls a specific SOAP function (defined in the WSDL).
*
* #param string $functionName
* #param string $options (optional, no implemented yet)
*
* #Given /^I make a SOAP call to "([^"]*)" with "([^"]*)"$/
* #Given /^I make a SOAP call to "([^"]*)"$/
*/
public function iMakeASOAPCallTo($functionName, $passedOptions = NULL) {
//Deal with the options
$options = array($passedOptions);
if (stristr($passedOptions, ',')) {
$options = explode(',', $passedOptions);
}
else if (empty($passedOptions)) {
$options = array();
}
//Also should try to figure out how to match the function call to the option wrapper
#Function placeholder
//Attempt to make the call
try {
$result = $this->client->__soapCall($functionName, $options);
}
catch (\Exception $e) {
throw new Exception("Failed to call SOAP function.");
}
//Process the result
if (!empty($result)) {
$result = $this->decodeSOAPResult($functionName, $result);
if (!empty($result)) {
echo " It returns:\n" . print_r($result, true) . "\n";
}
else {
throw new Exception("Invalid result from function call.");
}
}
else {
throw new Exception("Failed result or exception from function call.");
}
}
And this is my function that attempts to get the schema details after establishing the connection to the soap service.
private function buildSchemaDetails() {
$xml = simplexml_load_file($this->soapURL);
echo "\n" . print_r($xml, true) . "\n";
echo "For the ns:\n";
$element = $xml->getDocNamespaces();
echo "\n" . print_r($element, true) . "\n";
$element = $xml->children('wsdl', true)->types->children();
echo "\n" . print_r($element, true) . "\n";
die();
}
As you can see I have some testing code in there. It is ugly right now, but I need to figure out how to process this. If anyone knows of a tool that does all of this for me ahead of time that would be awesome.
Essentially what I want to be able to do is identify the parameters to a function before I make any attempts to call it. If the function has only one parameter then I would like to just map the variable entered to the one parameter name based on the function I am calling and then call it.
This is useful within Behat when writing features and scenarios because then it allows me to write a Gherkin-style line such as 'Then I make a SOAP call to "GetQuote" with "GOOG"' and not having to worry about specifying the name of the parameter. In the case of this WSDL I found it to be a bit ridiculous that couldn't just pass in the one variable and be done with it. I have seen anther SOAP service where I didn't have to specify the parameter name.
So being able to understand the call structure is key to simplifying all of this.

Overriding Kohana_Exception::_handler() for Production - 3.3

I am using Kohana 3.3 and I read in this forum post.
It says that to prevent stack traces from being shown to the end users, I need to override Kohana_Exception::_handler() to do something different with the errors that percolate up. Does that mean overriding Kohana_Exception and adding the following function?
public static function _handler(Exception $e)
{
try
{
// Log the exception
Kohana_Exception::log($e);
// Generate the response
//instead of below line:
//$response = Kohana_Exception::response($e);
$response = //what do I do here, return a 404 page or custom 500 page?
return $response;
}
//rest of function
}
If so, what do I return there?
EDIT:
bootstrap.php
/**
* Attach the file write to logging. Multiple writers are supported.
*/
Kohana::$log->attach(new Log_File(APPPATH.'logs'));
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
/**
* Attach customer error handler if we are in production
*/
if(Kohana::$environment == Kohana::PRODUCTION || Kohana::$environment == Kohana::STAGING)
{
set_exception_handler(array('My_Exception', 'handler'));
throw new Exception('text'); //this works, if removed however my exception handler does not do anything
}
My_Exception.php (in classes/My/Exception.php)
<?php
class My_Exception extends Kohana_Exception
{
public static function handler(Exception $e)
{
try
{
// Log the exception
Kohana_Exception::log($e);
// Let's try and load an error View
$class = get_class($e);
if($class == 'HTTP_Exception_404')
{
$view = View::factory('errors/404');
$view->set('error_code', 404);
}
else
{
$view = View::factory('errors/general');
$view->set('error_code', $e->getCode()); // alternatively use $e->getCode()
$view->set('error_message', $e->getMessage()); // alternatively use $e->getMessage();
}
// Let's render the output and send it to the browser
$response = $view->render();
echo $response;
}
catch (Exception $e)
{
/**
* Things are going *really* badly for us, We now have no choice
* but to bail. Hard.
*/
// Clean the output buffer if one exists
ob_get_level() AND ob_clean();
// Set the Status code to 500, and Content-Type to text/plain.
header('Content-Type: text/plain; charset='.Kohana::$charset, TRUE, 500);
// This will output the Exceptiones error message
// You may want to display something else
echo $e->getMessage();
exit(1);
}
}
}
I have actually investigated quite a bit further this issue and rewritten my asnwer from scratch now that I have a more complete understanding of Kohana's behaviour in this area.
To achieve what you're after you need to do two things:
Change the default error View (in APPPATH/bootstrap.php):
/**
* Change default error View
*/
if(Kohana::$environment == Kohana::PRODUCTION || Kohana::$environment == Kohana::STAGING)
{
Kohana_Exception::$error_view = 'errors/general';
}
Note that your template file has to use the same (and only those) variable names as Kohana's native one, i.e.:
$class
$code
$message
$file
$line
$trace
2. Create custom HTTP error pages following the tutorial you linked to in the comments.
By following these steps you assure that:
You have your own view for all Kohana's error pages.
You can have custom views for different HTTP errors.
You don't have to override Kohana's default Exception Handler (which, as this exercise proved, isn't exactly simple to implement).
I have tested the above approach and it worked like a charm for me.
I just set the Kohana_Exception::$error_view at the bootstrap file, and created the corresponding view, nothing else was necessary, all errors have redirected auto-magically...

Request for IRC URI Scheme for HTML Purifier 4.2.0

Can someone help me to establish using IRC URI Scheme for HTML Purifier 4.2.0? I can't seem to figure out how to configure or which files to modify so that purified html allows for irc:// links.
Is it possible I can simply modify configuration within the following code block?
require_once "htmlpurifier-4.2.0/library/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set("HTML.Doctype", "XHTML 1.0 Strict");
$purifier = new HTMLPurifier($purifier_config);
Update:
I edited library/standalone/HTMLPurifier/ConfigSchema/schema.ser changing both instances of "4:nntp" to "3:irc" and found error:
Warning: Directory htmlpurifier-4.2.0/library/standalone/HTMLPurifier/DefinitionCache/Serializer/URI not writable, please chmod to 777
I believe this will help to establish support for IRC URI Scheme after making this change. I'll report back in a bit.
Hmm, after making it writable, no error appeared, but no results =\
HTML Purifier doesn't seem to have a native support for the IRC scheme. But: Have you tried something like this? Put this in /library/HTMLPurifier/URIScheme, or otherwise make sure that autoloading finds it:
class HTMLPurifier_URIScheme_irc extends HTMLPurifier_URIScheme {
public $default_port = 6667;
public $browsable = false;
public function validate(&$uri, $config, $context) {
if (parent::validate($uri, $config, $context) === false) {
return false;
}
if (!is_null($uri->path)) {
// get channel name
$uri->path = array_shift(explode('/', $uri->path));
}
$uri->userinfo = null;
$uri->query = null;
$uri->fragment = null;
return true;
}
}
...and change your configuration with...
$purifier->config->set(
'URI.AllowedSchemes',
array('irc' => true, /* ... other schemes here ... */)
);
That may not work out of the box, but I'm thinking that should be the right direction...

Instantiating a AMF PHP class not working

I am trying to use AMF PHP to pass variables to a flash file, thus far I cannot see anything wrong with my code, but I have very little experience with creating classes, so here it goes, here is my code,
index.php:
<?php
include "amfphp/services/flashMe.php";
$session = true;
if ($session == true) {
$uid = '12345';
$thing = new flashMe;
$thing->push($uid);
} else {
//login
}
?>
flashMe.php:
<?php
class flashMe {
public function __construct() {
}
public function push($one)
{
return $one;//sends the uid to the flash file?
}
}
?>
Flash is looking for the flashMe class and the push method within that class, but I keep getting null variables in my flash file when I run it, is there something wrong with this code?
Thanx in advance!
Your index.php file is unnecessary.
Your second file is incomplete. Here is the example from the docs for their "hello world" class file:
<?php
class HelloWorld
{
function HelloWorld()
{
$this->methodTable = array
(
"say" => array
(
"access" => "remote",
"description" => "Pings back a message"
)
);
}
function say($sMessage)
{
return 'You said: ' . $sMessage;
}
}
?>
This file should be saved as "HelloWorld" matching the "class HelloWorld" you have named in the php file (you did this part right with FlashMe).
The example file in the docs for the Flash piece (in actionscript) is here:
import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;
var gatewayUrl:String = "http://localhost/flashservices/gateway.php"
NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);
var pc:PendingCall = _service.say("Hello world!");
pc.responder = new RelayResponder(this, "handleResult", "handleError");
function handleResult(re:ResultEvent)
{
trace('The result is: ' + re.result);
}
function handleError(fe:FaultEvent)
{
trace('There has been an error');
}
The gateway URL should go to wherever your services can be reached. I'm sure if you try a few you'll find the right one. The neat thing about amfphp is that it allows you to also test your services out before you try implementing them in the gateway (if you go to the URL in your browser).
I'm pretty new to AMFPHP as well, but I've found the docs to be extraordinarily useful. If you need more help on classes, you can find more info on the PHP docs page.
You missed the parenthesis after new flashMe
$thing = new flashMe();
$thing->push($uid);
Amfphp or Zend AMF only allow you to call public methods on a remote class that is exposed by your gateway. You example is not a class and therefore no remote method can be called. This looks more like something that you would do with an http post.
http://framework.zend.com/manual/en/zend.amf.server.html

Categories