use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class JavaServiceDescBuilder method registerType.
private void registerType(JaxRpcTypeInfo type, TypeMapping typeMapping) throws OpenEJBException {
Class javaType;
try {
javaType = classLoader.loadClass(type.javaType);
} catch (ClassNotFoundException e) {
throw new OpenEJBException("Could not load class for JaxRpc mapping " + type.javaType);
}
// Default uses the generic Java Beans serializer/deserializer
Class serializerFactoryClass = BeanSerializerFactory.class;
Class deserializerFactoryClass = BeanDeserializerFactory.class;
switch(type.serializerType) {
case ARRAY:
serializerFactoryClass = ArraySerializerFactory.class;
deserializerFactoryClass = ArrayDeserializerFactory.class;
break;
case ENUM:
serializerFactoryClass = EnumSerializerFactory.class;
deserializerFactoryClass = EnumDeserializerFactory.class;
break;
case LIST:
serializerFactoryClass = SimpleListSerializerFactory.class;
deserializerFactoryClass = SimpleListDeserializerFactory.class;
break;
default:
if (type.simpleBaseType != null) {
Class clazz = SOAP_TYPE_MAPPING.getClassForQName(type.simpleBaseType, null, null);
if (null != clazz) {
// Built in SOAP type
serializerFactoryClass = SOAP_TYPE_MAPPING.getSerializer(clazz, type.simpleBaseType).getClass();
deserializerFactoryClass = SOAP_TYPE_MAPPING.getDeserializer(clazz, type.simpleBaseType, null).getClass();
} else {
clazz = JAXRPC_TYPE_MAPPING.getClassForQName(type.simpleBaseType, null, null);
if (null != clazz) {
// Built in XML schema type
serializerFactoryClass = JAXRPC_TYPE_MAPPING.getSerializer(clazz, type.simpleBaseType).getClass();
deserializerFactoryClass = JAXRPC_TYPE_MAPPING.getDeserializer(clazz, type.simpleBaseType, null).getClass();
}
}
}
break;
}
SerializerFactory serializerFactory = BaseSerializerFactory.createFactory(serializerFactoryClass, javaType, type.qname);
DeserializerFactory deserializerFactory = BaseDeserializerFactory.createFactory(deserializerFactoryClass, javaType, type.qname);
typeMapping.register(javaType, type.qname, serializerFactory, deserializerFactory);
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class HeavyweightOperationInfoBuilder method buildOperationInfo.
public JaxRpcOperationInfo buildOperationInfo() throws OpenEJBException {
if (operationInfo != null) {
return operationInfo;
}
operationInfo = new JaxRpcOperationInfo();
operationInfo.name = operationName;
// Binding style rpc/encoded, doc/lit, wrapped, etc.
operationInfo.bindingStyle = bindingStyle;
// Operation style one way, request response, etc/
operationInfo.operationStyle = operationStyle;
// Java method name
operationInfo.javaMethodName = methodMapping.getJavaMethodName();
//
// Map the parameters
//
mapParameters();
//
if (methodMapping.getWsdlReturnValueMapping() != null) {
mapReturnType();
}
// Validate output mapping is complete
if (outputMessage != null && bindingStyle.isWrapped()) {
Part inputPart = getWrappedPart(outputMessage);
QName wrapperName = inputPart.getElementName();
XmlElementInfo wraperElement = schemaInfo.elements.get(wrapperName);
XmlTypeInfo wrapperType = schemaInfo.types.get(wraperElement.xmlType);
Set<String> expectedOutParams = new HashSet<String>();
for (XmlElementInfo expectedOutParam : wrapperType.elements.values()) {
expectedOutParams.add(expectedOutParam.qname.getLocalPart());
}
if (!outParamNames.equals(expectedOutParams)) {
throw new OpenEJBException("Not all wrapper children were mapped to parameters or a return value for operation " + operationName);
}
} else if (null != outputMessage) {
if (!outParamNames.equals(outputMessage.getParts().keySet())) {
throw new OpenEJBException("Not all output message parts were mapped to parameters or a return value for operation " + operationName);
}
}
//
for (Fault fault : faults) {
JaxRpcFaultInfo faultInfo = mapFaults(fault);
operationInfo.faults.add(faultInfo);
}
return operationInfo;
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class HeavyweightOperationInfoBuilder method mapReturnType.
private void mapReturnType() throws OpenEJBException {
if (outputMessage == null) {
throw new OpenEJBException("No output message, but a mapping for it for operation " + operationName);
}
// verify mapped return value qname matches expected output message name
WsdlReturnValueMapping wsdlReturnValueMapping = methodMapping.getWsdlReturnValueMapping();
if (!wsdlReturnValueMapping.getWsdlMessage().equals(outputMessage.getQName())) {
throw new OpenEJBException("OutputMessage has QName: " + outputMessage.getQName() + " but mapping specifies: " + wsdlReturnValueMapping.getWsdlMessage() + " for operation " + operationName);
}
//
// Determind return type qname and xml schema type
//
QName returnQName = null;
QName returnXmlType = null;
if (wsdlReturnValueMapping.getWsdlMessagePartName() != null) {
String wsdlMessagePartName = wsdlReturnValueMapping.getWsdlMessagePartName();
if (outParamNames.contains(wsdlMessagePartName)) {
throw new OpenEJBException("output message part " + wsdlMessagePartName + " has both an INOUT or OUT mapping and a return value mapping for operation " + operationName);
}
if (bindingStyle.isWrapped()) {
Part outPart = getWrappedPart(outputMessage);
XmlElementInfo returnParticle = getWrapperChild(outPart, wsdlMessagePartName);
returnQName = new QName("", returnParticle.qname.getLocalPart());
returnXmlType = returnParticle.xmlType;
} else if (bindingStyle.isRpc()) {
Part part = outputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
}
returnQName = new QName("", part.getName());
// RPC can only use type
returnXmlType = part.getTypeName();
} else {
Part part = outputMessage.getPart(wsdlMessagePartName);
if (part == null) {
throw new OpenEJBException("No part for wsdlMessagePartName " + wsdlMessagePartName + " in output message for operation " + operationName);
}
returnQName = getPartName(part);
returnXmlType = returnQName;
}
outParamNames.add(wsdlMessagePartName);
} else {
// what does this mean????
}
operationInfo.returnQName = returnQName;
operationInfo.returnXmlType = returnXmlType;
operationInfo.returnJavaType = wsdlReturnValueMapping.getMethodReturnValue();
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class HeavyweightOperationInfoBuilder method mapParameters.
private JaxRpcParameterInfo[] mapParameters() throws OpenEJBException {
List<MethodParamPartsMapping> paramMappings = methodMapping.getMethodParamPartsMapping();
//
// Map the ParameterDesc instance in an array so they can be ordered properly
// before they are added to the the OperationDesc.
//
JaxRpcParameterInfo[] parameterInfos = new JaxRpcParameterInfo[paramMappings.size()];
for (MethodParamPartsMapping paramMapping : paramMappings) {
JaxRpcParameterInfo parameterInfo = mapParameter(paramMapping);
parameterInfos[paramMapping.getParamPosition().intValue()] = parameterInfo;
}
//
for (int i = 0; i < parameterInfos.length; i++) {
if (parameterInfos[i] == null) {
throw new OpenEJBException("There is no mapping for parameter number " + i + " for operation " + operationName);
}
}
//
if (bindingStyle.isWrapped()) {
// verify that all child elements have a parameter mapping
Part inputPart = getWrappedPart(inputMessage);
QName wrapperName = inputPart.getElementName();
XmlElementInfo wrapperElement = schemaInfo.elements.get(wrapperName);
XmlTypeInfo wrapperType = schemaInfo.types.get(wrapperElement.xmlType);
Set<String> expectedInParams = new HashSet<String>();
for (XmlElementInfo expectedInParam : wrapperType.elements.values()) {
expectedInParams.add(expectedInParam.qname.getLocalPart());
}
if (!inParamNames.equals(expectedInParams)) {
throw new OpenEJBException("Not all wrapper children were mapped for operation name" + operationName);
}
} else {
// verify all input message parts are mapped
if (!inParamNames.equals(inputMessage.getParts().keySet())) {
throw new OpenEJBException("Not all input message parts were mapped for operation name" + operationName);
}
}
return parameterInfos;
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class HeavyweightOperationInfoBuilder method mapFaults.
private JaxRpcFaultInfo mapFaults(Fault fault) throws OpenEJBException {
Message message = fault.getMessage();
ExceptionMapping exceptionMapping = mapping.getExceptionMappingMap().get(message.getQName());
if (exceptionMapping == null) {
throw new OpenEJBException("No exception mapping for fault " + fault.getName() + " and fault message " + message.getQName() + " for operation " + operationName);
}
// TODO investigate whether there are other cases in which the namespace of faultQName can be determined.
// this is weird, but I can't figure out what it should be.
// if part has an element rather than a type, it should be part.getElementName() (see below)
Part part;
if (exceptionMapping.getWsdlMessagePartName() != null) {
// According to schema documentation, this will only be set when several headerfaults use the same message.
String headerFaultMessagePartName = exceptionMapping.getWsdlMessagePartName();
part = message.getPart(headerFaultMessagePartName);
} else {
part = (Part) message.getOrderedParts(null).iterator().next();
}
// Determine the fault qname and xml schema type
QName faultQName;
XmlTypeInfo faultTypeInfo;
if (part.getElementName() != null) {
XmlElementInfo elementInfo = schemaInfo.elements.get(part.getElementName());
if (elementInfo == null) {
throw new OpenEJBException("Can not find element: " + part.getElementName() + ", known elements: " + schemaInfo.elements.keySet());
}
faultTypeInfo = schemaInfo.types.get(elementInfo.xmlType);
if (faultTypeInfo == null) {
throw new OpenEJBException("Can not find type " + elementInfo.xmlType + " for element " + elementInfo.qname + ", known types: " + schemaInfo.types.keySet());
}
faultQName = part.getElementName();
} else if (part.getTypeName() != null) {
faultTypeInfo = schemaInfo.types.get(part.getTypeName());
if (faultTypeInfo == null) {
throw new OpenEJBException("Can not find type: " + part.getTypeName() + ", known elements: " + schemaInfo.types.keySet());
}
faultQName = new QName("", fault.getName());
} else {
throw new OpenEJBException("Neither type nor element name supplied for part: " + part);
}
//
// Build the fault info
//
JaxRpcFaultInfo faultInfo = new JaxRpcFaultInfo();
faultInfo.qname = faultQName;
faultInfo.xmlType = faultTypeInfo.qname;
faultInfo.javaType = exceptionMapping.getExceptionType();
faultInfo.complex = faultTypeInfo.simpleBaseType == null;
//
if (exceptionMapping.getConstructorParameterOrder() != null) {
if (faultTypeInfo.simpleBaseType != null) {
throw new OpenEJBException("ConstructorParameterOrder can only be set for complex types, not " + faultTypeInfo.qname);
}
Map<String, XmlElementInfo> elements = new HashMap<String, XmlElementInfo>();
for (XmlElementInfo element : faultTypeInfo.elements.values()) {
elements.put(element.qname.getLocalPart(), element);
}
ConstructorParameterOrder constructorParameterOrder = exceptionMapping.getConstructorParameterOrder();
for (int i = 0; i < constructorParameterOrder.getElementName().size(); i++) {
String paramName = constructorParameterOrder.getElementName().get(i);
// get the parameter element
XmlElementInfo paramElementInfo = elements.get(paramName);
if (paramElementInfo == null) {
throw new OpenEJBException("Can not find element " + paramName + " in fault type " + faultTypeInfo.qname + ", known elements: " + elements.keySet());
}
// Java Type
String paramJavaType = null;
XmlTypeInfo paramTypeInfo = schemaInfo.types.get(paramElementInfo.xmlType);
if (paramTypeInfo != null) {
if (paramTypeInfo.anonymous) {
paramJavaType = anonymousTypes.get(paramTypeInfo.qname.getLocalPart());
} else {
paramJavaType = publicTypes.get(paramTypeInfo.qname);
}
}
// if we don't have a java type yet, check the simple types
if (paramJavaType == null) {
paramJavaType = qnameToJavaType.get(paramElementInfo.xmlType);
}
if (paramJavaType == null) {
throw new OpenEJBException("No class mapped for element type: " + paramElementInfo.xmlType);
}
JaxRpcParameterInfo parameterInfo = new JaxRpcParameterInfo();
parameterInfo.qname = paramElementInfo.qname;
parameterInfo.mode = Mode.OUT;
// todo could be a soap header
parameterInfo.soapHeader = false;
parameterInfo.xmlType = paramElementInfo.xmlType;
parameterInfo.javaType = paramJavaType;
faultInfo.parameters.add(parameterInfo);
}
}
return faultInfo;
}
Aggregations