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;
}
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;
}
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();
}
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;
}
Aggregations