juniorsatanas 14 de set. de 2012
Boa Tarde !
Android--------------------------REST ou SOAP-------------------Serviço do Seu WebService
já sabe em que e feito o WEBSERVICE ?
erickles 16 de set. de 2012
Bom, vou tentar responder sua pergunta…
Fizemos um Web Service via Visual Studio, conhecido como WCF. Sabemos que com o Android, há maneiras especificas de se fazer isso. Pesquisamos e encontramos um framework chamado “OData”, porém, achamos muito poucos exemplos para seguirmos.
Já fez algo assim antes?
juniorsatanas 16 de set. de 2012
Boa tarde Herick
Terminei o SOAP, agora estou fazendo o REST… ta dando este erro !
INFO: configuring from resource: /hibernate.cfg.xml
INFO: Configuration resource: /hibernate.cfg.xml
INFO: Configured SessionFactory: null
INFO: Binding entity from annotated class: Model.Cliente
INFO: Binding Named query: Cliente.findAll => SELECT c FROM Cliente c
INFO: Binding Named query: Cliente.findById => SELECT c FROM Cliente c WHERE <a href= "http://c.id" > c.id</a> = :id
INFO: Binding Named query: Cliente.findByNome => SELECT c FROM Cliente c WHERE c.nome = :nome
INFO: Binding Named query: Cliente.findByCpf => SELECT c FROM Cliente c WHERE c.cpf = :cpf
INFO: Binding Named query: Cliente.findByEndereco => SELECT c FROM Cliente c WHERE c.endereco = :endereco
INFO: Bind entity Model.Cliente on table Cliente
INFO: Hibernate Validator not found: ignoring
INFO: Using Hibernate built-in connection pool (not for production use!)
INFO: Hibernate connection pool size: 20
INFO: autocommit mode: false
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/sisau
INFO: connection properties: {user=root, password=****}
INFO: RDBMS: PostgreSQL, version: 9.0.3
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC3 with SSL (build 603)
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
INFO: Using default transaction strategy (direct JDBC transactions)
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO: Automatic flush during beforeCompletion(): disabled
INFO: Automatic session close at end of transaction: disabled
INFO: JDBC batch size: 15
INFO: JDBC batch updates for versioned data: disabled
INFO: Scrollable result sets: enabled
INFO: JDBC3 getGeneratedKeys(): disabled
INFO: Connection release mode: auto
INFO: Default schema: sisau
INFO: Default batch fetch size: 1
INFO: Generate SQL with comments: enabled
INFO: Order SQL updates by primary key: disabled
INFO: Order SQL inserts for batching: disabled
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO: Using ASTQueryTranslatorFactory
INFO: Query language substitutions: {}
INFO: JPA-QL strict compliance: disabled
INFO: Second-level cache: enabled
INFO: Query cache: disabled
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
INFO: Optimize cache for minimal puts: disabled
INFO: Structured second-level cache entries: disabled
INFO: Echoing all SQL to stdout
INFO: Statistics: disabled
INFO: Deleted entity synthetic identifier rollback: disabled
INFO: Default entity-mode: pojo
INFO: Named query checking : enabled
INFO: building session factory
GRAVE: ===================Initial SessionFactory creation failed.==============================java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
GRAVE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.ExceptionInInitializerError
at Util.HibernateUtil.getSessionFactory(HibernateUtil.java:30)
at Dao.ClienteDao.buscarTodos(ClienteDao.java:15)
at Controller.ClienteController.buscarTodos(ClienteController.java:17)
at Resources.ClienteResource.selTodosGSON(ClienteResource.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init> (AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init> (PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init> (EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init> (EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.<init> (AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init> (SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init> (SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at Util.HibernateUtil.getSessionFactory(HibernateUtil.java:22)
… 47 more
AVISO : StandardWrapperValve [ ServletAdaptor ] : PWC1406 : Servlet . service () for servlet ServletAdaptor threw exception
java . lang . NoClassDefFoundError : Could not initialize class net . sf . cglib . proxy . Enhancer
at org . hibernate . proxy . pojo . cglib . CGLIBLazyInitializer . getProxyFactory ( CGLIBLazyInitializer . java : 117 )
at org . hibernate . proxy . pojo . cglib . CGLIBProxyFactory . postInstantiate ( CGLIBProxyFactory . java : 43 )
at org . hibernate . tuple . entity . PojoEntityTuplizer . buildProxyFactory ( PojoEntityTuplizer . java : 162 )
at org . hibernate . tuple . entity . AbstractEntityTuplizer . < init > ( AbstractEntityTuplizer . java : 135 )
at org . hibernate . tuple . entity . PojoEntityTuplizer . < init > ( PojoEntityTuplizer . java : 55 )
at org . hibernate . tuple . entity . EntityEntityModeToTuplizerMapping . < init > ( EntityEntityModeToTuplizerMapping . java : 56 )
at org . hibernate . tuple . entity . EntityMetamodel . < init > ( EntityMetamodel . java : 295 )
at org . hibernate . persister . entity . AbstractEntityPersister . < init > ( AbstractEntityPersister . java : 434 )
at org . hibernate . persister . entity . SingleTableEntityPersister . < init > ( SingleTableEntityPersister . java : 109 )
at org . hibernate . persister . PersisterFactory . createClassPersister ( PersisterFactory . java : 55 )
at org . hibernate . impl . SessionFactoryImpl . < init > ( SessionFactoryImpl . java : 226 )
at org . hibernate . cfg . Configuration . buildSessionFactory ( Configuration . java : 1294 )
at org . hibernate . cfg . AnnotationConfiguration . buildSessionFactory ( AnnotationConfiguration . java : 859 )
at Util . HibernateUtil . getSessionFactory ( HibernateUtil . java : 22 )
at Dao . ClienteDao . buscarTodos ( ClienteDao . java : 15 )
at Controller . ClienteController . buscarTodos ( ClienteController . java : 17 )
at Resources . ClienteResource . selTodosGSON ( ClienteResource . java : 28 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 39 )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 25 )
at java . lang . reflect . Method . invoke ( Method . java : 597 )
at com . sun . jersey . spi . container . JavaMethodInvokerFactory $ 1. invoke ( JavaMethodInvokerFactory . java : 60 )
at com . sun . jersey . server . impl . model . method . dispatch . AbstractResourceMethodDispatchProvider $ TypeOutInvoker . _dispatch ( AbstractResourceMethodDispatchProvider . java : 185 )
at com . sun . jersey . server . impl . model . method . dispatch . ResourceJavaMethodDispatcher . dispatch ( ResourceJavaMethodDispatcher . java : 75 )
at com . sun . jersey . server . impl . uri . rules . HttpMethodRule . accept ( HttpMethodRule . java : 288 )
at com . sun . jersey . server . impl . uri . rules . RightHandPathRule . accept ( RightHandPathRule . java : 147 )
at com . sun . jersey . server . impl . uri . rules . ResourceClassRule . accept ( ResourceClassRule . java : 108 )
at com . sun . jersey . server . impl . uri . rules . RightHandPathRule . accept ( RightHandPathRule . java : 147 )
at com . sun . jersey . server . impl . uri . rules . RootResourceClassesRule . accept ( RootResourceClassesRule . java : 84 )
at com . sun . jersey . server . impl . application . WebApplicationImpl . _handleRequest ( WebApplicationImpl . java : 1469 )
at com . sun . jersey . server . impl . application . WebApplicationImpl . _handleRequest ( WebApplicationImpl . java : 1400 )
at com . sun . jersey . server . impl . application . WebApplicationImpl . handleRequest ( WebApplicationImpl . java : 1349 )
at com . sun . jersey . server . impl . application . WebApplicationImpl . handleRequest ( WebApplicationImpl . java : 1339 )
at com . sun . jersey . spi . container . servlet . WebComponent . service ( WebComponent . java : 416 )
at com . sun . jersey . spi . container . servlet . ServletContainer . service ( ServletContainer . java : 537 )
at com . sun . jersey . spi . container . servlet . ServletContainer . service ( ServletContainer . java : 708 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 770 )
at org . apache . catalina . core . StandardWrapper . service ( StandardWrapper . java : 1542 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 281 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 175 )
at org . apache . catalina . core . StandardPipeline . doInvoke ( StandardPipeline . java : 655 )
at org . apache . catalina . core . StandardPipeline . invoke ( StandardPipeline . java : 595 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 161 )
at org . apache . catalina . connector . CoyoteAdapter . doService ( CoyoteAdapter . java : 331 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 231 )
at com . sun . enterprise . v3 . services . impl . ContainerMapper $ AdapterCallable . call ( ContainerMapper . java : 317 )
at com . sun . enterprise . v3 . services . impl . ContainerMapper . service ( ContainerMapper . java : 195 )
at com . sun . grizzly . http . ProcessorTask . invokeAdapter ( ProcessorTask . java : 849 )
at com . sun . grizzly . http . ProcessorTask . doProcess ( ProcessorTask . java : 746 )
at com . sun . grizzly . http . ProcessorTask . process ( ProcessorTask . java : 1045 )
at com . sun . grizzly . http . DefaultProtocolFilter . execute ( DefaultProtocolFilter . java : 228 )
at com . sun . grizzly . DefaultProtocolChain . executeProtocolFilter ( DefaultProtocolChain . java : 137 )
at com . sun . grizzly . DefaultProtocolChain . execute ( DefaultProtocolChain . java : 104 )
at com . sun . grizzly . DefaultProtocolChain . execute ( DefaultProtocolChain . java : 90 )
at com . sun . grizzly . http . HttpProtocolChain . execute ( HttpProtocolChain . java : 79 )
at com . sun . grizzly . ProtocolChainContextTask . doCall ( ProtocolChainContextTask . java : 54 )
at com . sun . grizzly . SelectionKeyContextTask . call ( SelectionKeyContextTask . java : 59 )
at com . sun . grizzly . ContextTask . run ( ContextTask . java : 71 )
at com . sun . grizzly . util . AbstractThreadPool $ Worker . doWork ( AbstractThreadPool . java : 532 )
at com . sun . grizzly . util . AbstractThreadPool $ Worker . run ( AbstractThreadPool . java : 513 )
at java . lang . Thread . run ( Thread . java : 662 )
erickles 16 de set. de 2012
Cara, me desculpe, mas o que tentou fazer?
erickles 17 de set. de 2012
Bom dia,
Dei uma boa vasculhada e achei um tutorial bem interessante, utilizando REST, eis o que fiz até agora:
public void run () {
// TODO Auto-generated method stub
//Minha thread que faz o login
loginActivity . getHandler (). post ( new Runnable (){
public void run () {
// TODO Auto-generated method stub
//try {
editLoginUser = loginActivity . getEditLoginUser ();
editLoginPassword = loginActivity . getEditLoginPassword ();
LoginResponse loginResponse = new LoginResponse ();
try {
Login ( Integer . parseInt ( editLoginUser . getText (). toString ()), encript ( editLoginPassword . getText (). toString ()));
} catch ( NumberFormatException e ) {
// TODO Auto-generated catch block
e . printStackTrace ();
} catch ( EncryptorException e ) {
// TODO Auto-generated catch block
e . printStackTrace ();
}
}
});
}
Aqui, o metodo que faz o login:
public LoginResponse Login ( int username , byte [] password )
{
SetLoginParameters ( username , password );
HttpClient httpclient = new DefaultHttpClient ();
HttpGet httpget = new HttpGet ( serviceAddress + loginParameters );
HttpResponse response ;
LoginResponse loginResponse = null ;
try
{
response = httpclient . execute ( httpget );
HttpEntity entity = response . getEntity ();
if ( entity != null )
{
InputStream instream = entity . getContent ();
String result = convertStreamToString ( instream );
JSONObject json = new JSONObject ( result );
// Parsing
JSONArray nameArray = json . names ();
JSONArray valArray = json . toJSONArray ( nameArray );
loginResponse = new LoginResponse ( valArray . getBoolean ( 1 ), valArray . getString ( 0 ), valArray . getString ( 2 ));
instream . close ();
}
}
catch ( Exception e )
{
loginResponse = new LoginResponse ();
String sDummy = e . toString ();
}
return loginResponse ;
}
Mas mesmo assim, falta algo, o login não esta sendo concluído...acredito que seja a password, pois a mesma é encriptada e também é um array de bytes. Alguém tem alguma luz?
erickles 17 de set. de 2012
Isso serviria para WCF?
O que pesquisei também é que há um modo de automaticamente, o eclipse “incorporar” os métodos do WebService e criar uma classe própria, alguém conhece?