lundi 21 avril 2014

JAXB cannot handle an interface - what am I missing?


Vote count:

0




I'm getting familiar with web services in Java using Jax-ws (or JAXB, not sure, anyway...).


I've created small project with a single webservice. The WS has the only endpoint called transfer and returns objects inheriting ITransferResult interface.


Web service contract



//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface IBankWebSrv {
@WebMethod
ITransferResult transfer(String accountNumber, double amount);
}


Web service implementation



//Service Implementation
@WebService(endpointInterface = "Contracts.IBankWebSrv")
public class BankWebSrv implements IBankWebSrv {
@Override
public ITransferResult transfer(String accountNumber, double amount) {
ITransferResult result = new TransferResult();
// TODO logic here
result.setSuccessful(true);
return result;
}
}


TransferResult contract



@XmlJavaTypeAdapter(TransferResult.class)
public interface ITransferResult {
boolean isSuccessful();
void setSuccessful(boolean successful);
}


TransferResult implementation



public class TransferResult extends XmlAdapter<TransferResult, ITransferResult>
implements ITransferResult {

@XmlElement
boolean successful;

public boolean isSuccessful() {
return this.successful;
}

public void setSuccessful(boolean successful) {
this.successful = successful;
}

@Override
public TransferResult marshal(ITransferResult v) throws Exception {
return (TransferResult) v;
}

@Override
public ITransferResult unmarshal(TransferResult v) throws Exception {
return (ITransferResult) v;
}
}


When I publish my web service, I get the following error:



Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext...


Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions ITransferResult is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at ITransferResult



I've looked over SO for the answer and applied to the most repetitive tips, but none of them have worked for me yet.


What am I missing?



asked 22 secs ago






Aucun commentaire:

Enregistrer un commentaire