@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(); }
private String getEndIndentionWithReturn(int n) { return getEol() + getIndention(n) + "}"; }
@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; 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(); 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) {
@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(); + 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); ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol(); for (BindingOperationInfo boi : bindingInfo.getOperations()) { Class<?> partClass = mpi.getTypeClass();
@ManagedAttribute(description = "The cxf servlet context", currencyTimeLimit = 60) public String getServletContext() { if (!isInOSGi()) { LOG.log(Level.FINE, "Not In OSGi."); return getSingletonCxfServletContext(); } String ret = "/cxf"; //if can't get it from configAdmin use the default value if (getConfigurationAdmin() != null) { try { Configuration configuration = getConfigurationAdmin().getConfiguration("org.apache.cxf.osgi"); if (configuration != null) { Dictionary properties = configuration.getProperties(); if (properties != null) { String servletContext = (String)configuration.getProperties(). get("org.apache.cxf.servlet.context"); if (servletContext != null) { ret = servletContext; } } } } catch (IOException e) { LOG.log(Level.WARNING, "getServletContext failed.", e); } } return ret; }
private Class<?> findClass(String clsName) { if (!isWSDL()) { Set<Class<?>> resourceTypes = getRESTResourceTypes(); if (resourceTypes != null) { try {
@ManagedAttribute(description = "The cxf servlet context", currencyTimeLimit = 60) public String getServletContext() { if (!isInOSGi()) { LOG.log(Level.FINE, "Not In OSGi."); return null; //not in OSGi container } String ret = "/cxf"; //if can't get it from configAdmin use the default value if (getConfigurationAdmin() != null) { try { Configuration configuration = getConfigurationAdmin().getConfiguration("org.apache.cxf.osgi", null); if (configuration != null) { Dictionary properties = configuration.getProperties(); if (properties != null) { String servletContext = (String)configuration.getProperties(). get("org.apache.cxf.servlet.context"); if (servletContext != null) { ret = servletContext; } } } } catch (IOException e) { LOG.log(Level.WARNING, "getServletContext failed.", e); } } return ret; }
@Override public void initialize(Bus bus) { List<Server> servers = new ArrayList<Server>(); ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class); servers.addAll(serverRegistry.getServers()); for (Iterator<Server> iter = servers.iterator(); iter.hasNext();) { Server server = (Server) iter.next(); ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server); InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class); if (iMgr == null) { iMgr = new InstrumentationManagerImpl(bus); } ((InstrumentationManagerImpl)iMgr).setUsePlatformMBeanServer(true); ((InstrumentationManagerImpl)iMgr).setCreateMBServerConnectorFactory(false); ((InstrumentationManagerImpl)iMgr).setEnabled(true); ((InstrumentationManagerImpl)iMgr).init(); if (iMgr != null) { try { iMgr.register(mApi); } catch (JMException jmex) { jmex.printStackTrace(); LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex); } } } }
@Override public void initialize(Server server, Bus bus) { ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server); ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server); InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class); slcMgr.registerListener(mApi); slcMgr.registerListener(mEndpoint); mApi.startServer(server); mEndpoint.startServer(server);
@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(); + 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); 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) + "\""
@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(); + 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); ret = ret + getBeginIndentionWithReturn(1) + "\"" + "definitions" + "\" " + " : {" + getEol(); for (BindingOperationInfo boi : bindingInfo.getOperations()) { Class<?> partClass = mpi.getTypeClass();
private Class<?> findClass(String clsName) { if (!isWSDL()) { Set<Class<?>> resourceTypes = getRESTResourceTypes(); if (resourceTypes != null) { try {
@Override public void initialize(Server server, Bus bus) { ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server); InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class); if (iMgr != null) { try { iMgr.register(mApi); ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class); if (slcMgr != null) { slcMgr.registerListener(mApi); slcMgr.startServer(server); } } catch (JMException jmex) { jmex.printStackTrace(); LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex); } } }
@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(); + 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); 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) + "\""
private String getEndIndentionWithReturnForList(int n) { return getEol() + getIndention(n) + "]"; }
ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server); ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server); InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
@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(); }
@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; 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(); 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) {