|
GettingStarted
Any issue,question or suggestion post in JSON Group. Getting started with JSON Web Service1) Overview JSON web service is focused towards developing web service with JSON as input and output format. Also existing web service can be accessed using JSON.2) Dependency
Other default development tools (Ant java and tomcat) 3) Installation
2) JAX-WS/Metro installation,Download jax-ws from https://jax-ws.dev.java.net/ and copy all .jars located from EXTRACT_ROOT/lib into your application's /WEB-INF/lib directory. (optionaly you can ignore -tools.jar,-extra.jar) Note : installation of Java 1.5 ant and tomcat refer in relevant sites.4) Creating hello world
(For eclipse webtools users dynamic webproject create it for you)
2) Now follow up installation procedure described in previous step 3. Its simply copying jar files into your WEB-INF/lib folder.In case of if your using metro, all jax-ws jars named as webservices-.jar. In case if your using Java webservice developer pack your jar name looks like jax-.jar, saaj.jar, etc After installation procedure your file structure looks something like, 3) web.xml update.Now open your helloWorld/WebContent/WEB-INF/web.xml and jax-ws specific following servlet entry.<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <listener> <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> </listener> <servlet> <servlet-name>JAX-WS-Service</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JAX-WS-Service</servlet-name> <url-pattern>/json/*</url-pattern> </servlet-mapping> <!-- OPTIONAL IF YOU ALSO LIKE TO USE SOAP --> <servlet-mapping> <servlet-name>JAX-WS-Service</servlet-name> <url-pattern>/soap/*</url-pattern> </servlet-mapping> </web-app> 4) sun-jaxws.xml update.Now open your helloWorld/WebContent/WEB-INF/sun-jaxws.xml and hello world specific implementation entry.5) Creating HelloWorldImpl.<?xml version="1.0" encoding="UTF-8"?> <endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" > <endpoint name="HelloService" implementation="com.mycompany.HelloWorldImpl" url-pattern="/json/hello" binding="http://jsonplugin.googlecode.com/json/"/> <!-- OPTIONAL IF YOU ALSO LIKE TO USE SOAP --> <endpoint name="HelloServiceSOAP" implementation="com.mycompany.HelloWorldImpl" binding="http://schemas.xmlsoap.org/wsdl/soap/http" url-pattern="/soap/hello" /> </endpoints>Now create folders com/mycompany under src directory. And create HelloWorldImpl.java file. In HelloWorldImpl.java add your methods,
NOTE: @SOAPBinding(style = SOAPBinding.Style.RPC) annotation is required, Document binding NOT tested with this JSON codec. 6) BuildTo build war creates ant build.xml inside workspace/helloWorld folder. Following are the content of build.xml
7) Run the ant build.xml . You may down load pre build war from here http://jsonwebservice.googlecode.com/svn/trunk/demos/helloWorld/helloWorld.war 8) Now you can see the helloWorld.war inside workspace/helloWorld. 9) Now copy the way file into tomcat webapps folder or use tomcat manager console to deploy it.
|
hi ,
I am downloaded this application war file.After that i copied in tomcat 1.5 webapp directory.when ever i started server i got .class file bad version message coming.please let me know reason of this. webservices-api.jar file got error message.how can i get new jar. thanks,
subrahmanyam k
Hi subrahmanyam k,
Please check your java version.Hi there,
I followed your guide and create json webservice successfully, and now I want to call this json ws from jQuery library by using getJSON() method, can you give me some piece of code demonstrating this?
Thank you.
Hi,
Anyone know how to put array or wrapped array parameter on JSON request? I tried but always get null array or wrapped array parameter from the Web Method.
Thanks.
For array issue check comment in http://code.google.com/p/jsonwebservice/issues/detail?id=20&can=1
If your looking for support or having problem with this codec please post your query in google group http://groups.google.com/group/jsonwebservice
I could be wrong, but step 3) Installation could be a lot easier if using Maven for dependency injection.
Maven avaiable in https://oss.sonatype.org/content/repositories/releases/com/googlecode/jsonwebservice/jsonwebservice-ri/0.8.0/jsonwebservice-ri-0.8.0.jar
we will update getting started with maven soon.
Hi. i have followed your tutorial very neatly. The problem is that i am deploying in glassfish 4.1 i have included jsonwebservice-rt-0.7 in my web application but i keep getting the below error.
JAXBContextImpl context = (JAXBContextImpl)endPoint.getSEIModel().getJAXBContext();
Severe: caught throwable java.lang.NoSuchMethodError?: com.sun.xml.ws.api.model.SEIModel.getJAXBContext()Lcom/sun/xml/bind/api/JAXBRIContext;
Also i have tried differrent versions of the jsonwebservice jar file versions 0.5, 0.6, 0.7 and 0.8.0 and i have traced the error to be from line 83 of the
Kindly assist me in deploying to glassfish 4.1