Search in sources :

Example 71 with MessagePartInfo

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

the class RequestWrapper method setOperationInfo.

@Override
public void setOperationInfo(final OperationInfo op) {
    super.setOperationInfo(op);
    MessagePartInfo mpi = op.getInput().getFirstMessagePart();
    setName(mpi.getElementQName());
    setClassName((String) mpi.getProperty("REQUEST.WRAPPER.CLASSNAME"));
}
Also used : MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 72 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project fabric8 by jboss-fuse.

the class ManagedApi method getJSONSchema.

@ManagedOperation(description = "get the JSON schema from a given endpoint", currencyTimeLimit = 60)
public String getJSONSchema() {
    String ret = "";
    if (!isWSDL()) {
        Set<Class<?>> resourceTypes = getRESTResourceTypes();
        if (resourceTypes != null) {
            try {
                ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol();
                for (Class<?> cls : resourceTypes) {
                    if (JsonSchemaLookup.getSingleton().getSchemaForClass(cls).length() > 0) {
                        ret = ret + getIndention(2) + "\"" + cls.getName() + "\" : " + getEol();
                        ret = ret + rollbackEol(reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(cls), 3)) + "," + getEol();
                    }
                }
                ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturn(1);
                ret = ret + getEndIndentionWithReturn(0);
            } catch (Throwable e) {
                LOG.log(Level.WARNING, "getJSONSchema failed.", e);
            }
        }
    } else {
        try {
            for (ServiceInfo serviceInfo : endpoint.getService().getServiceInfos()) {
                for (BindingInfo bindingInfo : serviceInfo.getBindings()) {
                    ret = ret + getBeginIndentionWithReturn(1) + "\"operations\" : " + getBeginIndentionWithReturn(0);
                    for (BindingOperationInfo boi : bindingInfo.getOperations()) {
                        ret = ret + getIndention(2) + "\"" + boi.getOperationInfo().getName().getLocalPart() + "\" " + " : " + getBeginIndentionWithReturn(3);
                        if (boi.getInput() != null && boi.getInput().getMessageParts() != null) {
                            ret = ret + "\"input\" : " + getBeginIndentionWithReturn(4) + "\"type\" : \"" + boi.getOperationInfo().getInput().getName().getLocalPart() + "\"" + getEndIndentionWithReturn(3) + "," + getEol();
                        }
                        if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null) {
                            ret = ret + getIndention(3) + "\"output\" : " + getBeginIndentionWithReturn(4) + "\"type\" : \"" + boi.getOperationInfo().getOutput().getName().getLocalPart() + "\"" + getEndIndentionWithReturn(3);
                        }
                        ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturn(2) + "," + getEol();
                    }
                    if (ret.length() > 0) {
                        ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturn(1) + ",";
                    }
                    Set<String> addedType = new HashSet<String>();
                    ret = ret + getEol() + getIndention(1) + "\"definitions\" : " + getBeginIndentionWithReturn(0);
                    for (BindingOperationInfo boi : bindingInfo.getOperations()) {
                        if (boi.getInput() != null && boi.getInput().getMessageParts() != null && !addedType.contains(boi.getOperationInfo().getInput().getName().getLocalPart())) {
                            ret = ret + getIndention(2) + "\"" + boi.getOperationInfo().getInput().getName().getLocalPart() + "\" : " + getBeginIndentionWithReturnForList(0);
                            for (MessagePartInfo mpi : boi.getInput().getMessageParts()) {
                                Class<?> partClass = mpi.getTypeClass();
                                if (partClass != null) {
                                    ret = ret + rollbackEol(reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3)) + "," + getEol();
                                }
                            }
                            ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturnForList(2) + "," + getEol();
                            addedType.add(boi.getOperationInfo().getInput().getName().getLocalPart());
                        }
                        if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null && !addedType.contains(boi.getOperationInfo().getOutput().getName().getLocalPart())) {
                            ret = ret + getIndention(2) + "\"" + boi.getOperationInfo().getOutput().getName().getLocalPart() + "\" : " + getBeginIndentionWithReturnForList(0);
                            for (MessagePartInfo mpi : boi.getOutput().getMessageParts()) {
                                Class<?> partClass = mpi.getTypeClass();
                                if (partClass != null) {
                                    ret = ret + rollbackEol(reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3)) + "," + getEol();
                                }
                            }
                            ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturnForList(2) + "," + getEol();
                            addedType.add(boi.getOperationInfo().getOutput().getName().getLocalPart());
                        }
                    }
                    if (ret.length() > 0) {
                        ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturn(1);
                    }
                    if (ret.length() > 0) {
                        ret = rollbackColon(ret) + getEndIndentionWithReturn(0);
                    }
                }
            }
        } catch (Throwable e) {
            LOG.log(Level.WARNING, "getJSONSchema failed.", e);
        }
    }
    return ret;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) HashSet(java.util.HashSet) ManagedOperation(org.apache.cxf.management.annotation.ManagedOperation)

Example 73 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project fabric8 by jboss-fuse.

the class ManagedApi method getJSONSchemaForOperation.

@ManagedOperation(description = "get the JSON schema from a given soap endpoint for a given operation", currencyTimeLimit = 60)
public String getJSONSchemaForOperation(String operationName) {
    if (!isWSDL()) {
        return null;
    }
    String ret = "";
    for (ServiceInfo serviceInfo : endpoint.getService().getServiceInfos()) {
        for (BindingInfo bindingInfo : serviceInfo.getBindings()) {
            for (BindingOperationInfo boi : bindingInfo.getOperations()) {
                if (operationName.equals(boi.getOperationInfo().getName().getLocalPart())) {
                    ret = ret + getBeginIndentionWithReturn(1) + "\"" + boi.getOperationInfo().getName().getLocalPart() + "\" " + " : " + getBeginIndentionWithReturn(2);
                    if (boi.getInput() != null && boi.getInput().getMessageParts() != null) {
                        ret = ret + "\"input\" : " + getBeginIndentionWithReturn(4) + "\"type\" : \"" + boi.getOperationInfo().getInput().getName().getLocalPart() + "\"" + getEndIndentionWithReturn(2) + "," + getEol();
                    }
                    if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null) {
                        ret = ret + getIndention(2) + "\"output\" : " + getBeginIndentionWithReturn(4) + "\"type\" : \"" + boi.getOperationInfo().getOutput().getName().getLocalPart() + "\"" + getEndIndentionWithReturn(2);
                    }
                    ret = rollbackColon(ret) + getEndIndentionWithReturn(1) + ",";
                    ret = ret + getEol() + getIndention(1) + "\"definitions\" : " + getBeginIndentionWithReturn(2);
                    if (boi.getInput() != null && boi.getInput().getMessageParts() != null) {
                        ret = ret + "\"" + boi.getOperationInfo().getInput().getName().getLocalPart() + "\" : " + getBeginIndentionWithReturnForList(0);
                        for (MessagePartInfo mpi : boi.getInput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null) {
                                ret = ret + rollbackEol(reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3)) + "," + getEol();
                            }
                        }
                        ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturnForList(2) + "," + getEol();
                    }
                    if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null) {
                        ret = ret + getIndention(2) + "\"" + boi.getOperationInfo().getOutput().getName().getLocalPart() + "\" : " + getBeginIndentionWithReturnForList(0);
                        for (MessagePartInfo mpi : boi.getOutput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null) {
                                ret = ret + rollbackEol(reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3)) + "," + getEol();
                            }
                        }
                        ret = rollbackColon(rollbackEol(ret)) + getEndIndentionWithReturnForList(2) + ",";
                    }
                }
            }
            if (ret.length() > 0) {
                ret = rollbackColon(ret) + getEndIndentionWithReturn(1);
            }
            if (ret.length() > 0) {
                ret = rollbackColon(ret) + getEndIndentionWithReturn(0);
            }
        }
    }
    return ret;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ManagedOperation(org.apache.cxf.management.annotation.ManagedOperation)

Example 74 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project camel by apache.

the class DefaultCxfBinding method getResponsePayloadList.

// Non public methods
// -------------------------------------------------------------------------
protected MessageContentsList getResponsePayloadList(org.apache.cxf.message.Exchange exchange, List<Source> elements) {
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
        exchange.put(BindingOperationInfo.class, boi);
    }
    MessageContentsList answer = new MessageContentsList();
    int i = 0;
    if (boi.getOutput() != null) {
        for (MessagePartInfo partInfo : boi.getOutput().getMessageParts()) {
            if (elements != null && elements.size() > i) {
                answer.put(partInfo, elements.get(i++));
            }
        }
    }
    return answer;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 75 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project midpoint by Evolveum.

the class CustomWrappedOutInterceptor method writeParts.

@Override
protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
    // TODO Auto-generated method stub
    OutputStream out = message.getContent(OutputStream.class);
    XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
    Service service = exchange.getService();
    XMLStreamWriter xmlWriter = origXmlWriter;
    CachingXmlEventWriter cache = null;
    Object en = message.getContextualProperty(OUT_BUFFERING);
    boolean allowBuffer = true;
    boolean buffer = false;
    if (en != null) {
        buffer = Boolean.TRUE.equals(en) || "true".equals(en);
        allowBuffer = !(Boolean.FALSE.equals(en) || "false".equals(en));
    }
    // need to cache the events in case validation fails or buffering is enabled
    if (buffer || (allowBuffer && shouldValidate(message) && !isRequestor(message))) {
        cache = new CachingXmlEventWriter();
        try {
            cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
        } catch (XMLStreamException e) {
        //ignorable, will just get extra namespace decls
        }
        xmlWriter = cache;
        out = null;
    }
    if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.isTrue(message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION))) {
        if (xmlWriter != null) {
            try {
                xmlWriter.writeCharacters("");
                xmlWriter.flush();
            } catch (XMLStreamException e) {
                throw new Fault(e);
            }
        }
        DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
        for (MessagePartInfo part : parts) {
            if (objs.hasValue(part)) {
                Object o = objs.get(part);
                osWriter.write(o, part, out);
            }
        }
    } else {
        DataWriter<XMLStreamWriter> dataWriter = new CustomDataWriter(prismContext);
        for (MessagePartInfo part : parts) {
            if (objs.hasValue(part)) {
                Object o = objs.get(part);
                dataWriter.write(o, part, xmlWriter);
            }
        }
    }
    if (cache != null) {
        try {
            for (XMLEvent event : cache.getEvents()) {
                StaxUtils.writeEvent(event, origXmlWriter);
            }
        } catch (XMLStreamException e) {
            throw new Fault(e);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)157 QName (javax.xml.namespace.QName)97 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)44 Test (org.junit.Test)38 MessageInfo (org.apache.cxf.service.model.MessageInfo)36 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)27 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 Fault (org.apache.cxf.interceptor.Fault)20 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)18 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)12 FaultInfo (org.apache.cxf.service.model.FaultInfo)11