WebSphere Web Services Client for C++, Version 1.0.1 オペレーティング・システム: Linux, Windows

クライアント・ハンドラーのサンプル・コード

以下に示すコード・サンプルは、クライアント・アプリケーション用のハンドラーを作成する方法を実証するテンプレートとなります。

株価情報サンプルには、以下のサンプル・ファイルがあります。 以下の 3 つのサンプル・ファイルです。

これらのファイルは、<inst_dir>/samples/handlers 内にあります。

myClientHandler.hpp

/*********************************************************************/
/* */
/* IBM Web Services Client for C/C++ */
/* */
/* FILE NAME: myClientHandler.hpp */
/* */
/* DESCRIPTION: Example Client handler header file */
/* for the Stock Quote sample */
/* */
/*********************************************************************/
/* <START_COPYRIGHT> */
/* */
/* Licensed Materials - Property of IBM */
/* */
/* 6205-001 */
/* */
/* (c) Copyright IBM Corp. 2004, 2005 */
/* All Rights Reserved */
/* */
/* U.S. Government Users Restricted Rights - use, */
/* duplication or disclosure restricted by GSA */
/* ADP Schedule Contract with IBM Corp. */
/* */
/* Status: Version 1 Release 0 */
/* <END_COPYRIGHT> */
/* */
/*********************************************************************/
#if !defined( _HANDLER_HPP__INCLUDED_)
#define _HANDLER_HPP__INCLUDED_
#include <axis/Handler.hpp>
AXIS_CPP_NAMESPACE_USE
class myClientHandler : public Handler
{
public:
myClientHandler();
virtual ~myClientHandler();
// init is called when the Handler is loaded.
int AXISCALL init();
// invoke is called when AxisClient is about to send the request SOAP message
// or when a response message has just been received.
int AXISCALL invoke( void * pvIMsg);
// onFault is called if there is a fault with message processing.
void AXISCALL onFault( void * pvIMsg);
// fini is called when the Handler is about to unloaded.
int AXISCALL fini();
};
#endif // !defined(_HANDLER_HPP__INCLUDED_)

myClientHandler.cpp

/*********************************************************************/
/* */
/* IBM Web Services Client for C/C++ */
/* */
/* FILE NAME: myClientHandler.cpp */
/* */
/* DESCRIPTION: Example Client Handler */
/* for the stock quote sample */
/* */
/*********************************************************************/
/* <START_COPYRIGHT> */
/* */
/* Licensed Materials - Property of IBM */
/* */
/* 6205-001 */
/* */
/* (c) Copyright IBM Corp. 2004, 2005 */
/* All Rights Reserved */
/* */
/* U.S. Government Users Restricted Rights - use, */
/* duplication or disclosure restricted by GSA */
/* ADP Schedule Contract with IBM Corp. */
/* */
/* Status: Version 1 Release 0 */
/* <END_COPYRIGHT> */
/* */
/*********************************************************************/
// Include myClientHandler header file to obtain the class definition, etc.
#include "myClientHandler.hpp"
// Include the header file to obtain the BasicHandler object, etc.
#include <axis/GDefine.hpp>
#include <axis/IHandlerSoapSerializer.hpp>
#include <axis/IHandlerSoapDeSerializer.hpp>
#include <iostream>
// myHandler is called when the object is created.
myClientHandler::myClientHandler()
{
}
// ~myClientHandler is called when the object is destroyed.
myClientHandler::~myClientHandler()
{
}
int myClientHandler::invoke( void * pvHandlerMessage)
{
// Cast the current message into the IMessageData type. This will allow the
// user to change the SOAP message as appropriate.
IMessageData * pIMsgData = (IMessageData *) pvHandlerMessage;
// Check if the SOAP message is just about to be transmitted or has just been
// received.
if( pIMsgData->isPastPivot())
{
// Yes - the available SOAP message is a response
cout << "Past the pivot point – Handler can see the response message."
<< endl;
}
else
{
// No - the available SOAP message is a request
cout << "Before the pivot point – Handler can see the request message¥n"
<< endl;
}
return AXIS_SUCCESS;
}
void myClientHandler::onFault( void * pvFaultMessage)
{
// Please leave empty.
}
int myClientHandler::init()
{
return AXIS_SUCCESS;
}
int myClientHandler::fini()
{
return AXIS_SUCCESS;
}

myClientHandlerFactory.cpp

/*********************************************************************/
/* */
/* IBM Web Services Client for C/C++ */
/* */
/* FILE NAME: myClientHandlerFactory.cpp */
/* */
/* DESCRIPTION: Example client handler factory */
/* for the stock quote sample */
/* */
/*********************************************************************/
/* <START_COPYRIGHT> */
/* */
/* Licensed Materials - Property of IBM */
/* */
/* 6205-001 */
/* */
/* (c) Copyright IBM Corp. 2004, 2005 */
/* All Rights Reserved */
/* */
/* U.S. Government Users Restricted Rights - use, */
/* duplication or disclosure restricted by GSA */
/* ADP Schedule Contract with IBM Corp. */
/* */
/* Status: Version 1 Release 0 */
/* <END_COPYRIGHT> */
/* */
/*********************************************************************/
// Include myClientHandler header file to obtain the class definition, etc.
#include "myClientHandler.hpp"
// Include the header file to obtain the BasicHandler object, etc.
#include <axis/GDefine.hpp>
// External methods available to the loader of this handler library.
extern "C"
{
// GetClassInstance is passed a pointer to a pointer that will contain the
// handler object to be created by this factory. Before the handler object is
// returned, it is wrapped in a BasicHandler object and the handler's
// initialise method is called.
STORAGE_CLASS_INFO int GetClassInstance( BasicHandler ** ppClassInstance)
{
*ppClassInstance = new BasicHandler();
myClientHandler * pmyClientHandler = new myClientHandler();
// Setting functions to zero indicates that the handler is a C++ type
(*ppClassInstance)->_functions = 0;
// If the handler was loaded successfully, save the handler object and
// initialise it.
if( pmyClientHandler)
{
(*ppClassInstance)->_object = pmyClientHandler;
return pmyClientHandler->init();
}
// If the hander was not loaded successfully, then return an error.
return AXIS_FAIL;
}
// DestroyInstance is passed a pointer to a generic BasicHandler object that
// contains an instance of this type of handler object. The handler is
// unwrapped from the BasicHandler object whereupon, the handler's finish
// method is called before deleting the handler and then the BasicHandler
// wrapper.
STORAGE_CLASS_INFO int DestroyInstance( BasicHandler * pClassInstance)
{
if( pClassInstance)
{
//Cast the generic handler object to the specific class.
myClientHandler * pmyClientHandler = static_cast<myClientHandler*>
(pClassInstance->_object);
// Call the finish method on the handler. This will allow the handler to
// ‘tidy’ before it is deleted.
pmyClientHandler->fini();
// Delete the handler objects.
delete pmyClientHandler;
delete pClassInstance;
// Return success.
return AXIS_SUCCESS;
}
// Return error if there was no handler to close down and delete.
return AXIS_FAIL;
}
}

Reference topic

ご利用条件 | フィードバック (英語のみ)

Timestamp icon最終更新: 12 Jun 2006
(C) Copyright IBM Corporation 2005, 2006. All Rights Reserved.
このインフォメーション・センターでは Eclipse テクノロジーが採用されています。(http://www.eclipse.org)