Coder Social home page Coder Social logo

Request as XML about amadeus-ws-client HOT 8 CLOSED

tommiehansen avatar tommiehansen commented on June 29, 2024
Request as XML

from amadeus-ws-client.

Comments (8)

DerMika avatar DerMika commented on June 29, 2024 1

The logger object you provide on Client instantiation should be an instance of Psr\Log\LoggerInterface. You can provide a Monolog logger or any other PSR-compatible log object which can be set up to log to a file or a DB or anything you like.

If you do that, you'll find all request and response XML's in the logfile.

You shouldn't be overriding the log function, you should just provide a PSR compatible logging object to log to the location of your choice.

I will make filling the responseXml a configurable parameter, but I can't turn it off by default until I release a 2.0 version - since I'm following semantic versioning.

from amadeus-ws-client.

DerMika avatar DerMika commented on June 29, 2024 1

Here's a sample:

First step: install Monolog as a dependency.

Setup a logger to log to a file on your machine:

<?php

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('/var/www/myapp/logs/requestresponse.log', Logger::INFO));

Now use the $log object you created instead of the NullLogger as shown in the client instantiation example: https://github.com/amabnl/amadeus-ws-client/blob/master/docs/about-get-started.rst#set-up-a-test-client

Execute some messages through the client, and you'll find the entire request & response messages in /var/www/myapp/logs/requestresponse.log.

from amadeus-ws-client.

DerMika avatar DerMika commented on June 29, 2024

If you provide a logger to the client, it will log all requests & responses.

Do you mean that having responseXml in the result object should be optional? What's your reasoning for that?

from amadeus-ws-client.

tommiehansen avatar tommiehansen commented on June 29, 2024

Hm, yes -- adding things to the default log() @ NullLogger.php or creating an own logger and adding stuff to it seems to interrupt everything and not return the raw xml messages though? Expected, from me, is that one has the ability to simply put stuff into logs without interrupting the normal flow.

ie:

    public function log($level, $message, array $context = array())
    {
		
		print_r($message);
		print_r($level);
		print_r($context);	
		
    }

What i want is basically to turn on logging and then log every XML req/response as files, in a db or whatever.

The reasoning for not including the RAW XML in the response (making it object + raw xml) is that some results are 0.7-1 MB in pure XML. Hardly matters for tiny responses/requests, but try 250 results using MasterPricer and then have 100 of such requests in 1 second. :)

from amadeus-ws-client.

tommiehansen avatar tommiehansen commented on June 29, 2024
  1. Hm -- okay. It seems to be beyond my understanding unfortunately. Will try to figure it out anyway when i got the time.

  2. Ok -- great!

from amadeus-ws-client.

tommiehansen avatar tommiehansen commented on June 29, 2024

Completed and it works, thanks for the help!

It's an ugly implementation but here it is for anyone else wondering how to do it:

BASH/CMD

cd <your_dir_with_amabnl_lib>
composer require monolog/monolog

yourFile.php

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logName = 'requestResponse';
$logSrc = $conf->logger->src; // ie /var/www/amabnl/logs/
$log = new Logger('log');
$log->pushHandler(new StreamHandler($logSrc . $logName .'.log', Logger::INFO));

// ns
use Amadeus\Client;
use Amadeus\Client\Params;
use Amadeus\Client\Result;
use Amadeus\Client\RequestOptions\CommandCrypticOptions;

// amadeus default params
$params = new Params([
    'sessionHandlerParams' => [
        'soapHeaderVersion' => Client::HEADER_V4, // default, can be omitted.
        'wsdl' => $conf->amadeus->wsdl,
        'stateful' => true, // Enabled by default. Stateful needed for transactions etc
        'logger' => $log, // use log object previously created
        'authParams' => [
            'officeId' => $conf->amadeus->officeId, // The Amadeus Office Id you want to sign in to - must be open on your WSAP.
            'userId' => $conf->amadeus->user, // Also known as 'Originator' for Soap Header 1 & 2 WSDL's
            'passwordData' => base64_encode($conf->amadeus->pass), // **base 64 encoded** password
        ]
    ],
    'requestCreatorParams' => [
        'receivedFrom' => $conf->amadeus->company, // The "Received From" string that will be visible in PNR History
    ]
]);


$client = new Client($params);

// DO STUFF ...

from amadeus-ws-client.

DerMika avatar DerMika commented on June 29, 2024

Good to hear! Then I'm closing this issue and the follow-up for the responseXml will be handled in the other issue.

from amadeus-ws-client.

DerMika avatar DerMika commented on June 29, 2024

Added a sample to create a logfile in the docs: https://github.com/amabnl/amadeus-ws-client/blob/master/docs/how-to.rst#logging-request-and-response

from amadeus-ws-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.