Here is the client implementation that we use to call a SOAP RPC service
from inside an EJB. Note that we use pure JAXRPC here. The web service
is implemented in Axis and runs inside Weblogic 6.1.
One further note: The axis client stuff re-uses code from the server
implementation. That code buggers around with classloaders, which is
unnecessary in the client and violates the EJB spec. It does appear to
work but use at your own risk.
Cheers
ADK
package nz.co.vodafone.plive.charging.payment.billing.alcatel.soap;
// imports
import nz.co.vodafone.plive.charging.common.util.Util;
import
nz.co.vodafone.plive.charging.payment.billing.alcatel.common.AlcatelBillingSystemException;
import
nz.co.vodafone.plive.charging.payment.billing.alcatel.common.AlcatelBillingSystemProxy;
import nz.co.vodafone.plive.charging.payment.billing.alcatel.corba.Log;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import org.apache.log4j.Category;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
/**
* AlcatelBillingSystemProxy that proxies the charge or refund request
* via SOAP to a servlet that then uses the AlcatelCorbaConnector to talk
* to Alcatel IN. This is done to avoid address translation problems with
IORs
* generated by the Alcatel IN.
*/
public class AlcatelSoapClient implements AlcatelBillingSystemProxy
{
private static final Category _trace =
Category.getInstance(AlcatelSoapClient.class);
//--------------------------------------------------------------------------
// attributes
private String _serviceUrl;
private Service _service;
//--------------------------------------------------------------------------
// construction
/**
* Param ctor
* @param serviceUrl the URL of the Alcatel SOAP service.
*/
public AlcatelSoapClient(String serviceUrl)
{
_serviceUrl = serviceUrl;
}
/**
* Gets the Alcatel service instance, creating one if necessary.
* @return The cached Service instance for the alcatel service.
* @throws MalformedURLException If the service URL is poorly formed.
* @throws ServiceException If a connection to the service cannot be
established.
*/
private Service getService() throws MalformedURLException,
ServiceException
{
if (_service == null)
{
ServiceFactory fx = ServiceFactory.newInstance();
_service = fx.createService(
new URL(_serviceUrl+ "?WSDL"),
new QName(_serviceUrl, "alcatel"));
}
return _service;
}
//--------------------------------------------------------------------------
// charging operations
/**
* Charge the Alcatel billing system all or nothing. If there are
insufficient
* funds then fail the operation
* @param msisdn the account id
* @param amount the amount to charge
* @return SUCCESS if the entire amount charged or INSUFFICIENT_FUNDS
if
* insufficeient funds
* @exception AlcatelBillingSystemException
*/
public int chargeAllOrNothing(String msisdn, BigDecimal amount)
throws AlcatelBillingSystemException
{
_trace.debug(Log.METHOD_ENTRY);
Integer ret = (Integer)callService("chargeAllOrNothing", msisdn,
amount);
_trace.debug(Log.METHOD_RETURN);
return ret.intValue();
}
/**
* Charge the Alcatel billing system as much as possible
* @param msisdn the account id
* @param amount the amount to charge
* @return the amount charged
* @exception AlcatelBillingSystemException
*/
public BigDecimal chargeAsMuchAsPossible(String msisdn, BigDecimal
amount)
throws AlcatelBillingSystemException
{
_trace.debug(Log.METHOD_ENTRY);
BigDecimal ret = (BigDecimal)callService("chargeAsMuchAsPossible",
msisdn, amount);
_trace.debug(Log.METHOD_RETURN);
return ret;
}
/**
* Refund the Alcatel billing system
* @param msisdn the account id
* @param amount the amount to refund (a positive amount)
* @return SUCCESS currently
* @exception AlcatelBillingSystemException
*/
public int refund(String msisdn, BigDecimal amount)
throws AlcatelBillingSystemException
{
_trace.debug(Log.METHOD_ENTRY);
Integer ret = (Integer)callService("refund", msisdn, amount);
_trace.debug(Log.METHOD_RETURN);
return ret.intValue();
}
/**
*
* @param serviceName
* @param msisdn
* @param amount
* @return
*/
private Object callService(String serviceName, String msisdn,
BigDecimal amount) throws AlcatelBillingSystemException
{
Object ret;
try
{
Call call = getService().createCall(
new QName("AlcatelBillingSystemProxy"),
new QName(serviceName));
ret = call.invoke(new Object[] {msisdn, amount});
Util.assertNotNull(ret);
}
catch (java.rmi.RemoteException e)
{
Log.soap.error("The SOAP service failed to fulfill the
request: " + e.getMessage());
throw new AlcatelBillingSystemException(e);
}
catch (MalformedURLException e)
{
Log.soap.error("The URL configured for property
'plhpayment.alcatel.soap.proxy.url' is invalid.", e);
throw new AlcatelBillingSystemException(e);
}
catch (ServiceException e)
{
_service = null; // Ensure that a new service object is
created on the next request.
Log.soap.error("Unable to create Call to SOAP service.", e);
throw new AlcatelBillingSystemException(e);
}
catch (Throwable t)
{
Log.soap.error("Caught unchecked exception.", t);
throw new AlcatelBillingSystemException("Caught unchecked
exception.");
}
return ret;
}
}
--------------------------------------------
There is no magic.
[EMAIL PROTECTED]
04/04/03 12:04 PM
Please respond to axis-user
To: [EMAIL PROTECTED]
cc:
Subject: Need some information - probably a code snippet for accessing
an Axis
webservice using an Weblogic client.
Hi,
I am trying to access an Axis webservice deployed on weblogic appserver
from
an weblogic client. The service has some user defined datatypes , does any
one have some information or
pointers to documents which has code snippets, describing how we could do
that.
thanks
-----------------------------------------------------------------------------------------------
Have you seen our website?.... http://www.vodafone.co.nz
CAUTION: This correspondence is confidential and intended for the named recipient(s)
only.
If you are not the named recipient and receive this correspondence in error, you must
not copy,
distribute or take any action in reliance on it and you should delete it from your
system and
notify the sender immediately. Thank you.
Unless otherwise stated, any views or opinions expressed are solely those of the
author and do
not represent those of Vodafone New Zealand Limited.
Vodafone New Zealand Limited
21 Pitt Street, Private Bag 92161, Auckland, 1020, New Zealand
Telephone + 64 9 357 5100
Facsimile + 64 9 377 0962