Search in sources :

Example 11 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation in project fabric8 by fabric8io.

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 12 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation in project fabric8 by fabric8io.

the class ManagedApi method getJSONSchemaForClass.

@ManagedOperation(description = "get the JSON schema from a given class", currencyTimeLimit = 60)
public String getJSONSchemaForClass(String clsName) {
    String ret = "";
    if (!isWSDL()) {
        Set<Class<?>> resourceTypes = getRESTResourceTypes();
        if (resourceTypes != null) {
            try {
                ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol();
                for (Class<?> cls : resourceTypes) {
                    if (cls.getName().endsWith(clsName) && JsonSchemaLookup.getSingleton().getSchemaForClass(cls).length() > 0) {
                        ret = ret + getIndention(2) + "\"" + cls.getName() + "\" : " + getEol();
                        ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(cls), 3);
                        ret = ret + getEol();
                    }
                }
                ret = ret + getEndIndentionWithReturn(1);
                ret = ret + getEndIndentionWithReturn(0);
            } catch (Throwable e) {
                LOG.log(Level.WARNING, "getJSONSchemaForClass failed.", e);
            }
        }
    } else {
        for (ServiceInfo serviceInfo : endpoint.getService().getServiceInfos()) {
            for (BindingInfo bindingInfo : serviceInfo.getBindings()) {
                ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol();
                for (BindingOperationInfo boi : bindingInfo.getOperations()) {
                    if (boi.getInput() != null && boi.getInput().getMessageParts() != null) {
                        for (MessagePartInfo mpi : boi.getInput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null && partClass.getName().endsWith(clsName)) {
                                ret = ret + getIndention(2) + "\"" + partClass.getName() + "\" : " + getEol();
                                ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3);
                            }
                        }
                    }
                    if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null) {
                        for (MessagePartInfo mpi : boi.getOutput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null && partClass.getName().endsWith(clsName)) {
                                ret = ret + getIndention(2) + "\"" + partClass.getName() + "\" : " + getEol();
                                ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3);
                            }
                        }
                    }
                }
                ret = ret + getEndIndentionWithReturn(1);
                ret = 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 13 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation in project fabric8 by fabric8io.

the class ManagedApi method jsonToXml.

@ManagedOperation(description = "get xml payload from json payload", currencyTimeLimit = 60)
public String jsonToXml(String jsonText, String pojoType) {
    ObjectMapper objectMapper = new ObjectMapper();
    StringWriter sw = new StringWriter();
    try {
        Object pojo = objectMapper.readValue(jsonText, findClass(pojoType));
        JAXBContext jc = JAXBContext.newInstance(findClass(pojoType));
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(pojo, sw);
    } catch (Exception e) {
        LOG.log(Level.WARNING, "jsonToXml failed.", e);
    }
    return sw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JMException(javax.management.JMException) ManagedOperation(org.apache.cxf.management.annotation.ManagedOperation)

Example 14 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation in project fabric8 by jboss-fuse.

the class ManagedApi method getJSONSchemaForClass.

@ManagedOperation(description = "get the JSON schema from a given class", currencyTimeLimit = 60)
public String getJSONSchemaForClass(String clsName) {
    String ret = "";
    if (!isWSDL()) {
        Set<Class<?>> resourceTypes = getRESTResourceTypes();
        if (resourceTypes != null) {
            try {
                ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol();
                for (Class<?> cls : resourceTypes) {
                    if (cls.getName().endsWith(clsName) && JsonSchemaLookup.getSingleton().getSchemaForClass(cls).length() > 0) {
                        ret = ret + getIndention(2) + "\"" + cls.getName() + "\" : " + getEol();
                        ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(cls), 3);
                        ret = ret + getEol();
                    }
                }
                ret = ret + getEndIndentionWithReturn(1);
                ret = ret + getEndIndentionWithReturn(0);
            } catch (Throwable e) {
                LOG.log(Level.WARNING, "getJSONSchemaForClass failed.", e);
            }
        }
    } else {
        for (ServiceInfo serviceInfo : endpoint.getService().getServiceInfos()) {
            for (BindingInfo bindingInfo : serviceInfo.getBindings()) {
                ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol();
                for (BindingOperationInfo boi : bindingInfo.getOperations()) {
                    if (boi.getInput() != null && boi.getInput().getMessageParts() != null) {
                        for (MessagePartInfo mpi : boi.getInput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null && partClass.getName().endsWith(clsName)) {
                                ret = ret + getIndention(2) + "\"" + partClass.getName() + "\" : " + getEol();
                                ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3);
                            }
                        }
                    }
                    if (boi.getOutput() != null && boi.getOutput().getMessageParts() != null) {
                        for (MessagePartInfo mpi : boi.getOutput().getMessageParts()) {
                            Class<?> partClass = mpi.getTypeClass();
                            if (partClass != null && partClass.getName().endsWith(clsName)) {
                                ret = ret + getIndention(2) + "\"" + partClass.getName() + "\" : " + getEol();
                                ret = ret + reformatIndent(JsonSchemaLookup.getSingleton().getSchemaForClass(partClass), 3);
                            }
                        }
                    }
                }
                ret = ret + getEndIndentionWithReturn(1);
                ret = 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)

Aggregations

ManagedOperation (org.apache.cxf.management.annotation.ManagedOperation)14 BindingInfo (org.apache.cxf.service.model.BindingInfo)6 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)6 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 JMException (javax.management.JMException)5 ManagedOperationParameters (org.apache.cxf.management.annotation.ManagedOperationParameters)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 JAXBContext (javax.xml.bind.JAXBContext)2 Marshaller (javax.xml.bind.Marshaller)2 AcknowledgementRange (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)2 Method (java.lang.reflect.Method)1 Descriptor (javax.management.Descriptor)1 ManagedAttribute (org.apache.cxf.management.annotation.ManagedAttribute)1 ManagedNotification (org.apache.cxf.management.annotation.ManagedNotification)1 ManagedOperationParameter (org.apache.cxf.management.annotation.ManagedOperationParameter)1