- This topic has 6 replies, 3 voices, and was last updated 15 years, 6 months ago by Karun.
-
AuthorPosts
-
kayak20012001MemberThis looks like an quick way to set-up a REST Web Service.
However, I have one question for example this tutorial webservice would require a separate network call to add each customer. Would it be possible to create a web service method using this wizard that would take multiple customers as an XML input element from a POST and still take advantage of JAXB to convert the list of Custoner entities from Java to XML and back.
Put another way I would need to be able to send the XML output of the call to
@GET
public List<Customer> getCustomers() {
List<Customer> customers = new ArrayList<Customer>();
customers.addAll(customerMap.values());
return customers;
}to a REST service to add mulitple Customers with one network call.
If this is possible could you please include source code like the tutorial for example here is the single Customer Add method,
@POST
@Path(“add”)
@Produces(“text/plain”)
@Consumes(“application/xml”)
public String addCustomer(Customer customer) {
int id = customerMap.size();
customer.setId(id);
customerMap.put(id, customer);
return “Customer ” + customer.getName() + ” added with Id ” + id;
}Thank you.
kayak20012001MemberIf this is not possible to do using the REST WebServices wizard could someone from Support please say so. I did create a separate class package com.myeclipseide.ws;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
//import java.util.Collection;
import java.util.List;@XmlRootElement
public class Customers {
public List<Customer> customerlist;}
and added the following to the CustomersResource. java file.
@POST
@Path(“addall”)
@Produces(“text/plain”)
@Consumes(“application/xml”)
public String addCustomers(Customers customers) {return “addCustomers webservice called!”;
}The List is not properly populated it only has one Customer object and the name and address are blank.
Thank you
kayak20012001MemberPerhaps this is NOT possible…here is some incentive for someone that has done this….
I’ll offer $50.00 via paypal
if someone has an answer that works with the MyEclipse REST Tutorial on how to POST multiple customers to the REST webservice by modifying the CustomerResource with the appropriate method.
Brian FernandesModeratorkayak,
Here is a small snippet that will help, replace your Customers class with this
@XmlRootElement public class Customers { @XmlElement(required = true) protected List<Customer> customer; public String toString() { if (customer == null) { return "no customers added"; } String rVal = ""; for (Iterator iterator = customer.iterator(); iterator.hasNext();) { Customer customer = (Customer) iterator.next(); rVal += customer.getName() + ", "; } return rVal; } }
The important lines are
@XmlElement(required = true) protected List<Customer> customer;
The code you added to CustomerResources is fine, you could call customers.toString() to see the names of the added customers.
Hope this helps!
kayak20012001MemberBrian,
Your the man! That was exactly what I was missing was the @XmlElement(required = true) on the List <Customer> in the Customers class.
I’ll certainly be buying the product now that I have this out of the way. If you give let me know which paypal account I’ll be happy to send you the $50.00 for answering my question.
Now all I need to do is get an answer to the one I posted on how to deploy this webservice to a standalone Tomcat and I’ll be a happy camper. I’ve tried copying the .war file that is created but get a 404 error. I even tried moving the files manually and copying all of the jar files for jersey that are included in the war file to the lib directory under the restdemo directory which is located in webapps on the standalone Tomcat install. No luck.
Thanks again
KarunMemberHello Brian/ Kayak,
I am facing a similar situation as Kayak did. I did what you told to kayak in your previous post. I did the same thing but to me I get an error.
Source not found for Class<T>.getDeclaredConstructors0(boolean) line: not available [native method]
can you please help ASAP.
Thanks,
Karun
KarunMemberHello Brian/ Kayak,
I made some changes and now I get this error.
SEVERE: Servlet.service() for servlet JAX-RS REST Servlet threw exception
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
com.siemens.ikm.cks.sqm.webservices.visits.ChartAbstractionResource$ChartAbstractions is a non-static inner class, and JAXB can’t handle those.
this problem is related to the following location:
at com.siemens.ikm.cks.sqm.webservices.visits.ChartAbstractionResource$ChartAbstractionsat com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:447)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:288)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1111)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:214)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext(AbstractJAXBProvider.java:199)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getJAXBContext(AbstractJAXBProvider.java:177)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:131)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:104)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:97)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:391)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:81)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityParamInInvoker.getParams(EntityParamDispatchProvider.java:99)
at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$TypeOutInvoker._dispatch(EntityParamDispatchProvider.java:136)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:154)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:543)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:502)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:493)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:308)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:314)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:239)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)@karun.anantharam wrote:
Hello Brian/ Kayak,
I am facing a similar situation as Kayak did. I did what you told to kayak in your previous post. I did the same thing but to me I get an error.
Source not found for Class<T>.getDeclaredConstructors0(boolean) line: not available [native method]
can you please help ASAP.
Thanks,
Karun -
AuthorPosts