Hallo Leute!
Ich scheitere an einem Mini-Projekt das sich eigentlich gar nicht kompliziert anhört: Ein simpler Webshop soll programmiert werden, der Produkte beinhaltet und Kunden sollen Waren anzeigen bzw. in den Warenkorb legen können. Realisiert soll der Shop als WebService werden, mittels Client greifen "Kunden" darauf zu
Kein Problem denk ich mir zuerst und code los:
Das ganze wollte ich in meiner Eclipse-Umgebung als "Web Service" veröffentlichen, klick also mit rechter Maustaste auf die Datei und es öffnet sich der Web Service Wizard. Klick auf "Next" um das Webservice zu erstellen und ... FEHLER
Warum? Wieso? Ich versteh es nicht... Product hat doch einen public Constructor. Ich steh auf der Leitung ???:L Kann mir jemand weiterhelfen?
Danke im Vorraus!
Ich scheitere an einem Mini-Projekt das sich eigentlich gar nicht kompliziert anhört: Ein simpler Webshop soll programmiert werden, der Produkte beinhaltet und Kunden sollen Waren anzeigen bzw. in den Warenkorb legen können. Realisiert soll der Shop als WebService werden, mittels Client greifen "Kunden" darauf zu
Kein Problem denk ich mir zuerst und code los:
Java:
package org;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
class Product {
String name;
int price;
int id;
String eigenschaften;
public Product(String name, int price, int id, String eigenschaften) {
this.name = name;
this.price = price;
this.id = id;
this.eigenschaften = eigenschaften;
}
}
@WebService(targetNamespace = "http://org/", portName = "WebshopPort", serviceName = "WebshopService")
public class Webshop {
protected static Product[] produktarray = new Product[5];
@WebMethod(operationName = "erzeuge", action = "urn:Erzeuge")
@RequestWrapper(className = "org.jaxws.Erzeuge", localName = "erzeuge", targetNamespace = "http://org/")
@ResponseWrapper(className = "org.jaxws.ErzeugeResponse", localName = "erzeugeResponse", targetNamespace = "http://org/")
public void erzeuge() {
produktarray[0] = new Product("DVD", 20, 1, "Brachialkomödie");
produktarray[1] = new Product("Buch", 20, 2, "Quine - Grundzüge der Logik");
produktarray[2] = new Product("Spielzeug", 50, 3, "LEGO");
produktarray[3] = new Product("Schmuck", 100, 4, "Swarovski");
produktarray[4] = new Product("TV", 999, 5, "Philips 3D");
}
@WebMethod(operationName = "showPrice", action = "urn:ShowPrice")
@RequestWrapper(className = "org.jaxws.ShowPrice", localName = "showPrice", targetNamespace = "http://org/")
@ResponseWrapper(className = "org.jaxws.ShowPriceResponse", localName = "showPriceResponse", targetNamespace = "http://org/")
public int showPrice(@WebParam(name = "arg0") String name) {
int i=0;
for(;i<produktarray.length;i++) {
if((produktarray[i].name).equals(name)) {
break;
}
}
Product obj = produktarray[i];
return obj.price;
}
@WebMethod(operationName = "showEigenschaften", action = "urn:ShowEigenschaften")
@RequestWrapper(className = "org.jaxws.ShowEigenschaften", localName = "showEigenschaften", targetNamespace = "http://org/")
@ResponseWrapper(className = "org.jaxws.ShowEigenschaftenResponse", localName = "showEigenschaftenResponse", targetNamespace = "http://org/")
public String showEigenschaften(@WebParam(name = "arg0") String name) {
int i=0;
for(;i<produktarray.length;i++) {
if((produktarray[i].name).equals(name)) {
break;
}
}
Product obj = produktarray[i];
return obj.eigenschaften;
}
@WebMethod(operationName = "listAll", action = "urn:ListAll")
@RequestWrapper(className = "org.jaxws.ListAll", localName = "listAll", targetNamespace = "http://org/")
@ResponseWrapper(className = "org.jaxws.ListAllResponse", localName = "listAllResponse", targetNamespace = "http://org/")
public Product[] listAll() {
return produktarray;
}
@WebMethod(operationName = "getProduct", action = "urn:GetProduct")
@RequestWrapper(className = "org.jaxws.GetProduct", localName = "getProduct", targetNamespace = "http://org/")
@ResponseWrapper(className = "org.jaxws.GetProductResponse", localName = "getProductResponse", targetNamespace = "http://org/")
public Product getProduct(@WebParam(name = "arg0") String name) {
int i=0;
for(;i<produktarray.length;i++) {
if((produktarray[i].name).equals(name)) {
break;
}
}
Product obj = produktarray[i];
return obj;
}
}
Das ganze wollte ich in meiner Eclipse-Umgebung als "Web Service" veröffentlichen, klick also mit rechter Maustaste auf die Datei und es öffnet sich der Web Service Wizard. Klick auf "Next" um das Webservice zu erstellen und ... FEHLER
The value type "org.Product" used via the service class "org.Webshop" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.
Warum? Wieso? Ich versteh es nicht... Product hat doch einen public Constructor. Ich steh auf der Leitung ???:L Kann mir jemand weiterhelfen?
Danke im Vorraus!