Spring interview questions part 23

Spring interview questions part 23

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. e static method to locate a platform MBean server. import java.lang.management.ManagementFactory; import javax.management.Descriptor; import javax.management.JMException; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.modelmbean.DescriptorSupport; import javax.management.modelmbean.InvalidTargetObjectTypeException; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanInfo; import javax.management.modelmbean.ModelMBeanInfoSupport; import javax.management.modelmbean.ModelMBeanOperationInfo; import javax.management.modelmbean.RequiredModelMBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName("bean:name=documentReplicator"); RequiredModelMBean mbean = new RequiredModelMBean(); mbean.setManagedResource(documentReplicator, "objectReference"); Descriptor srcDirDescriptor = new DescriptorSupport(new String[] { "name=SrcDir", "descriptorType=attribute", "getMethod=getSrcDir", "setMethod=setSrcDir" }); ModelMBeanAttributeInfo srcDirInfo = new ModelMBeanAttributeInfo( "SrcDir", "java.lang.String", "Source directory", true, true, false, srcDirDescriptor); Descriptor destDirDescriptor = new DescriptorSupport(new String[] { "name=DestDir", "descriptorType=attribute", "getMethod=getDestDir", "setMethod=setDestDir" }); public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); ModelMBeanAttributeInfo destDirInfo = new ModelMBeanAttributeInfo( "DestDir", "java.lang.String", "Destination directory", true, true, false, destDirDescriptor); ModelMBeanOperationInfo getSrcDirInfo = new ModelMBeanOperationInfo( "Get source directory", FileReplicator.class.getMethod("getSrcDir")); ModelMBeanOperationInfo setSrcDirInfo = new ModelMBeanOperationInfo( "Set source directory", FileReplicator.class.getMethod("setSrcDir", String.class)); ModelMBeanOperationInfo getDestDirInfo = new ModelMBeanOperationInfo( "Get destination directory", FileReplicator.class.getMethod("getDestDir")); ModelMBeanOperationInfo setDestDirInfo = new ModelMBeanOperationInfo( "Set destination directory", FileReplicator.class.getMethod("setDestDir", String.class)); ModelMBeanOperationInfo replicateInfo = new ModelMBeanOperationInfo( "Replicate files", FileReplicator.class.getMethod("replicate")); ModelMBeanInfo mbeanInfo = new ModelMBeanInfoSupport( "FileReplicator", "File replicator", new ModelMBeanAttributeInfo[] { srcDirInfo, destDirInfo }, null, new ModelMBeanOperationInfo[] { getSrcDirInfo, setSrcDirInfo, getDestDirInfo, setDestDirInfo, replicateInfo }, null); mbean.setModelMBeanInfo(mbeanInfo); mbeanServer.registerMBean(mbean, objectName); } catch (JMException e) { ... } catch (InvalidTargetObjectTypeException e) { ... } catch (NoSuchMethodException e) { ... } System.in.read(); } }

Correct Answer is : ManagementFactory.getPlatformMBeanServer()

2. om the preceding code, you can see that for each MBean attribute and MBean operation, you need to create a:- import java.lang.management.ManagementFactory; import javax.management.Descriptor; import javax.management.JMException; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.modelmbean.DescriptorSupport; import javax.management.modelmbean.InvalidTargetObjectTypeException; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanInfo; import javax.management.modelmbean.ModelMBeanInfoSupport; import javax.management.modelmbean.ModelMBeanOperationInfo; import javax.management.modelmbean.RequiredModelMBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName("bean:name=documentReplicator"); RequiredModelMBean mbean = new RequiredModelMBean(); mbean.setManagedResource(documentReplicator, "objectReference"); Descriptor srcDirDescriptor = new DescriptorSupport(new String[] { "name=SrcDir", "descriptorType=attribute", "getMethod=getSrcDir", "setMethod=setSrcDir" }); ModelMBeanAttributeInfo srcDirInfo = new ModelMBeanAttributeInfo( "SrcDir", "java.lang.String", "Source directory", true, true, false, srcDirDescriptor); Descriptor destDirDescriptor = new DescriptorSupport(new String[] { "name=DestDir", "descriptorType=attribute", "getMethod=getDestDir", "setMethod=setDestDir" }); public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext("beans-jmx.xml"); FileReplicator documentReplicator = (FileReplicator) context.getBean("documentReplicator"); ModelMBeanAttributeInfo destDirInfo = new ModelMBeanAttributeInfo( "DestDir", "java.lang.String", "Destination directory", true, true, false, destDirDescriptor); ModelMBeanOperationInfo getSrcDirInfo = new ModelMBeanOperationInfo( "Get source directory", FileReplicator.class.getMethod("getSrcDir")); ModelMBeanOperationInfo setSrcDirInfo = new ModelMBeanOperationInfo( "Set source directory", FileReplicator.class.getMethod("setSrcDir", String.class)); ModelMBeanOperationInfo getDestDirInfo = new ModelMBeanOperationInfo( "Get destination directory", FileReplicator.class.getMethod("getDestDir")); ModelMBeanOperationInfo setDestDirInfo = new ModelMBeanOperationInfo( "Set destination directory", FileReplicator.class.getMethod("setDestDir", String.class)); ModelMBeanOperationInfo replicateInfo = new ModelMBeanOperationInfo( "Replicate files", FileReplicator.class.getMethod("replicate")); ModelMBeanInfo mbeanInfo = new ModelMBeanInfoSupport( "FileReplicator", "File replicator", new ModelMBeanAttributeInfo[] { srcDirInfo, destDirInfo }, null, new ModelMBeanOperationInfo[] { getSrcDirInfo, setSrcDirInfo, getDestDirInfo, setDestDirInfo, replicateInfo }, null); mbean.setModelMBeanInfo(mbeanInfo); mbeanServer.registerMBean(mbean, objectName); } catch (JMException e) { ... } catch (InvalidTargetObjectTypeException e) { ... } catch (NoSuchMethodException e) { ... } System.in.read(); } }

Correct Answer is : All of the mentioned

3. VM argument to enable local monitoring of this application.

Correct Answer is : -Dcom.sun.management.jmxremote

4. However, in an environment with no MBean server available, you have to create one explicitly using:-

Correct Answer is : MBeanServerFactoryBean

5. Spring allows you to create a JMX connector server through:-

Correct Answer is : ConnectorServerFactoryBean

6. ? should be replaced by:- ...

Correct Answer is : service:jmx:rmi://localhost/jndi/rmi://localhost:1099/replicator

7. If no RMI registry has been created externally, you should create one by using:-

Correct Answer is : RmiRegistryFactoryBean

8. The simplest MBean assembler in Spring is, which allows you to specify the names of the methods to export.

Correct Answer is : MethodNameBasedMBeanInfoAssembler

9. Spring allows your beans to publish JMX notifications through:-

Correct Answer is : NotificationPublisher

10. Payload format for REST services.

Correct Answer is : All of the mentioned

11. All REST service payloads rely on XML markup.

Correct Answer is : FALSE

12. Class that forms part of Spring to apply JSON content.

Correct Answer is : MappingJacksonJsonView

13. The MappingJacksonJsonView class depends on Jackson JSON processor library.

Correct Answer is : org.codehaus.jackson

14. Information you wish to publishas a JSON Object can be located in a RDBMS or text file, accessed through JDBC or ORM.

Correct Answer is : TRUE

15. JSON payload consists of text and separators like.

Correct Answer is : All of the mentioned

16. To access JSON in a Spring application, library used is:-

Correct Answer is : JSON-LIB

17. You are often better served accessing and manipulating REST services with XML payloads in Spring applications.

Correct Answer is : TRUE

18. Class which is capable of performing a multitude of operations on REST services.

Correct Answer is : RestTemplate

19. XML query language for selecting nodes from an XML document.

Correct Answer is : XPath

20. The Handler method assigns the returning XML payload to a String.

Correct Answer is : TRUE

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon