[CXF-6598] Fix problem of inout headers when unwrapped causing IndexOutOfBoundsException
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/28c213f3 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/28c213f3 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/28c213f3 Branch: refs/heads/3.0.x-fixes Commit: 28c213f33c7dc8c3f314ec6dcc81fd106c3abe98 Parents: c0b5983 Author: Daniel Kulp <dk...@apache.org> Authored: Fri Mar 24 10:02:24 2017 -0400 Committer: Daniel Kulp <dk...@apache.org> Committed: Fri Mar 24 10:51:18 2017 -0400 ---------------------------------------------------------------------- .../factory/ReflectionServiceFactoryBean.java | 54 ++++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/28c213f3/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java ---------------------------------------------------------------------- diff --git a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java index 872076e..b62e469 100644 --- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java +++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/service/factory/ReflectionServiceFactoryBean.java @@ -126,6 +126,7 @@ import org.apache.ws.commons.schema.utils.NamespaceMap; * will be filled in from the service class. If no WSDL URL is specified, the * Service will be constructed directly from the class structure. */ +//CHECKSTYLE:OFF:NCSS - This class is just huge and complex public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory.AbstractServiceFactoryBean { public static final String ENDPOINT_CLASS = "endpoint.class"; @@ -752,6 +753,15 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory } 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++) { @@ -764,12 +774,16 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory 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()); } @@ -777,6 +791,20 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory setFaultClassInfo(o, method); return true; } + private void setIndexes(MessageInfo m) { + int max = -1; + for (MessagePartInfo mpi : m.getMessageParts()) { + if (mpi.getIndex() > max && mpi.getIndex() != Integer.MAX_VALUE) { + max = mpi.getIndex(); + } + } + for (MessagePartInfo mpi : m.getMessageParts()) { + if (mpi.getIndex() == Integer.MAX_VALUE) { + max++; + mpi.setIndex(max); + } + } + } private boolean initializeParameter(OperationInfo o, Method method, int i, Class<?> paramType, Type genericType) { boolean isIn = isInParam(method, i); @@ -799,26 +827,33 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory } if (part == null && isHeader && o.isUnwrapped()) { part = ((UnwrappedOperationInfo)o).getWrappedOperation().getInput().getMessagePart(name); + boolean add = true; if (part == null) { QName name2 = this.getInParameterName(o, method, i); part = o.getInput().getMessagePart(name2); if (part != null) { + add = false; name = name2; } } if (part != null) { //header part in wsdl, need to get this mapped in to the unwrapped form - MessagePartInfo inf = o.getInput().addMessagePart(part.getName()); - inf.setTypeQName(part.getTypeQName()); - inf.setElement(part.isElement()); - inf.setElementQName(part.getElementQName()); - inf.setConcreteName(part.getConcreteName()); - inf.setXmlSchema(part.getXmlSchema()); if (paraAnnos != null) { part.setProperty(PARAM_ANNOTATION, paraAnnos); } - part = inf; - inf.setProperty(HEADER, Boolean.TRUE); + if (add) { + MessagePartInfo inf = o.getInput().addMessagePart(part.getName()); + inf.setTypeQName(part.getTypeQName()); + inf.setElement(part.isElement()); + inf.setElementQName(part.getElementQName()); + inf.setConcreteName(part.getConcreteName()); + inf.setXmlSchema(part.getXmlSchema()); + part = inf; + if (paraAnnos != null) { + part.setProperty(PARAM_ANNOTATION, paraAnnos); + } + } + part.setProperty(HEADER, Boolean.TRUE); } } if (part == null) { @@ -1497,7 +1532,6 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory MessageInfo inMsg = op.createMessage(this.getInputMessageName(op, method), MessageInfo.Type.INPUT); op.setInput(inMsg.getName().getLocalPart(), inMsg); final Annotation[][] parAnnotations = method.getParameterAnnotations(); - // CHECKSTYLE:ON final Type[] genParTypes = method.getGenericParameterTypes(); for (int j = 0; j < paramClasses.length; j++) { if (Exchange.class.equals(paramClasses[j])) { @@ -1518,9 +1552,7 @@ public class ReflectionServiceFactoryBean extends org.apache.cxf.service.factory LOG.log(Level.WARNING, "INVALID_WEBPARAM_MODE", getServiceClass().getName() + "." + method.getName()); } - // CHECKSTYLE:ON initializeParameter(part, paramClasses[j], genParTypes[j]); - //TODO:remove method param annotations part.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations); part.setProperty(PARAM_ANNOTATION, parAnnotations[j]); if (getJaxbAnnoMap(part).size() > 0) {