use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class ReflectionServiceFactoryBean method createBareMessage.
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {
MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();
final List<MessagePartInfo> messageParts = message.getMessageParts();
if (messageParts.isEmpty()) {
return;
}
Method method = (Method) opInfo.getProperty(METHOD);
int paraNumber = 0;
for (MessagePartInfo mpi : messageParts) {
SchemaInfo schemaInfo = null;
QName qname = (QName) mpi.getProperty(ELEMENT_NAME);
if (messageParts.size() == 1 && qname == null) {
qname = !isOut ? getInParameterName(opInfo, method, -1) : getOutParameterName(opInfo, method, -1);
if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
qname = isOut ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname.getNamespaceURI(), method.getName());
}
} else if (isOut && messageParts.size() > 1 && qname == null) {
while (!isOutParam(method, paraNumber)) {
paraNumber++;
}
qname = getOutParameterName(opInfo, method, paraNumber);
} else if (qname == null) {
qname = getInParameterName(opInfo, method, paraNumber);
}
for (SchemaInfo s : serviceInfo.getSchemas()) {
if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
schemaInfo = s;
break;
}
}
final XmlSchema schema;
if (schemaInfo == null) {
schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
schema = schemaInfo.getSchema();
} else {
schema = schemaInfo.getSchema();
if (schema != null && schema.getElementByName(qname) != null) {
mpi.setElement(true);
mpi.setElementQName(qname);
mpi.setXmlSchema(schema.getElementByName(qname));
paraNumber++;
continue;
}
}
// cached element is now invalid
schemaInfo.setElement(null);
XmlSchemaElement el = new XmlSchemaElement(schema, true);
el.setName(qname.getLocalPart());
el.setNillable(true);
if (mpi.isElement()) {
XmlSchemaElement oldEl = (XmlSchemaElement) mpi.getXmlSchema();
if (null != oldEl && !oldEl.getQName().equals(qname)) {
el.setSchemaTypeName(oldEl.getSchemaTypeName());
el.setSchemaType(oldEl.getSchemaType());
if (oldEl.getSchemaTypeName() != null) {
addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
}
}
mpi.setElement(true);
mpi.setXmlSchema(el);
mpi.setElementQName(qname);
mpi.setConcreteName(qname);
continue;
}
if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG, method.getDeclaringClass().getName(), method.getName(), mpi.getName()));
}
if (mpi.getTypeQName() != null) {
el.setSchemaTypeName(mpi.getTypeQName());
} else {
el.setSchemaType((XmlSchemaType) mpi.getXmlSchema());
}
mpi.setXmlSchema(el);
mpi.setConcreteName(qname);
if (mpi.getTypeQName() != null) {
addImport(schema, mpi.getTypeQName().getNamespaceURI());
}
mpi.setElement(true);
mpi.setElementQName(qname);
paraNumber++;
}
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class WSDLServiceFactory method create.
public Service create() {
List<ServiceInfo> services;
if (serviceName == null) {
try {
WSDLServiceBuilder builder = new WSDLServiceBuilder(getBus());
builder.setAllowElementRefs(allowRefs);
services = builder.buildServices(definition);
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SERVICE_EXC", LOG));
}
// @@TODO - this isn't good, need to return all the services
serviceName = services.get(0).getName();
// get all the service info's that match that first one.
Iterator<ServiceInfo> it = services.iterator();
while (it.hasNext()) {
if (!it.next().getName().equals(serviceName)) {
it.remove();
}
}
} else {
javax.wsdl.Service wsdlService = definition.getService(serviceName);
if (wsdlService == null) {
if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName)) && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName)) && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
try {
Map<QName, PortType> portTypes = CastUtils.cast(definition.getAllPortTypes());
String existPortName = null;
PortType portType = null;
for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) {
existPortName = entry.getKey().getLocalPart();
if (serviceName.getLocalPart().contains(existPortName)) {
portType = entry.getValue();
break;
}
}
WSDLFactory factory = WSDLFactory.newInstance();
ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
Binding binding = PartialWSDLProcessor.doAppendBinding(definition, existPortName, portType, extReg);
definition.addBinding(binding);
wsdlService = PartialWSDLProcessor.doAppendService(definition, existPortName, extReg, binding);
definition.addService(wsdlService);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
} else {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
}
try {
services = new WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService, endpointName);
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SUCH_ENDPOINT_EXC", LOG, endpointName));
}
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
}
ServiceImpl service = new ServiceImpl(services);
setService(service);
return service;
}
Aggregations