Я сгенерировал веб-клиенты для SOAP
веб-сервисов, используя Apache Axis2 1.7.8
И я написал ниже класс CustomStub
, который класс stub
расширяет / наследует.
public class CustomStub extends Stub {
protected AxisService _service;
protected ArrayList modules = new ArrayList();
protected ServiceClient _serviceClient;
/**
* Get service client implementation used by this stub.
*
* @return service client
*/
public ServiceClient _getServiceClient() {
return _serviceClient;
}
/**
* Set service client implementation used by this stub. Once set, the
* service client is owned by this stub and will automatically be removed
* from the configuration when use of the stub is done.
*
* @param _serviceClient
*/
public void _setServiceClient(ServiceClient _serviceClient) {
this._serviceClient = _serviceClient;
}
/**
* Create a SOAP message envelope using the supplied options.
* TODO generated stub code should use this method, or similar method taking
* an operation client
*
* @param options
* @return generated
* @throws SOAPProcessingException
*/
protected static SOAPEnvelope createEnvelope(Options options) throws SOAPProcessingException {
return getFactory(options.getSoapVersionURI()).getDefaultEnvelope();
}
/**
* Get Axiom factory appropriate to selected SOAP version.
*
* @param soapVersionURI
* @return factory
*/
protected static SOAPFactory getFactory(String soapVersionURI) {
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
return OMAbstractFactory.getSOAP11Factory();
} else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapVersionURI)) {
return OMAbstractFactory.getSOAP12Factory();
} else {
throw new RuntimeException(Messages
.getMessage("unknownsoapversion"));
}
}
/**
* Finalize method called by garbage collection. This is overridden to
* support cleanup of any associated resources.
*
* @throws Throwable
*/
protected void finalize() throws Throwable {
super.finalize();
cleanup();
}
/**
* Cleanup associated resources. This removes the axis service from the
* configuration.
*
* @throws AxisFault
*/
public void cleanup() throws AxisFault {
// service is removed from the service client it self.
_serviceClient.cleanup();
}
/**
* sets the epr of the service client to given value
*
* @param address
*/
protected void setServiceClientEPR(String address) {
EndpointReference toEPRFromServiceClient = _serviceClient.getOptions().getTo();
toEPRFromServiceClient.setAddress(address);
}
/**
* add an http header with name and value to message context
*
* @param messageContext
* @param name
* @param value
*/
protected void addHttpHeader(MessageContext messageContext,
String name,
String value) {
java.lang.Object headersObj = messageContext.getProperty(HTTPConstants.HTTP_HEADERS);
if (headersObj == null) {
headersObj = new java.util.ArrayList();
}
java.util.List headers = (java.util.List) headersObj;
Header header = new Header();
header.setName(name);
header.setValue(value);
headers.add(header);
messageContext.setProperty(HTTPConstants.HTTP_HEADERS, headers);
}
/**
* sets the propertykey and propertyValue as a pair to operation client
*
* @param operationClient
* @param propertyKey
* @param propertyValue
*/
protected void addPropertyToOperationClient(OperationClient operationClient,
String propertyKey,
Object propertyValue) {
operationClient.getOptions().setProperty(propertyKey, propertyValue);
}
protected void addPropertyToOperationClient(OperationClient operationClient,
String propertyKey,
boolean value) {
addPropertyToOperationClient(operationClient, propertyKey, new Boolean(value));
}
protected void addPropertyToOperationClient(OperationClient operationClient,
String propertyKey,
int value) {
addPropertyToOperationClient(operationClient, propertyKey, new Integer(value));
}
protected void setMustUnderstand(OMElement headerElement, OMNamespace omNamespace) {
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMAttribute mustUnderstandAttribute =
omFactory.createOMAttribute(SOAP12Constants.ATTR_MUSTUNDERSTAND, omNamespace,
"true");
headerElement.addAttribute(mustUnderstandAttribute);
}
protected void addHeader(OMElement omElementToadd,
SOAPEnvelope envelop,
boolean mustUnderstand){
SOAPHeaderBlock soapHeaderBlock =
envelop.getHeader().addHeaderBlock(omElementToadd.getLocalName(),omElementToadd.getNamespace());
// soapHeaderBlock.setMustUnderstand(mustUnderstand);
OMNode omNode = null;
// add child elements
Iterator children = omElementToadd.getChildElements();
while (children.hasNext()) {
// for (Iterator iter = omElementToadd.getChildren(); iter.hasNext();){
omNode = (OMNode) children.next();
soapHeaderBlock.addChild(omNode);
}
OMAttribute omatribute = null;
// add attributes
for (Iterator iter = omElementToadd.getAllAttributes(); iter.hasNext();){
omatribute = (OMAttribute) iter.next();
soapHeaderBlock.addAttribute(omatribute);
}
}
protected void addHeader(OMElement omElementToadd,
SOAPEnvelope envelop){
addHeader(omElementToadd,envelop,false);
}
protected void addAnonymousOperations(){
RobustOutOnlyAxisOperation robustoutoonlyOperation =
new RobustOutOnlyAxisOperation(ServiceClient.ANON_ROBUST_OUT_ONLY_OP);
_service.addOperation(robustoutoonlyOperation);
OutOnlyAxisOperation outOnlyOperation = new OutOnlyAxisOperation(ServiceClient.ANON_OUT_ONLY_OP);
_service.addOperation(outOnlyOperation);
OutInAxisOperation outInOperation = new OutInAxisOperation(ServiceClient.ANON_OUT_IN_OP);
_service.addOperation(outInOperation);
}
}
Но когда япри вызове веб-службы получаю следующее сообщение об ошибке:
log4j: ПРЕДУПРЕЖДЕНИЕ. Не удалось найти ни одного добавочного файла для регистратора (org.apache.axiom.locator.DefaultOMMetaFactoryLocator).log4j: WARN Пожалуйста, правильно инициализируйте систему log4j.Исключение в потоке "main" java.util.ConcurrentModificationException: текущий узел был удален с использованием метода, отличного от Iterator # remove (), в org.apache.axiom.om.impl.traverse.OMAbstractIterator.hasNext (OMAbstractIterator.java:67) в org.apache.axiom.om.impl.traverse.OMFilterIterator.hasNext (OMFilterIterator.java:54) в org.apache.axis2.axis2userguide.CustomStub.addHeader (CustomStub.java:200) в org.apache.axis2.axis2userguide.1012 *