Search in sources :

Example 1 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation 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 2 with ManagedOperation

use of org.apache.cxf.management.annotation.ManagedOperation 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 3 with ManagedOperation

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

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

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

the class ModelMBeanAssembler method getModelMbeanInfo.

public ModelMBeanInfo getModelMbeanInfo(Class<?> clazz) {
    supporter.clear();
    ManagedResource mr = getManagedResource(clazz);
    if (mr == null) {
        // the class is not need to expose to jmx
        return null;
    }
    // Clazz get all the method which should be managemed
    Descriptor mbeanDescriptor = supporter.buildMBeanDescriptor(mr);
    // add the notification
    ManagedNotification[] mns = getManagedNotifications(clazz);
    for (int k = 0; k < mns.length; k++) {
        supporter.addModelMBeanNotification(mns[k].notificationTypes(), mns[k].name(), mns[k].description(), null);
    }
    Method[] methods = clazz.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        ManagedAttribute ma = getManagedAttribute(methods[i]);
        // add Attribute to the ModelMBean
        if (ma != null) {
            String attributeName = getAttributeName(methods[i].getName());
            if (!supporter.checkAttribute(attributeName)) {
                String attributeType = getAttributeType(methods, attributeName);
                ManagedAttributeInfo mai = getAttributInfo(methods, attributeName, attributeType, ma);
                Descriptor attributeDescriptor = supporter.buildAttributeDescriptor(ma, attributeName, mai.is, mai.read, mai.write);
                // should setup the description
                supporter.addModelMBeanAttribute(mai.fname, mai.ftype, mai.read, mai.write, mai.is, mai.description, attributeDescriptor);
                Method method;
                // add the attribute methode to operation
                if (mai.read) {
                    if (mai.is) {
                        method = findMethodByName(methods, "is" + attributeName);
                    } else {
                        method = findMethodByName(methods, "get" + attributeName);
                    }
                    addAttributeOperation(method);
                }
                if (mai.write) {
                    method = findMethodByName(methods, "set" + attributeName);
                    addAttributeOperation(method);
                }
            }
        } else {
            // add Operation to the ModelMBean
            ManagedOperation mo = getManagedOperation(methods[i]);
            if (mo != null) {
                Class<?>[] types = methods[i].getParameterTypes();
                ManagedOperationParameter[] mop = getManagedOperationParameters(methods[i]);
                String[] paramTypes = new String[types.length];
                String[] paramNames = new String[types.length];
                String[] paramDescs = new String[types.length];
                for (int j = 0; j < types.length; j++) {
                    paramTypes[j] = types[j].getName();
                    if (j < mop.length) {
                        paramDescs[j] = mop[j].description();
                        paramNames[j] = mop[j].name();
                    } else {
                        paramDescs[j] = "";
                        paramNames[j] = types[j].getName();
                    }
                }
                Descriptor operationDescriptor = supporter.buildOperationDescriptor(mo, methods[i].getName());
                supporter.addModelMBeanMethod(methods[i].getName(), paramTypes, paramNames, paramDescs, mo.description(), methods[i].getReturnType().getName(), operationDescriptor);
            }
        }
    }
    return supporter.buildModelMBeanInfo(mbeanDescriptor);
}
Also used : Method(java.lang.reflect.Method) ManagedResource(org.apache.cxf.management.annotation.ManagedResource) ManagedAttribute(org.apache.cxf.management.annotation.ManagedAttribute) ManagedOperation(org.apache.cxf.management.annotation.ManagedOperation) ManagedNotification(org.apache.cxf.management.annotation.ManagedNotification) ManagedOperationParameter(org.apache.cxf.management.annotation.ManagedOperationParameter) Descriptor(javax.management.Descriptor)

Example 5 with ManagedOperation

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

the class ManagedRMEndpoint method terminateSourceSequence.

@ManagedOperation(description = "Terminate Source Sequence")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "sequenceId", description = "The sequence identifier") })
public void terminateSourceSequence(String sid) throws JMException {
    SourceSequence ss = getSourceSeq(sid);
    if (null == ss) {
        throw new JMException("no source sequence");
    }
    Proxy proxy = endpoint.getProxy();
    try {
        proxy.terminate(ss);
        ss.getSource().removeSequence(ss);
    } catch (RMException e) {
        throw new JMException("Error terminating sequence: " + e.getMessage());
    }
}
Also used : JMException(javax.management.JMException) ManagedOperationParameters(org.apache.cxf.management.annotation.ManagedOperationParameters) 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