use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class DocLiteralInInterceptor method getPara.
private void getPara(DepthXMLStreamReader xmlReader, DataReader<XMLStreamReader> dr, MessageContentsList parameters, Iterator<MessagePartInfo> itr, Message message) {
boolean hasNext = true;
while (itr.hasNext()) {
MessagePartInfo part = itr.next();
if (hasNext) {
hasNext = StaxUtils.toNextElement(xmlReader);
}
Object obj = null;
if (hasNext) {
QName rname = xmlReader.getName();
while (part != null && !rname.equals(part.getConcreteName())) {
if (part.getXmlSchema() instanceof XmlSchemaElement) {
// TODO - should check minOccurs=0 and throw validation exception
// thing if the part needs to be here
parameters.put(part, null);
}
if (itr.hasNext()) {
part = itr.next();
} else {
part = null;
}
}
if (part == null) {
return;
}
if (rname.equals(part.getConcreteName())) {
obj = dr.read(part, xmlReader);
}
}
parameters.put(part, obj);
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method initializeClassInfo.
/**
* set the holder generic type info into message part info
*
* @param o
* @param method
*/
protected boolean initializeClassInfo(OperationInfo o, Method method, List<String> paramOrder) {
OperationInfo origOp = o;
if (isWrapped(method)) {
if (o.getUnwrappedOperation() == null) {
// the "normal" algorithm didn't allow for unwrapping,
// but the annotations say unwrap this. We'll need to
// make it.
WSDLServiceBuilder.checkForWrapped(o, true);
}
if (o.getUnwrappedOperation() != null) {
if (o.hasInput()) {
MessageInfo input = o.getInput();
MessagePartInfo part = input.getFirstMessagePart();
part.setTypeClass(getRequestWrapper(method));
part.setProperty("REQUEST.WRAPPER.CLASSNAME", getRequestWrapperClassName(method));
part.setIndex(0);
}
if (o.hasOutput()) {
MessageInfo input = o.getOutput();
MessagePartInfo part = input.getFirstMessagePart();
part.setTypeClass(getResponseWrapper(method));
part.setProperty("RESPONSE.WRAPPER.CLASSNAME", getResponseWrapperClassName(method));
part.setIndex(0);
}
setFaultClassInfo(o, method);
o = o.getUnwrappedOperation();
} else {
LOG.warning(new Message("COULD_NOT_UNWRAP", LOG, o.getName(), method).toString());
setFaultClassInfo(o, method);
}
} else if (o.isUnwrappedCapable()) {
// remove the unwrapped operation because it will break the
// the WrapperClassOutInterceptor, and in general makes
// life more confusing
o.setUnwrappedOperation(null);
setFaultClassInfo(o, method);
}
o.setProperty(METHOD_PARAM_ANNOTATIONS, method.getParameterAnnotations());
o.setProperty(METHOD_ANNOTATIONS, method.getAnnotations());
// Set all out of band indexes to MAX_VALUE, anything left at MAX_VALUE after this is unmapped
for (MessagePartInfo mpi : o.getInput().getOutOfBandParts()) {
mpi.setIndex(Integer.MAX_VALUE);
}
if (o.hasOutput()) {
for (MessagePartInfo mpi : o.getOutput().getOutOfBandParts()) {
mpi.setIndex(Integer.MAX_VALUE);
}
}
Class<?>[] paramTypes = method.getParameterTypes();
Type[] genericTypes = method.getGenericParameterTypes();
for (int i = 0; i < paramTypes.length; i++) {
if (Exchange.class.equals(paramTypes[i])) {
continue;
}
Class<?> paramType = paramTypes[i];
Type genericType = genericTypes[i];
if (!initializeParameter(o, method, i, paramType, genericType)) {
return false;
}
}
setIndexes(o.getInput());
sendEvent(Event.OPERATIONINFO_IN_MESSAGE_SET, origOp, method, origOp.getInput());
// Initialize return type
if (o.hasOutput() && !initializeParameter(o, method, -1, method.getReturnType(), method.getGenericReturnType())) {
return false;
}
if (o.hasOutput()) {
setIndexes(o.getOutput());
}
if (origOp.hasOutput()) {
sendEvent(Event.OPERATIONINFO_OUT_MESSAGE_SET, origOp, method, origOp.getOutput());
}
setFaultClassInfo(o, method);
return true;
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method createMessageParts.
// CHECKSTYLE:OFF
protected void createMessageParts(InterfaceInfo intf, OperationInfo op, Method method) {
final Class<?>[] paramClasses = method.getParameterTypes();
// Setup the input message
op.setProperty(METHOD, method);
MessageInfo inMsg = op.createMessage(this.getInputMessageName(op, method), MessageInfo.Type.INPUT);
op.setInput(inMsg.getName().getLocalPart(), inMsg);
final Annotation[][] parAnnotations = method.getParameterAnnotations();
final Type[] genParTypes = method.getGenericParameterTypes();
for (int j = 0; j < paramClasses.length; j++) {
if (Exchange.class.equals(paramClasses[j])) {
continue;
}
if (isInParam(method, j)) {
QName q = getInParameterName(op, method, j);
QName partName = getInPartName(op, method, j);
if (!isRPC(method) && !isWrapped(method) && inMsg.getMessagePartsMap().containsKey(partName)) {
LOG.log(Level.WARNING, "INVALID_BARE_METHOD", getServiceClass() + "." + method.getName());
partName = new QName(partName.getNamespaceURI(), partName.getLocalPart() + j);
q = new QName(q.getNamespaceURI(), q.getLocalPart() + j);
}
MessagePartInfo part = inMsg.addMessagePart(partName);
if (isHolder(paramClasses[j], genParTypes[j]) && !isInOutParam(method, j)) {
LOG.log(Level.WARNING, "INVALID_WEBPARAM_MODE", getServiceClass().getName() + "." + method.getName());
}
initializeParameter(part, paramClasses[j], genParTypes[j]);
part.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
part.setProperty(PARAM_ANNOTATION, parAnnotations[j]);
if (getJaxbAnnoMap(part).size() > 0) {
op.setProperty(WRAPPERGEN_NEEDED, true);
}
if (!isWrapped(method) && !isRPC(method)) {
part.setProperty(ELEMENT_NAME, q);
}
if (isHeader(method, j)) {
part.setProperty(HEADER, Boolean.TRUE);
if (isRPC(method) || !isWrapped(method)) {
part.setElementQName(q);
} else {
part.setProperty(ELEMENT_NAME, q);
}
}
part.setIndex(j);
}
}
sendEvent(Event.OPERATIONINFO_IN_MESSAGE_SET, op, method, inMsg);
boolean hasOut = hasOutMessage(method);
if (hasOut) {
// Setup the output message
MessageInfo outMsg = op.createMessage(createOutputMessageName(op, method), MessageInfo.Type.OUTPUT);
op.setOutput(outMsg.getName().getLocalPart(), outMsg);
final Class<?> returnType = method.getReturnType();
if (!returnType.isAssignableFrom(void.class)) {
final QName q = getOutPartName(op, method, -1);
final QName q2 = getOutParameterName(op, method, -1);
MessagePartInfo part = outMsg.addMessagePart(q);
initializeParameter(part, method.getReturnType(), method.getGenericReturnType());
if (!isRPC(method) && !isWrapped(method)) {
part.setProperty(ELEMENT_NAME, q2);
}
final Annotation[] annotations = method.getAnnotations();
part.setProperty(METHOD_ANNOTATIONS, annotations);
part.setProperty(PARAM_ANNOTATION, annotations);
if (isHeader(method, -1)) {
part.setProperty(HEADER, Boolean.TRUE);
if (isRPC(method) || !isWrapped(method)) {
part.setElementQName(q2);
} else {
part.setProperty(ELEMENT_NAME, q2);
}
}
part.setIndex(0);
}
for (int j = 0; j < paramClasses.length; j++) {
if (Exchange.class.equals(paramClasses[j])) {
continue;
}
if (isOutParam(method, j)) {
if (outMsg == null) {
outMsg = op.createMessage(createOutputMessageName(op, method), MessageInfo.Type.OUTPUT);
}
QName q = getOutPartName(op, method, j);
QName q2 = getOutParameterName(op, method, j);
if (isInParam(method, j)) {
MessagePartInfo mpi = op.getInput().getMessagePartByIndex(j);
q = mpi.getName();
q2 = (QName) mpi.getProperty(ELEMENT_NAME);
if (q2 == null) {
q2 = mpi.getElementQName();
}
}
MessagePartInfo part = outMsg.addMessagePart(q);
part.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
part.setProperty(PARAM_ANNOTATION, parAnnotations[j]);
initializeParameter(part, paramClasses[j], genParTypes[j]);
part.setIndex(j + 1);
if (!isRPC(method) && !isWrapped(method)) {
part.setProperty(ELEMENT_NAME, q2);
}
if (isInParam(method, j)) {
part.setProperty(MODE_INOUT, Boolean.TRUE);
}
if (isHeader(method, j)) {
part.setProperty(HEADER, Boolean.TRUE);
if (isRPC(method) || !isWrapped(method)) {
part.setElementQName(q2);
} else {
part.setProperty(ELEMENT_NAME, q2);
}
}
}
}
sendEvent(Event.OPERATIONINFO_OUT_MESSAGE_SET, op, method, outMsg);
}
// setting the parameterOrder that
// allows preservation of method signatures
// when doing java->wsdl->java
setParameterOrder(method, paramClasses, op);
if (hasOut) {
// Faults are only valid if not a one-way operation
initializeFaults(intf, op, method);
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method createWrappedMessageSchema.
private void createWrappedMessageSchema(ServiceInfo serviceInfo, AbstractMessageContainer wrappedMessage, AbstractMessageContainer unwrappedMessage, SchemaInfo info, QName wrapperName) {
XmlSchema schema = info.getSchema();
// the cached schema will be no good
info.setElement(null);
XmlSchemaElement el = new XmlSchemaElement(schema, true);
el.setName(wrapperName.getLocalPart());
wrappedMessage.getFirstMessagePart().setXmlSchema(el);
boolean anonymousType = isAnonymousWrapperTypes();
XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, /*CXF-6783: don't create anonymous top-level types*/
!anonymousType);
if (!anonymousType) {
ct.setName(wrapperName.getLocalPart());
el.setSchemaTypeName(wrapperName);
}
el.setSchemaType(ct);
XmlSchemaSequence seq = new XmlSchemaSequence();
ct.setParticle(seq);
for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
el = new XmlSchemaElement(schema, Boolean.TRUE.equals(mpi.getProperty(HEADER)));
Map<Class<?>, Boolean> jaxbAnnoMap = getJaxbAnnoMap(mpi);
if (mpi.isElement()) {
addImport(schema, mpi.getElementQName().getNamespaceURI());
XmlSchemaUtils.setElementRefName(el, mpi.getElementQName());
} else {
// We hope that we can't have parts that different only in namespace.
el.setName(mpi.getName().getLocalPart());
if (mpi.getTypeQName() != null && !jaxbAnnoMap.containsKey(XmlList.class)) {
el.setSchemaTypeName(mpi.getTypeQName());
addImport(schema, mpi.getTypeQName().getNamespaceURI());
}
el.setSchemaType((XmlSchemaType) mpi.getXmlSchema());
if (schema.getElementFormDefault().equals(XmlSchemaForm.UNQUALIFIED)) {
mpi.setConcreteName(new QName(null, mpi.getName().getLocalPart()));
} else {
mpi.setConcreteName(mpi.getName());
}
}
if (!Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
boolean wasType = !mpi.isElement();
if (wasType) {
QName concreteName = mpi.getConcreteName();
mpi.setElement(true);
mpi.setElementQName(el.getQName());
mpi.setConcreteName(concreteName);
}
addMimeType(el, getMethodParameterAnnotations(mpi));
Annotation[] methodAnnotations = getMethodAnnotations(mpi);
if (methodAnnotations != null) {
addMimeType(el, methodAnnotations);
}
long min = getWrapperPartMinOccurs(mpi);
long max = getWrapperPartMaxOccurs(mpi);
boolean nillable = isWrapperPartNillable(mpi);
Boolean qualified = isWrapperPartQualified(mpi);
if (qualified == null) {
qualified = this.isQualifyWrapperSchema();
}
if (qualified && StringUtils.isEmpty(mpi.getConcreteName().getNamespaceURI())) {
QName newName = new QName(wrapperName.getNamespaceURI(), mpi.getConcreteName().getLocalPart());
mpi.setElement(true);
mpi.setElementQName(newName);
mpi.setConcreteName(newName);
el.setName(newName.getLocalPart());
el.setForm(XmlSchemaForm.QUALIFIED);
}
if (Collection.class.isAssignableFrom(mpi.getTypeClass()) && mpi.getTypeClass().isInterface()) {
Type type = (Type) mpi.getProperty(GENERIC_TYPE);
if (!(type instanceof java.lang.reflect.ParameterizedType) && el.getSchemaTypeName() == null && el.getSchemaType() == null) {
max = Long.MAX_VALUE;
el.setSchemaTypeName(Constants.XSD_ANYTYPE);
}
}
el.setMinOccurs(min);
el.setMaxOccurs(max);
if (nillable) {
el.setNillable(nillable);
}
seq.getItems().add(el);
mpi.setXmlSchema(el);
}
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
el.setName(qn.getLocalPart());
SchemaInfo headerSchemaInfo = getOrCreateSchema(serviceInfo, qn.getNamespaceURI(), getQualifyWrapperSchema());
if (!isExistSchemaElement(headerSchemaInfo.getSchema(), qn)) {
headerSchemaInfo.getSchema().getItems().add(el);
}
}
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method initializeWrappedSchema.
protected void initializeWrappedSchema(ServiceInfo serviceInfo) {
for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
if (op.getUnwrappedOperation() != null) {
if (op.hasInput()) {
MessagePartInfo fmpi = op.getInput().getFirstMessagePart();
if (fmpi.getTypeClass() == null) {
QName wrapperBeanName = fmpi.getElementQName();
XmlSchemaElement e = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
e = s.getElementByQName(wrapperBeanName);
if (e != null) {
fmpi.setXmlSchema(e);
break;
}
}
if (e == null) {
createWrappedSchema(serviceInfo, op.getInput(), op.getUnwrappedOperation().getInput(), wrapperBeanName);
}
}
for (MessagePartInfo mpi : op.getInput().getMessageParts()) {
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
mpi.setElement(true);
mpi.setElementQName(qn);
checkForElement(serviceInfo, mpi);
}
}
}
if (op.hasOutput()) {
MessagePartInfo fmpi = op.getOutput().getFirstMessagePart();
if (fmpi.getTypeClass() == null) {
QName wrapperBeanName = fmpi.getElementQName();
XmlSchemaElement e = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
e = s.getElementByQName(wrapperBeanName);
if (e != null) {
break;
}
}
if (e == null) {
createWrappedSchema(serviceInfo, op.getOutput(), op.getUnwrappedOperation().getOutput(), wrapperBeanName);
}
}
for (MessagePartInfo mpi : op.getOutput().getMessageParts()) {
if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
mpi.setElement(true);
mpi.setElementQName(qn);
checkForElement(serviceInfo, mpi);
}
}
}
}
}
}
Aggregations