That's the way I use SoapServer.
I would have thought it was more in keeping with the SoapServer API to allow
the Exception to be thrown but as it already doesn't maybe add the option.
Example
-- server.php --
<?php
class MyPersonalException extends Exception {}
class SoapTestClass {
public function testOne($value) {
return "You sent $value";
}
public function testTwo($value) {
throw new MyPersonalException('Ooops looks like we made a mistake,
but we can tell you about it');
}
public function testThree($value) {
throw new Exception('You Shouldn\'t see this error, cause it is
unhandled');
}
}
try {
$server = new SoapServer(null, array('uri' => '
http://localhost/tests/soap/server.php'));
$server->setClass('SoapTestClass');
$server->handle();
} catch(MyPersonalException $e) {
$server->fault($e->getCode(), $e->getMessage());
} catch(Exception $e) {
// do other things like logging, email the admin as this was an
unexpected error.
$server->fault('ERROR', 'An unknown error occured. Please try again.');
}
-- /server.php --
-- client.php --
<?php
$client = new SoapClient(
null,
array(
'location' => 'http://localhost/tests/soap/server.php',
'uri' => 'http://localhost/tests/soap/server.php',
'trace' => 1
)
);
echo '<b>Request One:</b><br/>';
try {
echo $client->testOne('FooBar');
} catch (SoapFault $soapFault) {
echo $soapFault;
}
echo '<br/><br/>';
echo '<b>Request Two:</b><br/>';
try {
echo $client->testTwo('FooBar');
} catch (SoapFault $soapFault) {
echo $soapFault;
}
echo '<br/><br/>';
echo '<b>Request Three:</b><br/>';
try {
echo $client->testThree('FooBar');
} catch (SoapFault $soapFault) {
echo $soapFault;
}
echo '<br/><br/>';
-- /client.php --
--
/James
On Fri, Apr 11, 2008 at 7:30 PM, Matthew Weier O'Phinney <[EMAIL PROTECTED]>
wrote:
> -- James Dempster <[EMAIL PROTECTED]> wrote
> (on Friday, 11 April 2008, 07:16 PM +0100):
> > The problem with this is that you loose the actual exception object.
>
> Okay, how about storing the exception object in the fault response? That
> would give you access to it should you want to log it or manipulate the
> response based on the exception.
>
> > I would much prefer something along what the front controller does.
> > Zend_Controller_Front::getInstance()->throwExceptions(true);
> >
> > Something like this would be handy for example...
> >
> > $server->throwException(true);
> > try {
> > echo $server->handle();
> > } catch (MyPersonalException $e) {
> > echo $server->fault($e);
> > } catch (Exception $e) {
> > // do other things like logging, email the admin as this was an
> unexpected
> > error.
> > echo $server->fault(new Exception('An unknown error occured. Please
> try
> > again.'));
> > }
>
> I'm not likely to implement this as we're trying to follow the
> SoapServer API with our server components -- and that's not how
> SoapServer works. Fault responses are still a normal response -- they
> just indicate an error occurred.
>
> > On Fri, Apr 11, 2008 at 6:05 PM, Matthew Weier O'Phinney <
> [EMAIL PROTECTED]>
> > wrote:
> >
> > -- James Dempster <[EMAIL PROTECTED]> wrote
> > (on Friday, 11 April 2008, 04:33 PM +0100):
> > > I have the very same problem.
> > >
> > > I'd much prefer to catch the Exceptions myself, and deal with them
> by
> > either
> > > allowing the message though based on the type of Exception, or
> change it
> > to a
> > > generic Exception.
> > >
> > > Maybe time to submit an issue regarding this?
> >
> > Actually, you can capture the response, and test to see if it is a
> fault
> > response, and then modify it before sending:
> >
> > $response = $server->handle();
> >
> > if ($response instanceof Zend_XmlRpc_Server_Fault) {
> > // handle differently
> > } else {
> > echo $response;
> > }
> >
> >
> > > On Fri, Apr 11, 2008 at 3:28 PM, Peter Boehlke <
> [EMAIL PROTECTED]>
> > wrote:
> > >
> > >
> > > Hi there,
> > >
> > > i'm trying around with the Zend_XMLRPC-Server. So far, i'm
> very
> > pleased
> > > with
> > > it. Everything runs without Problems etc.
> > >
> > > But i have one Problem concerning the Zend_XmlRpc_Server_Fault
> > > (standard)messages. I want to respond with my own
> fault-XML-grids, if
> > > something in the Request was wrong.
> > >
> > > Furthermore, i want to validate the Request by myself and
> generate
> > more
> > > exact error-messages in the fault-message;
> > >
> > > I hope this is understandable! ;)
> > > Thank you in advance,
> > >
> > > Peter Boehlke
> > > --
> > > View this message in context: http://www.nabble.com/
> > >
> >
> Zend_XMLRPC_Server-overwrite--response-customized-Fault-Msgs.-tp16627837p16627837.html
> > > Sent from the Zend Framework mailing list archive at
> Nabble.com.
> > >
> > >
> > >
> >
> > --
> > Matthew Weier O'Phinney
> > Software Architect | [EMAIL PROTECTED]
> > Zend - The PHP Company | http://www.zend.com/
> >
> >
>
> --
> Matthew Weier O'Phinney
> Software Architect | [EMAIL PROTECTED]
> Zend - The PHP Company | http://www.zend.com/
>