Java Code Examples for org.apache.cxf.service.model.MessagePartInfo#getProperty()

The following examples show how to use org.apache.cxf.service.model.MessagePartInfo#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXBEncoderDecoder.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Object createSet(MessagePartInfo part, List<Object> ret) {
    Type genericType = (Type)part.getProperty("generic.type");
    Class<?> tp2 = (Class<?>)((ParameterizedType)genericType).getRawType();
    if (tp2.isInterface()) {
        return new HashSet<>(ret);
    }
    Collection<Object> c;
    try {
        c = CastUtils.cast((Collection<?>)tp2.newInstance());
    } catch (Exception e) {
        c = new HashSet<>();
    }

    c.addAll(ret);
    return c;
}
 
Example 2
Source File: JAXBEncoderDecoder.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static boolean isSet(MessagePartInfo part) {
    if (part.getTypeClass().isArray() && !part.getTypeClass().getComponentType().isPrimitive()) {
        // && Collection.class.isAssignableFrom(part.getTypeClass())) {
        // it's List Para
        //
        Type genericType = (Type)part.getProperty("generic.type");

        if (genericType instanceof ParameterizedType) {
            Type tp2 = ((ParameterizedType)genericType).getRawType();
            if (tp2 instanceof Class) {
                return Set.class.isAssignableFrom((Class<?>)tp2);
            }
        }
    }
    return false;
}
 
Example 3
Source File: JAXBEncoderDecoder.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static boolean isList(MessagePartInfo part) {
    if (part.getTypeClass().isArray() && !part.getTypeClass().getComponentType().isPrimitive()) {
        // && Collection.class.isAssignableFrom(part.getTypeClass())) {
        // it's List Para
        //
        Type genericType = (Type)part.getProperty("generic.type");

        if (genericType instanceof ParameterizedType) {
            Type tp2 = ((ParameterizedType)genericType).getRawType();
            if (tp2 instanceof Class) {
                return List.class.isAssignableFrom((Class<?>)tp2);
            }
        }
    }
    return false;
}
 
Example 4
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Boolean isWrapperPartQualified(MessagePartInfo mpi) {
    Annotation[] annotations = (Annotation[])mpi.getProperty("parameter.annotations");
    if (annotations != null) {
        for (Annotation an : annotations) {
            String tns = null;
            if (an instanceof WebParam) {
                tns = ((WebParam)an).targetNamespace();
            } else if (an instanceof WebResult) {
                tns = ((WebResult)an).targetNamespace();
            }
            if (tns != null && !StringUtils.isEmpty(tns)) {
                return Boolean.TRUE;
            }
        }
    }
    return null;
}
 
Example 5
Source File: WrapperClassOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private synchronized WrapperHelper getWrapperHelper(Message message,
                                       MessageInfo messageInfo,
                                       MessageInfo wrappedMessageInfo,
                                       Class<?> wrapClass,
                                       MessagePartInfo messagePartInfo) {
    WrapperHelper helper = messagePartInfo.getProperty("WRAPPER_CLASS", WrapperHelper.class);
    if (helper == null) {
        Service service = ServiceModelUtil.getService(message.getExchange());
        DataBinding dataBinding = service.getDataBinding();
        if (dataBinding instanceof WrapperCapableDatabinding) {
            helper = createWrapperHelper((WrapperCapableDatabinding)dataBinding,
                                         messageInfo, wrappedMessageInfo, wrapClass);
            messagePartInfo.setProperty("WRAPPER_CLASS", helper);
        }
    }
    return helper;
}
 
Example 6
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Annotation[] getMethodParameterAnnotations(final MessagePartInfo mpi) {
    Annotation[][] paramAnno = (Annotation[][])mpi.getProperty(METHOD_PARAM_ANNOTATIONS);
    int index = mpi.getIndex();
    if (paramAnno != null && index < paramAnno.length && index >= 0) {
        return paramAnno[index];
    }
    return null;
}
 
Example 7
Source File: XMLStreamDataReader.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object read(MessagePartInfo part, XMLStreamReader input) {
    try {
        AegisType type = part.getProperty("org.apache.cxf.aegis.outerType", AegisType.class);
        if (type == null) {
            type = databinding.getType(part);
            return reader.read(input, type);
        }
        ArrayType arrayType = (ArrayType) type;
        return reader.readFlatArray(input, arrayType, part.getConcreteName());

    } catch (Exception e) {
        throw new Fault(e);
    }
}
 
Example 8
Source File: JAXBDataBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected final boolean honorJAXBAnnotations(MessagePartInfo part) {
    if (part == null) {
        return false;
    }
    if (!part.isElement()) {
        //RPC-Lit always needs to look for these
        return true;
    }
    //certain cases that use XmlJavaTypeAdapters will require this and the
    //JAXBSchemaInitializer will set this.
    Boolean b = (Boolean)part.getProperty("honor.jaxb.annotations");
    return b != null && b;
}
 
Example 9
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void checkForJAXBAnnotations(MessagePartInfo mpi, SchemaCollection schemaCollection, String ns) {
    Annotation[] anns = (Annotation[])mpi.getProperty("parameter.annotations");
    JAXBContextProxy ctx = JAXBUtils.createJAXBContextProxy(context, schemaCollection, ns);
    XmlJavaTypeAdapter jta = JAXBSchemaInitializer.findFromTypeAdapter(ctx, mpi.getTypeClass(), anns);
    if (jta != null) {
        JAXBBeanInfo jtaBeanInfo = JAXBSchemaInitializer.findFromTypeAdapter(ctx, jta.value());
        JAXBBeanInfo beanInfo = JAXBSchemaInitializer.getBeanInfo(ctx, mpi.getTypeClass());
        if (jtaBeanInfo != beanInfo) {
            mpi.setProperty("parameter.annotations", anns);
            mpi.setProperty("honor.jaxb.annotations", Boolean.TRUE);
        }
    }
}
 
Example 10
Source File: WrapperClassGenerator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Annotation[] getMethodParameterAnnotations(final MessagePartInfo mpi) {
    Annotation[] a = (Annotation[])mpi.getProperty(ReflectionServiceFactoryBean.PARAM_ANNOTATION);
    if (a != null) {
        return a;
    }

    Annotation[][] paramAnno = (Annotation[][])mpi
        .getProperty(ReflectionServiceFactoryBean.METHOD_PARAM_ANNOTATIONS);
    int index = mpi.getIndex();
    if (paramAnno != null && index < paramAnno.length && index >= 0) {
        return paramAnno[index];
    }
    return null;
}
 
Example 11
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isRefElement(MessagePartInfo outputPart, QName outElement) {
    OperationInfo wrappedOp = outputPart.getMessageInfo().getOperation().getUnwrappedOperation();
    MessagePartInfo mpart = wrappedOp.getOutput().getMessagePart(outElement);
    if (mpart == null) {
        return false;
    }
    return mpart.getProperty("isRefElement") != null;
}
 
Example 12
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Long getWrapperPartMinOccurs(MessagePartInfo mpi) {
    Annotation[] a = (Annotation[])mpi.getProperty(ReflectionServiceFactoryBean.PARAM_ANNOTATION);
    if (a != null) {
        for (Annotation a2 : a) {
            if (a2 instanceof XmlElement) {
                XmlElement e = (XmlElement)a2;
                if (e.required()) {
                    return 1L;
                }
            }
        }
    }
    return null;
}
 
Example 13
Source File: DefaultServiceConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Long getWrapperPartMinOccurs(MessagePartInfo mpi) {
    String miString = (String)mpi.getProperty("minOccurs");
    if (miString != null) {
        return Long.valueOf(miString, 10);
    }
    // If no explicit spec and not a primitive type (i.e. mappable to null)
    // set to 0.
    if (mpi.getTypeClass() != null && !mpi.getTypeClass().isPrimitive()) {
        return Long.valueOf(0);
    }
    return null;
}
 
Example 14
Source File: WrapperClassGenerator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void generateMessagePart(ClassWriter cw, MessagePartInfo mpi,
                                 Method method, String className) {
    if (Boolean.TRUE.equals(mpi.getProperty(ReflectionServiceFactoryBean.HEADER))) {
        return;
    }
    String classFileName = periodToSlashes(className);
    String name = mpi.getName().getLocalPart();
    Class<?> clz = mpi.getTypeClass();
    Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS);
    if (obj != null) {
        clz = (Class<?>)obj;
    }
    Type genericType = (Type)mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE);
    if (genericType instanceof ParameterizedType) {
        ParameterizedType tp = (ParameterizedType)genericType;
        if (tp.getRawType() instanceof Class
            && Holder.class.isAssignableFrom((Class<?>)tp.getRawType())) {
            genericType = tp.getActualTypeArguments()[0];
        }
    }
    String classCode = getClassCode(clz);
    String fieldDescriptor = null;

    if (genericType instanceof ParameterizedType) {
        if (Collection.class.isAssignableFrom(clz) || clz.isArray()) {
            ParameterizedType ptype = (ParameterizedType)genericType;

            java.lang.reflect.Type[] types = ptype.getActualTypeArguments();
            if (types.length > 0) {
                if (types[0] instanceof Class) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof GenericArrayType) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (Collection.class.isAssignableFrom(clz)) {
                    fieldDescriptor = getClassCode(genericType);
                } else if (types[0] instanceof ParameterizedType) {
                    classCode = getClassCode(((ParameterizedType)types[0]).getRawType());
                    fieldDescriptor = getClassCode(genericType);
                }
            }
        } else {
            classCode = getClassCode(((ParameterizedType)genericType).getRawType());
            fieldDescriptor = getClassCode(genericType);
        }
    }
    String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name;

    FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE,
                                    fieldName,
                                    classCode,
                                    fieldDescriptor,
                                    null);



    List<Annotation> jaxbAnnos = getJaxbAnnos(mpi);
    if (!addJAXBAnnotations(fv, jaxbAnnos, name)) {
        AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
        av0.visit("name", name);
        if (Boolean.TRUE.equals(factory.isWrapperPartQualified(mpi))) {
            av0.visit("namespace", mpi.getConcreteName().getNamespaceURI());
        }
        if (factory.isWrapperPartNillable(mpi)) {
            av0.visit("nillable", Boolean.TRUE);
        }
        if (factory.getWrapperPartMinOccurs(mpi) == 1) {
            av0.visit("required", Boolean.TRUE);
        }
        av0.visitEnd();
    }
    fv.visitEnd();

    String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER);
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode,
                                      fieldDescriptor == null ? null : "()" + fieldDescriptor,
                                      null);
    mv.visitCode();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
    mv.visitInsn(getType(classCode).getOpcode(Opcodes.IRETURN));
    mv.visitMaxs(0, 0);
    mv.visitEnd();

    methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER);
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V",
                        fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null);
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    ASMType setType = getType(classCode);
    mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

}
 
Example 15
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
            XmlSchema schema = 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;
                }
            }

            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;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            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++;
        }
    }
 
Example 16
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Annotation[] getMethodAnnotations(final MessagePartInfo mpi) {
    return (Annotation[])mpi.getProperty(METHOD_ANNOTATIONS);
}
 
Example 17
Source File: DefaultServiceConfiguration.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Boolean isWrapperPartNillable(MessagePartInfo mpi) {
    return (Boolean)mpi.getProperty("nillable");
}
 
Example 18
Source File: WrapperClassOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();

    MessageInfo messageInfo = message.get(MessageInfo.class);
    if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
        return;
    }

    BindingOperationInfo newbop = bop.getWrappedOperation();
    MessageInfo wrappedMsgInfo;
    if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
        wrappedMsgInfo = newbop.getInput().getMessageInfo();
    } else {
        wrappedMsgInfo = newbop.getOutput().getMessageInfo();
    }

    Class<?> wrapped = null;
    if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
        wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
    }

    if (wrapped != null) {
        MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
        if (helper == null) {
            helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
        }
        if (helper == null) {
            return;
        }

        try {
            MessageContentsList newObjs = new MessageContentsList();
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)
                && helper instanceof AbstractWrapperHelper) {
                ((AbstractWrapperHelper)helper).setValidate(true);
            }
            Object o2 = helper.createWrapperObject(objs);
            newObjs.put(firstMessagePart, o2);

            for (MessagePartInfo p : messageInfo.getMessageParts()) {
                if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
                    MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
                    if (objs.hasValue(p)) {
                        newObjs.put(mpi, objs.get(p));
                    }
                }
            }

            message.setContent(List.class, newObjs);
        } catch (Fault f) {
            throw f;
        } catch (Exception e) {
            throw new Fault(e);
        }

        // we've now wrapped the object, so use the wrapped binding op
        ex.put(BindingOperationInfo.class, newbop);

        if (messageInfo == bop.getOperationInfo().getInput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
            message.put(BindingMessageInfo.class, newbop.getInput());
        } else if (messageInfo == bop.getOperationInfo().getOutput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, newbop.getOutput());
        }
    }
}
 
Example 19
Source File: JAXBEncoderDecoder.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static List<Object> createList(MessagePartInfo part) {
    Type genericType = (Type)part.getProperty("generic.type");
    return createList(genericType);
}
 
Example 20
Source File: AegisDatabinding.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container,
                                 int partType, Set<AegisType> deps) {
    if (container == null) {
        return;
    }
    for (MessagePartInfo part : container.getMessageParts()) {
        AegisType type = getParameterType(s, serviceTM, part, partType);

        if (part.getXmlSchema() == null) {
            // schema hasn't been filled in yet
            if (type.isAbstract()) {
                part.setTypeQName(type.getSchemaType());
            } else {
                part.setElementQName(type.getSchemaType());
            }
        }

        Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);

        long miValue = -1;
        if (type.hasMinOccurs()) {
            miValue = type.getMinOccurs();
        }
        Integer i = AnnotationReader.getMinOccurs(anns);
        if (i != null) {
            miValue = i;
        }
        if (miValue > 0) {
            part.setProperty("minOccurs", Long.toString(miValue));
        }


        // The concept of type.isNillable is questionable: how are types nillable?
        // However, this if at least allow .aegis.xml files to get control.
        if (part.getProperty("nillable") == null) {
            boolean isNil = type.isNillable();
            Boolean b = AnnotationReader.isNillable(anns);
            if (b != null || (miValue != 0 && isNil)) {
                part.setProperty("nillable", b == null ? isNil : b);
            }
            /*
            if (miValue == -1 && (b == null ? isNil : b)) {
                part.setProperty("minOccurs", "1");
            }
            */
        }
        if (type.hasMaxOccurs()) {
            String moValue;
            long mo = type.getMaxOccurs();
            if (mo != Long.MAX_VALUE) {
                moValue = Long.toString(mo);
                part.setProperty("maxOccurs", moValue);
            }
        }


        part2Type.put(part, type);

        // QName elName = getSuggestedName(service, op, param)
        deps.add(type);
        type.getTypeMapping().register(type);
        addDependencies(deps, type);
    }
}