Sunday, December 28, 2014

[org.hibernate.LazyInitializationException: could not initialize proxy - no Session] with root cause

1.error

[QC] WARN [http-bio-8080-exec-1] org.apache.struts.chain.commands.AbstractExceptionHandler.execute(95) | Unhandled exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at com.chinamobile.onduty.db.TParty_$$_javassist_2.getName(TParty_$$_javassist_2.java)
at com.chinamobile.onduty.vo.LoginInfoVO.saveToSession(LoginInfoVO.java:56)
at com.chinamobile.onduty.struts.action.LoginAction.execute(LoginAction.java:66)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[QC] WARN [http-bio-8080-exec-1] org.apache.struts.chain.commands.ExceptionCatcher.postprocess(165) | Exception from exceptionCommand 'servlet-exception'
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at com.chinamobile.onduty.db.TParty_$$_javassist_2.getName(TParty_$$_javassist_2.java)
at com.chinamobile.onduty.vo.LoginInfoVO.saveToSession(LoginInfoVO.java:56)
at com.chinamobile.onduty.struts.action.LoginAction.execute(LoginAction.java:66)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
十二月 29, 2014 9:01:20 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [action] in context with path [/onduty] threw exception [org.hibernate.LazyInitializationException: could not initialize proxy - no Session] with root cause
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at com.chinamobile.onduty.db.TParty_$$_javassist_2.getName(TParty_$$_javassist_2.java)
at com.chinamobile.onduty.vo.LoginInfoVO.saveToSession(LoginInfoVO.java:56)
at com.chinamobile.onduty.struts.action.LoginAction.execute(LoginAction.java:66)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)



fixed



because TUser and TPart has foreign key relative in mysql.



edit web.xml,add OpenSessionInViewFilter:



<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

<!-- resolved org.hibernate.LazyInitializationException: could not initialize proxy -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

Thursday, December 25, 2014

Caused by: org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]

error:

十二月 26, 2014 9:08:16 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.unwrap(DriverManagerConnectionProviderImpl.java:91)
at org.springframework.orm.hibernate4.SessionFactoryUtils.getDataSource(SessionFactoryUtils.java:101)
at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 25 more



fixed:



changed hibernate.cfg.xml content to applicationContext.xml.



error:



The action name cannot be the same as the action suffix [Action] - Class: org.apache.struts2.convention.SEOActionNameBuilder
File: SEOActionNameBuilder.java
Method: build
Line: 64 - org/apache/struts2/convention/SEOActionNameBuilder.java:64:-1
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.IllegalStateException: The action name cannot be the same as the action suffix [Action]
at org.apache.struts2.convention.SEOActionNameBuilder.build(SEOActionNameBuilder.java:64)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.determineActionName(PackageBasedActionConfigBuilder.java:777)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:600)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:336)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
... 19 more



fixed:



changed structs.xml



old:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
</struts>

new:



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.convention.package.locators" value="actions,struts2"/>
</struts>

Tuesday, December 23, 2014

nested exception is org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

used hibernate to runtime create mysql tables.

old:


<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true
</value>
</property>



fixed:



        <property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>

Thursday, December 11, 2014

j2ee ssh developer error log

1.what

i used struct 1.3 and struct 2 in myeclipse 2014,and found some error.

2.error

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
十二月 11, 2014 4:26:47 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3920)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1357)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1451)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 26 more
十二月 11, 2014 4:26:47 下午 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
十二月 11, 2014 4:26:47 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/ServerBaseStation] startup failed due to previous errors
十二月 11, 2014 4:26:47 下午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
十二月 11, 2014 4:26:47 下午 org.apache.catalina.core.StandardContext listenerStop
严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:556)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3920)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1357)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1451)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:744)



fixed



comment some content in web.xml



<!--
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
-->



2. error



十二月 11, 2014 4:31:25 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
The action name cannot be the same as the action suffix [Action] - Class: org.apache.struts2.convention.SEOActionNameBuilder
File: SEOActionNameBuilder.java
Method: build
Line: 64 - org/apache/struts2/convention/SEOActionNameBuilder.java:64:-1
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.IllegalStateException: The action name cannot be the same as the action suffix [Action]
at org.apache.struts2.convention.SEOActionNameBuilder.build(SEOActionNameBuilder.java:64)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.determineActionName(PackageBasedActionConfigBuilder.java:777)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:600)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:336)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
... 19 more
十二月 11, 2014 4:31:25 下午 org.apache.catalina.core.StandardContext startInternal



fixed



add content in structs.xml:




<constant name="struts.convention.package.locators" value="actions,struts2"/>




error



十二月 11, 2014 4:33:24 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [action] in context with path [/ServerBaseStation] threw exception [org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'UserService' is defined] with root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'UserService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at com.chinamobile.serverbasestation.struts.action.BaseAction.getBean(BaseAction.java:10)
at com.chinamobile.serverbasestation.struts.action.LoginAction.execute(LoginAction.java:45)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)



fixed:



edit applicationContext.xml:



<bean id="UserService" class="com.chinamobile.serverbasestation.service.impl.UserService">
</bean>

Tuesday, December 9, 2014

android how to known mobile 2g/3g/4g signal signalstrength value in china or world?

1. sign and asu change fomula in gsm

    public static int sign2asu(int sign){
return (int)(sign+113)/2;
}

public static int asu2sign(int asu){
return -113+(2*asu);
}



2.get gsm 2g sign value,or in cdma



    protected TelephonyManager _tm;
private PhoneStateListener _listener;

public static PhoneStateListener signListener = new PhoneStateListener() {

public void onSignalStrengthsChanged(SignalStrength signalStrength){
int asu = 0;
isGsm=signalStrength.isGsm();
if (isGsm){
asu = signalStrength.getGsmSignalStrength();
sign = CommType.asu2sign(asu);
}else{
sign = signalStrength.getCdmaDbm();
}

}

public void onSignalStrengthChanged(int asu) {
// Log.e("BeanDateUtils", "asu"+asu);
}
};

// register it
_tm = (TelephonyManager) service.getSystemService(Context.TELEPHONY_SERVICE);

_listener = new PhoneStateMonitor();

_tm.listen(_listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

// unregister it

_tm.listen(_listener, PhoneStateListener.LISTEN_NONE);
_listener = null;
_tm = null;


3.get 2g gsm/cdma other value



    public static Map<String, Integer> getPhoneDatas(TelephonyManager tm){
/**
* MCC(Mobile Country Code,移动国家号码),用于唯一地标识移动客户属于的国家。它由三位十进制数组成(000-999),例如我国的MCC为460。
*/
int mcc = 0;
/**
* 定义
MNC(Mobile Network Code,移动网络号码),用于识别移动客户所属的移动网络。 
格式
MNC由二个十进制数组成,编码范围为十进制的00-99,例如中国移动的MNC为00和02[1],中国联通的MNC为01,中国电信的MNC为03。
*/
int mnc = 0;
int cid = 0;
int lac = 0;
Map<String, Integer> map=new HashMap<String, Integer>();

CellLocation cl = tm.getCellLocation();

// for no sim card phone
if( cl == null)
return map;

if(cl.getClass().equals(GsmCellLocation.class)){
mcc = 0;
mnc = 0;
GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
if (null!=gcl){
cid = gcl.getCid();
lac = gcl.getLac();
}

}else if(cl.getClass().equals(CdmaCellLocation.class)){
CdmaCellLocation gcl = (CdmaCellLocation) tm.getCellLocation();
if (null!=gcl){
cid = gcl.getBaseStationId();
lac = gcl.getSystemId();
}
}

String str1 = Build.MODEL;
if (str1.equals("HUAWEI MT2-L01"))
mnc = ((113 + mnc) / 2);

map.put(LABEL_CELL_MCC, mcc);
map.put(LABEL_CELL_MNC, mnc);
map.put(LABEL_CELL_CID, cid);
map.put(LABEL_CELL_LAC, lac);
return map;
}


4.get gsm cell info



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Map<String,String> _fillCellInfoGsm(CellInfoGsm cig){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityGsm cg = cig.getCellIdentity();
CellSignalStrengthGsm cssg = cig.getCellSignalStrength();

int tmp = cg.getCid();
ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_GSM);
ret.put(LABEL_CELL_CID,"" + cg.getCid());
ret.put(LABEL_CELL_LAC,"" + cg.getLac());
ret.put(LABEL_CELL_MCC,"" + cg.getMcc());
ret.put(LABEL_CELL_MNC,"" + cg.getMnc());

ret.put(LABEL_CELL_ASULEVEL,"" + cssg.getAsuLevel());
// ret.put(LABEL_CELL_DBM,"" + cssg.getDbm()); // ?
ret.put(LABEL_CELL_SIGN,"" + cssg.getDbm());
ret.put(LABEL_CELL_LEVEL,"" + cssg.getLevel());

do{
String s = cssg.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ber"))
ret.put(LABEL_CELL_BITERRORRATE,ssss[1]);
}
}while(false);
return ret;
}


5.get 4g lte cell info



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Map<String,String> _fillCellInfoLte(CellInfoLte cil,TelephonyManager tm){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityLte cid = cil.getCellIdentity();
CellSignalStrengthLte css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_LTE);
ret.put(LABEL_CELL_CI,"" + cid.getCi());
ret.put(LABEL_CELL_MCC,"" + cid.getMcc());
ret.put(LABEL_CELL_MNC,"" + cid.getMnc());
ret.put(LABEL_CELL_PCI,"" + cid.getPci());
ret.put(LABEL_CELL_TAC,"" + cid.getTac());

ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());
ret.put(LABEL_CELL_TIMEADVANCE,"" + css.getTimingAdvance());
ret.put(LABEL_CELL_RSRP,"" + css.getDbm()); // rsrp
// ret.put(LABEL_CELL_SIGN,"" + CommType.asu2sign(css.getDbm()));
ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());

do{
String s = css.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ss"))
ret.put(LABEL_CELL_SIGN,ssss[1]);
else if(ssss[0].equals("rsrq"))
ret.put(LABEL_CELL_RSRQ,ssss[1]);
else if(ssss[0].equals("rssnr"))
ret.put(LABEL_CELL_RSSNR,ssss[1]);
else if(ssss[0].equals("cqi"))
ret.put(LABEL_CELL_CQI,ssss[1]);
}
}while(false);

do{ // get td-lte
// cmcc
if(cid.getMcc() != 460 || (cid.getMnc()!=0 && cid.getMnc()!=2))
break;

CellLocation cl = tm.getCellLocation();
if(cl == null)
break;

if(!cl.getClass().equals(GsmCellLocation.class))
break;


}while(false);

return ret;
}


6. get cdma cell info



    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 
private static Map<String,String> _fillCellInfoCdma(CellInfoCdma cil){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityCdma cid = cil.getCellIdentity();
CellSignalStrengthCdma css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_CDMA);
ret.put(LABEL_CELL_NETWORKID,"" + cid.getNetworkId());
ret.put(LABEL_CELL_SYSTEMID,"" + cid.getSystemId());
ret.put(LABEL_CELL_CID,"" + cid.getBasestationId());
ret.put(LABEL_CELL_LONGTITUDE,"" + cid.getLongitude());
ret.put(LABEL_CELL_LATITUDE,"" + cid.getLatitude());

ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());
ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());
ret.put(LABEL_CELL_CDMALEVEL,"" + css.getCdmaLevel());
ret.put(LABEL_CELL_EVDOLEVEL,"" + css.getEvdoLevel());
ret.put(LABEL_CELL_DBM,"" + css.getDbm());
ret.put(LABEL_CELL_CDMADBM,"" + css.getCdmaDbm());
ret.put(LABEL_CELL_CDMAECIO,"" + css.getCdmaEcio());
ret.put(LABEL_CELL_EVDODBM,"" + css.getEvdoDbm());
ret.put(LABEL_CELL_EVDOECIO,"" + css.getEvdoEcio());
ret.put(LABEL_CELL_EVDOSNR,"" + css.getEvdoSnr());

return ret;
}



7.get wcdma cell info



    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 
private static Map<String,String> _fillCellInfo_18(CellInfo ci){
Map<String,String> ret = new HashMap<String,String>();

if(ci.getClass().equals(CellInfoWcdma.class)){
CellInfoWcdma cil = (CellInfoWcdma)ci;

CellIdentityWcdma cid = cil.getCellIdentity();
CellSignalStrengthWcdma css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_WCDMA);
ret.put(LABEL_CELL_MCC,"" + cid.getMcc());
ret.put(LABEL_CELL_MNC,"" + cid.getMnc());
ret.put(LABEL_CELL_TAC,"" + cid.getLac());
ret.put(LABEL_CELL_CID,"" + cid.getCid());
ret.put(LABEL_CELL_PSC,"" + cid.getPsc());

ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());
ret.put(LABEL_CELL_SIGN,"" + css.getDbm());
ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());

do{
String s = css.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ber"))
ret.put(LABEL_CELL_BITERRORRATE,ssss[1]);
}
}while(false);
}

return ret;
}



9.get android 4.2.2+ 3/4 g cell info code



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static List<Map<String,String> > _get4GPhoneCellDatas_17(TelephonyManager tm){
List<Map<String,String> > ret = null;

if(tm == null)
return ret;

List<CellInfo> ciList = tm.getAllCellInfo();
do{
if(ciList == null || ciList.size()==0)
break;

Map<String,String> retitem;

for(CellInfo ci : ciList){

retitem = null;

if(ci.getClass().equals(CellInfoGsm.class)){

retitem = _fillCellInfoGsm((CellInfoGsm)ci);

}else if(ci.getClass().equals(CellInfoLte.class)){

retitem = _fillCellInfoLte((CellInfoLte)ci,tm);

} else if(ci.getClass().equals(CellInfoCdma.class)){

retitem = _fillCellInfoCdma((CellInfoCdma)ci);

} else{

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
retitem = _fillCellInfo_18(ci);

}

if(retitem != null){

retitem.put(LABEL_CELL_TIME,microSecondsToString(ci.getTimeStamp()));

if(ret == null)
ret = new ArrayList<Map<String,String> >();

ret.add(retitem);
}
}

}while(false);

return ret;
}



10.get android all plateform 4g all cell code



    public static List<Map<String,String>> get4GPhoneCellAllDatas(TelephonyManager tm){
List<Map<String,String>> ret = null;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){
ret = _get4GPhoneCellDatas_17(tm);
}else{
Map<String, Integer> item = getPhoneDatas(tm);
if(item != null){
Map<String,String> tmp = new HashMap<String,String>();
for(Entry<String, Integer> a:item.entrySet()){
tmp.put(a.getKey(), "" + a.getValue());
}
ret = new ArrayList<Map<String,String>>();
ret.add(tmp);
}
}


return ret;
}



11. get td-lte 4g signalstreth value in china



    public static SignalStrengthData getLtePhoneSignalStrengthData(SignalStrength signalStrength){
SignalStrengthData ret = null;

do{
if(signalStrength == null)
break;

String s = signalStrength.toString();
String[] ss = s.split(" ");

if(ss.length<14)
break;

ret = new SignalStrengthData();

ret.Sign = Integer.parseInt(ss[8]);
ret.Rsrp = Integer.parseInt(ss[9]);
ret.Rsrq = Integer.parseInt(ss[10]);
ret.Rssnr = Integer.parseInt(ss[11]) / 10;
ret.Cqi = Integer.parseInt(ss[12]);

}while(false);

return ret;
}



Note:



in some mobile liked huawei some mode,those sign value need manul handle.



 



x.Last



Thanks.



Above code,we only test in cdma / gsm / td-lte some logic in china.

android how to known mobile 2g/3g/4g signal signalstrength value in china or world?

1. sign and asu change fomula in gsm

    public static int sign2asu(int sign){
return (int)(sign+113)/2;
}

public static int asu2sign(int asu){
return -113+(2*asu);
}



2.get gsm 2g sign value,or in cdma



    protected TelephonyManager _tm;
private PhoneStateListener _listener;

public static PhoneStateListener signListener = new PhoneStateListener() {

public void onSignalStrengthsChanged(SignalStrength signalStrength){
int asu = 0;
isGsm=signalStrength.isGsm();
if (isGsm){
asu = signalStrength.getGsmSignalStrength();
sign = CommType.asu2sign(asu);
}else{
sign = signalStrength.getCdmaDbm();
}

}

public void onSignalStrengthChanged(int asu) {
// Log.e("BeanDateUtils", "asu"+asu);
}
};

// register it
_tm = (TelephonyManager) service.getSystemService(Context.TELEPHONY_SERVICE);

_listener = new PhoneStateMonitor();

_tm.listen(_listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

// unregister it

_tm.listen(_listener, PhoneStateListener.LISTEN_NONE);
_listener = null;
_tm = null;


3.get 2g gsm/cdma other value



    public static Map<String, Integer> getPhoneDatas(TelephonyManager tm){
/**
* MCC(Mobile Country Code,移动国家号码),用于唯一地标识移动客户属于的国家。它由三位十进制数组成(000-999),例如我国的MCC为460。
*/
int mcc = 0;
/**
* 定义
MNC(Mobile Network Code,移动网络号码),用于识别移动客户所属的移动网络。 
格式
MNC由二个十进制数组成,编码范围为十进制的00-99,例如中国移动的MNC为00和02[1],中国联通的MNC为01,中国电信的MNC为03。
*/
int mnc = 0;
int cid = 0;
int lac = 0;
Map<String, Integer> map=new HashMap<String, Integer>();

CellLocation cl = tm.getCellLocation();

// for no sim card phone
if( cl == null)
return map;

if(cl.getClass().equals(GsmCellLocation.class)){
mcc = 0;
mnc = 0;
GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation();
if (null!=gcl){
cid = gcl.getCid();
lac = gcl.getLac();
}

}else if(cl.getClass().equals(CdmaCellLocation.class)){
CdmaCellLocation gcl = (CdmaCellLocation) tm.getCellLocation();
if (null!=gcl){
cid = gcl.getBaseStationId();
lac = gcl.getSystemId();
}
}

String str1 = Build.MODEL;
if (str1.equals("HUAWEI MT2-L01"))
mnc = ((113 + mnc) / 2);

map.put(LABEL_CELL_MCC, mcc);
map.put(LABEL_CELL_MNC, mnc);
map.put(LABEL_CELL_CID, cid);
map.put(LABEL_CELL_LAC, lac);
return map;
}


4.get gsm cell info



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Map<String,String> _fillCellInfoGsm(CellInfoGsm cig){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityGsm cg = cig.getCellIdentity();
CellSignalStrengthGsm cssg = cig.getCellSignalStrength();

int tmp = cg.getCid();
ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_GSM);
ret.put(LABEL_CELL_CID,"" + cg.getCid());
ret.put(LABEL_CELL_LAC,"" + cg.getLac());
ret.put(LABEL_CELL_MCC,"" + cg.getMcc());
ret.put(LABEL_CELL_MNC,"" + cg.getMnc());

ret.put(LABEL_CELL_ASULEVEL,"" + cssg.getAsuLevel());
// ret.put(LABEL_CELL_DBM,"" + cssg.getDbm()); // ?
ret.put(LABEL_CELL_SIGN,"" + cssg.getDbm());
ret.put(LABEL_CELL_LEVEL,"" + cssg.getLevel());

do{
String s = cssg.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ber"))
ret.put(LABEL_CELL_BITERRORRATE,ssss[1]);
}
}while(false);
return ret;
}


5.get 4g lte cell info



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Map<String,String> _fillCellInfoLte(CellInfoLte cil,TelephonyManager tm){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityLte cid = cil.getCellIdentity();
CellSignalStrengthLte css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_LTE);
ret.put(LABEL_CELL_CI,"" + cid.getCi());
ret.put(LABEL_CELL_MCC,"" + cid.getMcc());
ret.put(LABEL_CELL_MNC,"" + cid.getMnc());
ret.put(LABEL_CELL_PCI,"" + cid.getPci());
ret.put(LABEL_CELL_TAC,"" + cid.getTac());

ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());
ret.put(LABEL_CELL_TIMEADVANCE,"" + css.getTimingAdvance());
ret.put(LABEL_CELL_RSRP,"" + css.getDbm()); // rsrp
// ret.put(LABEL_CELL_SIGN,"" + CommType.asu2sign(css.getDbm()));
ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());

do{
String s = css.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ss"))
ret.put(LABEL_CELL_SIGN,ssss[1]);
else if(ssss[0].equals("rsrq"))
ret.put(LABEL_CELL_RSRQ,ssss[1]);
else if(ssss[0].equals("rssnr"))
ret.put(LABEL_CELL_RSSNR,ssss[1]);
else if(ssss[0].equals("cqi"))
ret.put(LABEL_CELL_CQI,ssss[1]);
}
}while(false);

do{ // get td-lte
// cmcc
if(cid.getMcc() != 460 || (cid.getMnc()!=0 && cid.getMnc()!=2))
break;

CellLocation cl = tm.getCellLocation();
if(cl == null)
break;

if(!cl.getClass().equals(GsmCellLocation.class))
break;


}while(false);

return ret;
}


6. get cdma cell info



    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) 
private static Map<String,String> _fillCellInfoCdma(CellInfoCdma cil){
Map<String,String> ret = new HashMap<String,String>();

CellIdentityCdma cid = cil.getCellIdentity();
CellSignalStrengthCdma css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_CDMA);
ret.put(LABEL_CELL_NETWORKID,"" + cid.getNetworkId());
ret.put(LABEL_CELL_SYSTEMID,"" + cid.getSystemId());
ret.put(LABEL_CELL_CID,"" + cid.getBasestationId());
ret.put(LABEL_CELL_LONGTITUDE,"" + cid.getLongitude());
ret.put(LABEL_CELL_LATITUDE,"" + cid.getLatitude());

ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());
ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());
ret.put(LABEL_CELL_CDMALEVEL,"" + css.getCdmaLevel());
ret.put(LABEL_CELL_EVDOLEVEL,"" + css.getEvdoLevel());
ret.put(LABEL_CELL_DBM,"" + css.getDbm());
ret.put(LABEL_CELL_CDMADBM,"" + css.getCdmaDbm());
ret.put(LABEL_CELL_CDMAECIO,"" + css.getCdmaEcio());
ret.put(LABEL_CELL_EVDODBM,"" + css.getEvdoDbm());
ret.put(LABEL_CELL_EVDOECIO,"" + css.getEvdoEcio());
ret.put(LABEL_CELL_EVDOSNR,"" + css.getEvdoSnr());

return ret;
}



7.get wcdma cell info



    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) 
private static Map<String,String> _fillCellInfo_18(CellInfo ci){
Map<String,String> ret = new HashMap<String,String>();

if(ci.getClass().equals(CellInfoWcdma.class)){
CellInfoWcdma cil = (CellInfoWcdma)ci;

CellIdentityWcdma cid = cil.getCellIdentity();
CellSignalStrengthWcdma css = cil.getCellSignalStrength();

ret.put(LABEL_CELLTYPE,LABEL_CELL_TYPE_WCDMA);
ret.put(LABEL_CELL_MCC,"" + cid.getMcc());
ret.put(LABEL_CELL_MNC,"" + cid.getMnc());
ret.put(LABEL_CELL_TAC,"" + cid.getLac());
ret.put(LABEL_CELL_CID,"" + cid.getCid());
ret.put(LABEL_CELL_PSC,"" + cid.getPsc());

ret.put(LABEL_CELL_LEVEL,"" + css.getLevel());
ret.put(LABEL_CELL_SIGN,"" + css.getDbm());
ret.put(LABEL_CELL_ASULEVEL,"" + css.getAsuLevel());

do{
String s = css.toString();
String[] ss = s.split(" ");
if(ss == null)
break;

for(String kev : ss){
String[] ssss = kev.split("=");
if(ssss.length<2)
continue;
if(ssss[0].equals("ber"))
ret.put(LABEL_CELL_BITERRORRATE,ssss[1]);
}
}while(false);
}

return ret;
}



9.get android 4.2.2+ 3/4 g cell info code



    
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static List<Map<String,String> > _get4GPhoneCellDatas_17(TelephonyManager tm){
List<Map<String,String> > ret = null;

if(tm == null)
return ret;

List<CellInfo> ciList = tm.getAllCellInfo();
do{
if(ciList == null || ciList.size()==0)
break;

Map<String,String> retitem;

for(CellInfo ci : ciList){

retitem = null;

if(ci.getClass().equals(CellInfoGsm.class)){

retitem = _fillCellInfoGsm((CellInfoGsm)ci);

}else if(ci.getClass().equals(CellInfoLte.class)){

retitem = _fillCellInfoLte((CellInfoLte)ci,tm);

} else if(ci.getClass().equals(CellInfoCdma.class)){

retitem = _fillCellInfoCdma((CellInfoCdma)ci);

} else{

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2)
retitem = _fillCellInfo_18(ci);

}

if(retitem != null){

retitem.put(LABEL_CELL_TIME,microSecondsToString(ci.getTimeStamp()));

if(ret == null)
ret = new ArrayList<Map<String,String> >();

ret.add(retitem);
}
}

}while(false);

return ret;
}



10.get android all plateform 4g all cell code



    public static List<Map<String,String>> get4GPhoneCellAllDatas(TelephonyManager tm){
List<Map<String,String>> ret = null;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){
ret = _get4GPhoneCellDatas_17(tm);
}else{
Map<String, Integer> item = getPhoneDatas(tm);
if(item != null){
Map<String,String> tmp = new HashMap<String,String>();
for(Entry<String, Integer> a:item.entrySet()){
tmp.put(a.getKey(), "" + a.getValue());
}
ret = new ArrayList<Map<String,String>>();
ret.add(tmp);
}
}


return ret;
}



11. get td-lte 4g signalstreth value in china



    public static SignalStrengthData getLtePhoneSignalStrengthData(SignalStrength signalStrength){
SignalStrengthData ret = null;

do{
if(signalStrength == null)
break;

String s = signalStrength.toString();
String[] ss = s.split(" ");

if(ss.length<14)
break;

ret = new SignalStrengthData();

ret.Sign = Integer.parseInt(ss[8]);
ret.Rsrp = Integer.parseInt(ss[9]);
ret.Rsrq = Integer.parseInt(ss[10]);
ret.Rssnr = Integer.parseInt(ss[11]) / 10;
ret.Cqi = Integer.parseInt(ss[12]);

}while(false);

return ret;
}



Note:



in some mobile liked huawei some mode,those sign value need manul handle.



 



x.Last



Thanks.



Above code,we only test in cdma / gsm / td-lte some logic in china.