Search in sources :

Example 1 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method initializeParameter.

protected void initializeParameter(MessagePartInfo part, Class<?> rawClass, Type type) {
    if (isHolder(rawClass, type)) {
        Type c = getHolderType(rawClass, type);
        if (c != null) {
            type = c;
            rawClass = getClass(type);
        }
    }
    if (type instanceof TypeVariable) {
        if (parameterizedTypes == null) {
            processParameterizedTypes();
        }
        TypeVariable<?> var = (TypeVariable<?>) type;
        final Object gd = var.getGenericDeclaration();
        Map<String, Class<?>> mp = parameterizedTypes.get(gd);
        if (mp != null) {
            Class<?> c = parameterizedTypes.get(gd).get(var.getName());
            if (c != null) {
                rawClass = c;
                type = c;
                part.getMessageInfo().setProperty("parameterized", Boolean.TRUE);
            }
        }
    }
    part.setProperty(GENERIC_TYPE, type);
    // and set it to type class
    if (Collection.class.isAssignableFrom(rawClass)) {
        part.setProperty(RAW_CLASS, rawClass);
    }
    part.setTypeClass(rawClass);
    if (part.getMessageInfo().getOperation().isUnwrapped() && Boolean.TRUE.equals(part.getProperty(HEADER))) {
        // header from the unwrapped operation, make sure the type is set for the
        // approriate header in the wrapped operation
        OperationInfo o = ((UnwrappedOperationInfo) part.getMessageInfo().getOperation()).getWrappedOperation();
        if (Boolean.TRUE.equals(part.getProperty(ReflectionServiceFactoryBean.MODE_OUT)) || Boolean.TRUE.equals(part.getProperty(ReflectionServiceFactoryBean.MODE_INOUT))) {
            MessagePartInfo mpi = o.getOutput().getMessagePart(part.getName());
            if (mpi != null) {
                mpi.setTypeClass(rawClass);
                mpi.setProperty(GENERIC_TYPE, type);
                if (Collection.class.isAssignableFrom(rawClass)) {
                    mpi.setProperty(RAW_CLASS, type);
                }
            }
        }
        if (!Boolean.TRUE.equals(part.getProperty(ReflectionServiceFactoryBean.MODE_OUT))) {
            MessagePartInfo mpi = o.getInput().getMessagePart(part.getName());
            if (mpi != null) {
                mpi.setTypeClass(rawClass);
                mpi.setProperty(GENERIC_TYPE, type);
                if (Collection.class.isAssignableFrom(rawClass)) {
                    mpi.setProperty(RAW_CLASS, type);
                }
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) Type(java.lang.reflect.Type) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) ParameterizedType(java.lang.reflect.ParameterizedType) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) TypeVariable(java.lang.reflect.TypeVariable) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 2 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class WSDLServiceBuilder method checkForWrapped.

public static void checkForWrapped(OperationInfo opInfo, boolean allowRefs, boolean relaxed, Level logLevel) {
    MessageInfo inputMessage = opInfo.getInput();
    MessageInfo outputMessage = opInfo.getOutput();
    boolean passedRule = true;
    // input message must exist
    if (inputMessage == null || inputMessage.size() == 0 || (inputMessage.size() > 1 && !relaxed)) {
        passedRule = false;
    }
    if (outputMessage != null && outputMessage.size() > 1) {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_1", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    SchemaCollection schemas = opInfo.getInterface().getService().getXmlSchemaCollection();
    XmlSchemaElement inputEl = null;
    XmlSchemaElement outputEl = null;
    // RULE No.2:
    // The input message part refers to a global element declaration whose
    // local name is equal to the operation name.
    MessagePartInfo inputPart = inputMessage.getMessagePartByIndex(0);
    if (!inputPart.isElement()) {
        passedRule = false;
    } else {
        QName inputElementName = inputPart.getElementQName();
        inputEl = schemas.getElementByQName(inputElementName);
        if (inputEl == null) {
            passedRule = false;
        } else if (!opInfo.getName().getLocalPart().equals(inputElementName.getLocalPart())) {
            passedRule = relaxed;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_2", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // RULE No.3:
    // The output message part refers to a global element declaration
    MessagePartInfo outputPart = null;
    if (outputMessage != null && outputMessage.size() == 1) {
        outputPart = outputMessage.getMessagePartByIndex(0);
        if (outputPart != null) {
            if (!outputPart.isElement() || schemas.getElementByQName(outputPart.getElementQName()) == null) {
                passedRule = false;
            } else {
                outputEl = schemas.getElementByQName(outputPart.getElementQName());
            }
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_3", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // RULE No.4 and No5:
    // wrapper element should be pure complex type
    // Now lets see if we have any attributes...
    // This should probably look at the restricted and substitute types too.
    OperationInfo unwrapped = new UnwrappedOperationInfo(opInfo);
    MessageInfo unwrappedInput = new MessageInfo(unwrapped, MessageInfo.Type.INPUT, inputMessage.getName());
    MessageInfo unwrappedOutput = null;
    XmlSchemaComplexType xsct = null;
    if (inputEl.getSchemaType() instanceof XmlSchemaComplexType) {
        xsct = (XmlSchemaComplexType) inputEl.getSchemaType();
        if (hasAttributes(xsct) || (inputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, inputEl.getQName().getNamespaceURI(), unwrappedInput, allowRefs)) {
            passedRule = false;
        }
    } else {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_4", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    if (outputMessage != null) {
        unwrappedOutput = new MessageInfo(unwrapped, MessageInfo.Type.OUTPUT, outputMessage.getName());
        if (outputEl != null && outputEl.getSchemaType() instanceof XmlSchemaComplexType) {
            xsct = (XmlSchemaComplexType) outputEl.getSchemaType();
            if (xsct.isAbstract()) {
                passedRule = false;
            }
            if (hasAttributes(xsct) || (outputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, outputEl.getQName().getNamespaceURI(), unwrappedOutput, allowRefs)) {
                passedRule = false;
            }
        } else {
            passedRule = false;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_5", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // we are wrappable!!
    opInfo.setUnwrappedOperation(unwrapped);
    unwrapped.setInput(opInfo.getInputName(), unwrappedInput);
    if (outputMessage != null) {
        unwrapped.setOutput(opInfo.getOutputName(), unwrappedOutput);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) Message(javax.wsdl.Message) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 3 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method createOperation.

protected OperationInfo createOperation(ServiceInfo serviceInfo, InterfaceInfo intf, Method m) {
    OperationInfo op = intf.addOperation(getOperationName(intf, m));
    op.setProperty(m.getClass().getName(), m);
    op.setProperty("action", getAction(op, m));
    final Annotation[] annotations = m.getAnnotations();
    final Annotation[][] parAnnotations = m.getParameterAnnotations();
    op.setProperty(METHOD_ANNOTATIONS, annotations);
    op.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
    boolean isrpc = isRPC(m);
    if (!isrpc && isWrapped(m)) {
        UnwrappedOperationInfo uOp = new UnwrappedOperationInfo(op);
        uOp.setProperty(METHOD_ANNOTATIONS, annotations);
        uOp.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
        op.setUnwrappedOperation(uOp);
        createMessageParts(intf, uOp, m);
        if (uOp.hasInput()) {
            MessageInfo msg = new MessageInfo(op, MessageInfo.Type.INPUT, uOp.getInput().getName());
            op.setInput(uOp.getInputName(), msg);
            createInputWrappedMessageParts(uOp, m, msg);
            for (MessagePartInfo p : uOp.getInput().getMessageParts()) {
                p.setConcreteName(p.getName());
            }
        }
        if (uOp.hasOutput()) {
            QName name = uOp.getOutput().getName();
            MessageInfo msg = new MessageInfo(op, MessageInfo.Type.OUTPUT, name);
            op.setOutput(uOp.getOutputName(), msg);
            createOutputWrappedMessageParts(uOp, m, msg);
            for (MessagePartInfo p : uOp.getOutput().getMessageParts()) {
                p.setConcreteName(p.getName());
            }
        }
    } else {
        if (isrpc) {
            op.setProperty(FORCE_TYPES, Boolean.TRUE);
        }
        createMessageParts(intf, op, m);
    }
    bindOperation(op, m);
    sendEvent(Event.INTERFACE_OPERATION_BOUND, op, m);
    return op;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 4 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class TypeClassInitializer method begin.

@Override
public void begin(MessagePartInfo part) {
    OperationInfo op = part.getMessageInfo().getOperation();
    if (!isFault && !allowWrapperOperations && op.isUnwrappedCapable() && !op.isUnwrapped()) {
        return;
    }
    QName name;
    if (part.isElement()) {
        name = part.getElementQName();
    } else {
        name = part.getTypeQName();
    }
    Mapping mapping = model.get(name);
    // String clsName = null;
    JType jType = null;
    if (mapping != null) {
        jType = mapping.getType().getTypeClass();
    }
    if (jType == null) {
        TypeAndAnnotation typeAndAnnotation = model.getJavaType(part.getTypeQName());
        if (typeAndAnnotation != null) {
            jType = typeAndAnnotation.getTypeClass();
        }
    }
    if (jType == null && part.isElement() && part.getXmlSchema() instanceof XmlSchemaElement && ((XmlSchemaElement) part.getXmlSchema()).getSchemaTypeName() == null) {
        // anonymous inner thing.....
        UnwrappedOperationInfo oInfo = (UnwrappedOperationInfo) op;
        op = oInfo.getWrappedOperation();
        if (part.getMessageInfo() == oInfo.getInput()) {
            mapping = model.get(op.getInput().getFirstMessagePart().getElementQName());
        } else {
            mapping = model.get(op.getOutput().getFirstMessagePart().getElementQName());
        }
        if (mapping != null) {
            jType = mapping.getType().getTypeClass();
            try {
                Iterator<JType> i = jType.classes();
                while (i.hasNext()) {
                    JType jt = i.next();
                    if (jt.name().equalsIgnoreCase(part.getElementQName().getLocalPart())) {
                        jType = jt;
                    }
                }
            } catch (Throwable t) {
            // ignore, JType is a type that doesn't have a classes method
            }
        }
    }
    if (jType == null) {
        throw new ServiceConstructionException(new Message("NO_JAXB_CLASSMapping", LOG, name));
    }
    Class<?> cls;
    try {
        int arrayCount = 0;
        JType rootType = jType;
        while (rootType.isArray()) {
            rootType = rootType.elementType();
            arrayCount++;
        }
        if (arrayCount == 0 && part.isElement() && part.getXmlSchema() instanceof XmlSchemaElement && ((XmlSchemaElement) part.getXmlSchema()).getMaxOccurs() > 1) {
            arrayCount = 1;
        }
        cls = getClassByName(rootType);
        // an array object on the way.
        if (arrayCount > 0) {
            int[] dimensions = new int[arrayCount];
            while (arrayCount > 0) {
                arrayCount--;
                dimensions[arrayCount] = 0;
            }
            Object emptyArray = Array.newInstance(cls, dimensions);
            cls = emptyArray.getClass();
        }
    } catch (ClassNotFoundException e) {
        throw new ServiceConstructionException(e);
    }
    part.setTypeClass(cls);
    if (isFault) {
        // need to create an Exception class for this
        try {
            part.getMessageInfo().setProperty(Class.class.getName(), createFaultClass(cls));
        } catch (Throwable t) {
        // ignore - probably no asm
        }
    }
    super.begin(part);
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Mapping(org.apache.cxf.common.jaxb.JAXBUtils.Mapping) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) TypeAndAnnotation(org.apache.cxf.common.jaxb.JAXBUtils.TypeAndAnnotation) JType(org.apache.cxf.common.jaxb.JAXBUtils.JType)

Example 5 with UnwrappedOperationInfo

use of org.apache.cxf.service.model.UnwrappedOperationInfo in project cxf by apache.

the class MAPAggregatorImpl method getActionUri.

protected String getActionUri(Message message, boolean checkMessage) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
    if (bop == null || Boolean.TRUE.equals(bop.getProperty("operation.is.synthetic"))) {
        return null;
    }
    OperationInfo op = bop.getOperationInfo();
    if (op.isUnwrapped()) {
        op = ((UnwrappedOperationInfo) op).getWrappedOperation();
    }
    String actionUri = null;
    if (checkMessage) {
        actionUri = (String) message.get(ContextUtils.ACTION);
        if (actionUri == null) {
            actionUri = (String) message.get(SoapBindingConstants.SOAP_ACTION);
        }
    }
    if (actionUri != null) {
        return actionUri;
    }
    String opNamespace = getActionBaseUri(op);
    boolean inbound = !ContextUtils.isOutbound(message);
    boolean requestor = ContextUtils.isRequestor(message);
    boolean inMsg = requestor ^ inbound;
    if (ContextUtils.isFault(message)) {
        String faultName = getFaultNameFromMessage(message);
        actionUri = getActionFromFaultMessage(op, faultName);
    } else if (inMsg) {
        String explicitAction = getActionFromInputMessage(op);
        if (StringUtils.isEmpty(explicitAction)) {
            SoapOperationInfo soi = InternalContextUtils.getSoapOperationInfo(bop);
            explicitAction = soi == null ? null : soi.getAction();
        }
        if (!StringUtils.isEmpty(explicitAction)) {
            actionUri = explicitAction;
        } else if (null == op.getInputName()) {
            actionUri = addPath(opNamespace, op.getName().getLocalPart() + "Request");
        } else {
            actionUri = addPath(opNamespace, op.getInputName());
        }
    } else {
        String explicitAction = getActionFromOutputMessage(op);
        if (explicitAction != null) {
            actionUri = explicitAction;
        } else if (null == op.getOutputName()) {
            actionUri = addPath(opNamespace, op.getName().getLocalPart() + "Response");
        } else {
            actionUri = addPath(opNamespace, op.getOutputName());
        }
    }
    return actionUri;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo)

Aggregations

OperationInfo (org.apache.cxf.service.model.OperationInfo)6 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)6 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 QName (javax.xml.namespace.QName)3 MessageInfo (org.apache.cxf.service.model.MessageInfo)3 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)3 Annotation (java.lang.annotation.Annotation)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 TypeVariable (java.lang.reflect.TypeVariable)1 WildcardType (java.lang.reflect.WildcardType)1 Message (javax.wsdl.Message)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlType (javax.xml.bind.annotation.XmlType)1 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)1 Message (org.apache.cxf.common.i18n.Message)1