// This code is more or less copied from AxisService.createService()
// ...but why is it so complicated???
static AxisService createService(final SOAPService soapService,
AxisConfiguration axisConfiguration) throws Exception {
AxisService axisService = new OSGiAxisService(soapService);
HashMap messageReceiverClassMap = new HashMap();
MessageReceiver messageReceiver = new org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver() {
protected Object makeNewServiceObject(MessageContext msgContext) throws AxisFault {
return soapService.serviceObj;
}
};
messageReceiverClassMap.put(WSDL2Constants.MEP_URI_IN_ONLY, messageReceiver);
MessageReceiver inOutmessageReceiver = new org.apache.axis2.rpc.receivers.RPCMessageReceiver() {
protected Object makeNewServiceObject(MessageContext msgContext) throws AxisFault{
return soapService.serviceObj;
}
};
messageReceiverClassMap.put(WSDL2Constants.MEP_URI_IN_OUT, inOutmessageReceiver);
messageReceiverClassMap.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY, inOutmessageReceiver);
axisService.setParent(axisConfiguration);
axisService.setName(soapService.serviceName);
soapService.schemaGenerator =
new DefaultSchemaGenerator(soapService.serviceObj.getClass().getClassLoader(),
soapService.serviceClass,
soapService.targetNamespace,
Java2WSDLConstants.SCHEMA_NAMESPACE_PRFIX, axisService) {
// override to use "allowed method" semantics
protected JMethod[] processMethods(JMethod[] declaredMethods) throws Exception {
ArrayList al = new ArrayList();
Hashtable props = new Hashtable();
for(int i = 0; i < declaredMethods.length; i++) {
String name = declaredMethods[i].getSimpleName();
props.put("name", name);
if(soapService.allowedMethodsFilter == null ||
soapService.allowedMethodsFilter.match(props)) {
Activator.log.info("allow method " + name);
al.add(declaredMethods[i]);
} else {
Activator.log.info("skip method " + name);
}
}
JMethod[] r = new JMethod[al.size()];
al.toArray(r);
JMethod[] methods = super.processMethods(r);
return methods;
}
};
soapService.schemaGenerator.setElementFormDefault(Java2WSDLConstants.FORM_DEFAULT_UNQUALIFIED);
// Utils.addExcludeMethods(soapService.excludeMethods);
// soapService.schemaGenerator.setExcludeMethods(soapService.excludeMethods);
Parameter parameter = new Parameter(Constants.SERVICE_CLASS, soapService.serviceClass);
OMElement paraElement = Utils.getParameter(Constants.SERVICE_CLASS, soapService.serviceClass, false);
parameter.setParameterElement(paraElement);
axisService.setUseDefaultChains(false);
axisService.addParameter(parameter);
axisService.setName(soapService.serviceName);
axisService.setClassLoader(soapService.serviceObj.getClass().getClassLoader());
NamespaceMap map = new NamespaceMap();
map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX, Java2WSDLConstants.AXIS2_XSD);
map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX, Java2WSDLConstants.URI_2001_SCHEMA_XSD);
axisService.setNameSpacesMap(map);
axisService.setElementFormDefault(false);
axisService.addSchema(soapService.schemaGenerator.generateSchema());
axisService.setSchemaTargetNamespace(soapService.schemaGenerator.getSchemaTargetNameSpace());
axisService.setTypeTable(soapService.schemaGenerator.getTypeTable());
if (soapService.targetNamespace == null) {
soapService.targetNamespace = soapService.schemaGenerator.getSchemaTargetNameSpace();
}
if (soapService.targetNamespace != null && !"".equals(soapService.targetNamespace)) {
axisService.setTargetNamespace(soapService.targetNamespace);
}
JMethod[] method = soapService.schemaGenerator.getMethods();
PhasesInfo pinfo = axisConfiguration.getPhasesInfo();
for (int i = 0; i < method.length; i++) {
JMethod jmethod = method[i];
AxisOperation operation = axisService.getOperation(new QName(jmethod.getSimpleName()));
String mep = operation.getMessageExchangePattern();
MessageReceiver mr;
if (messageReceiverClassMap != null) {
if (messageReceiverClassMap.get(mep) != null) {
Object obj = messageReceiverClassMap.get(mep);
if (obj instanceof MessageReceiver) {
mr = (MessageReceiver) obj;
operation.setMessageReceiver(mr);
} else {
Activator.log.error("Object is not an instance of MessageReceiver," +
" thus, default MessageReceiver has been set");
mr = axisConfiguration
.getMessageReceiver(operation.getMessageExchangePattern());
operation.setMessageReceiver(mr);
}
} else {
Activator.log.error("Required MessageReceiver couldn't be found," +
" thus, default MessageReceiver has been used");
mr = axisConfiguration
.getMessageReceiver(operation.getMessageExchangePattern());
operation.setMessageReceiver(mr);
}
} else {
Activator.log.error("MessageReceiverClassMap couldn't be found," +
" thus, default MessageReceiver has been used");
mr = axisConfiguration.getMessageReceiver(operation.getMessageExchangePattern());
operation.setMessageReceiver(mr);
}
pinfo.setOperationPhases(operation);
axisService.addOperation(operation);
}
return axisService;
}