Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Is it possible to access the SOAP::SOM object in a SOAP::Serializer subclass

Expand Messages
  • Martin Kutter
    Hi Simon, the serializer just gets passed the response, so that accessing the SOAP::SOM object not an option. The easiest way for setting the id (provided you
    Message 1 of 2 , Jan 23, 2009
    View Source
    • 0 Attachment
      Hi Simon,

      the serializer just gets passed the response, so that accessing the
      SOAP::SOM object not an option.

      The easiest way for setting the id (provided you are in a one-request
      per process environment) is to define a public variable in your
      serializer "our $REPORT_REQUEST_ID;" and set it from SUBS::Sushi:
      "$SAMS::Sushi::Serializer::REPORT_REQUEST_ID = $value_from_request;".

      Of course you can also use more elegant techniques like a dispatching to
      a object (not a class) and passing the object a reference to the
      serializer object, so it can set the ID via a setID() method or the like
      (or even pass the SOAP::SOM object) - this also avoids the side effect a
      global var has (like potentially affecting subsequent calls).

      Martin

      Am Mittwoch, den 21.01.2009, 17:30 +0000 schrieb Simon Rees:
      > Hi
      >
      > I have a mod_perl / SOAP::Lite server with a custom serializer that
      > overrides
      > the envelope method. Is it possible to access the SOAP::SOM object
      > associated
      > with the request from within the envelope method?
      > The reason I need to do this is that one of the attributes (ID) in
      > the
      > response header needs to be set to a value received in the request.
      >
      > Any suggestions on how I could do this would be appreciated!
      >
      > thanks Simon
      >
      > My abridged code.
      >
      > package SAMS::Sushi::Serializer;
      > use base qw( SOAP::Serializer );
      > sub envelope {
      >
      > my $self = shift;
      > my $type = shift;
      > my $data = shift;
      >
      > # XXX Need to access $report_request_id from request XXX
      >
      > if ( $type =~ /^(?:method|response)$/ ) {
      > $data = SOAP::Data->name('ReportResponse')->prefix('')
      > ->uri( SUSHI_COUNTER_NAMESPACE )
      > ->attr( { 'xmlns:s' => SUSHI_NAMESPACE,
      > 'xmlns:xsi'
      > => "http://www.w3.org/2001/XMLSchema-instance",
      > 'xsi:schemaLocation' => SCHEMA_LOCATION,
      > 'Created' => $create_date,
      > 'ID' => $report_request_id } );
      > }
      >
      > return $self->SUPER::envelope( $type, $data, @_ );
      > }
      > # =====================
      > package SUBS::Sushi::Apache;
      > use SOAP::Transport::HTTP;
      > use SAMS::Sushi::Serializer;
      >
      > my $server;
      > sub handler {
      >
      > $server ||= SOAP::Transport::HTTP::Apache
      > -> dispatch_with(
      > { "http://www.niso.org/schemas/sushi/counter" => "SUBS::Sushi" } )
      > -> serializer( SAMS::Sushi::Serializer->new() )
      > -> on_action( sub {} );
      > $server->handler( @_ );
      > }
      > # ======================
      > package SUBS::Sushi;
      > use base qw( SOAP::Server::Parameters );
      > sub ReportRequest {
      >
      > my $class = shift;
      > my $envelope = pop;
      > # handle request ....
      > }
      >
      > --
      > Simon Rees
      > Software Development Engineer
      >
      > Semantico, Floor 1, 21-23 Dyke Road, Brighton BN1 3FE
      > t: +44 1273 358246
      > f: +44 1273 723232
      > e: Simon dot Rees at semantico dot com
      > w: www.semantico.com
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.