You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Greg Holmberg (JIRA)" <ji...@apache.org> on 2012/06/07 01:19:23 UTC

[jira] [Commented] (CXF-3722) Generic interface and Implementation

    [ https://issues.apache.org/jira/browse/CXF-3722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13290577#comment-13290577 ] 

Greg Holmberg commented on CXF-3722:
------------------------------------

I tried to do something similar with JAX-RS and JAXB.  I found myself writing the same CRUD service code (create, get/query, update, delete) over and over again, for one POJO and then another.  The code was nearly identical in each case.  I thought, what a waste of time--I should write a generic CRUD service, and then instantiate it for each POJO.  For example:

@XmlType
public interface NamedObject {
    @XmlAttribute
    public String getName();
}

abstract class NamedObjectService<NamedObjectType extends NamedObject> {
    @PUT
    @Consumes("application/xml")
    public Response create(NamedObjectType object) { ... }
}

@XmlRootElement
public class MyPOJO implements NamedObject { ... }

@Path("/myservice")
public class MyService extends NamedObjectService<MyPOJO> { ... }


I wrote a proxy-based client (i.e. using the magic CGLib), and when I called MyService.create(), I got this exception:

Caused by: org.apache.cxf.jaxrs.client.ClientWebApplicationException: .No message body writer has been found for class : interface com.blah.NamedObject, ContentType : application/xml;charset=utf-8.
	at org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:611)
	at org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:409)
	at org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:640)

So it didn't find the JAXB code to marshall MyPOJO.

It's a shame.  It would save me so much time if I didn't have to copy and paste this code for each CRUD service.

I don't know if this is an issue for JAX-RS or for JAXB, but would it be possible to support this in CXF?

Thanks,

Greg
                
> Generic interface and Implementation
> ------------------------------------
>
>                 Key: CXF-3722
>                 URL: https://issues.apache.org/jira/browse/CXF-3722
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: CXF 2.2.6
> JAVA 6 
> Windows XP
> Tomcat 6 
> Code First
>            Reporter: Deboschère Tony
>            Assignee: Daniel Kulp
>            Priority: Minor
>             Fix For: Invalid
>
>
> I ve createad a Generic interface, let say IGenericInterface<TYPE extends MyAbstracTypeOne, TYPE2 extends MyAbstractTypeTwo>
> In this interface  are some méthode like : 
> public TYPE getTypeFromType2(TYPE2);
> In another interface I extends IGenericInterface
> and add some specific methods 
> ex : 
> @WebService
> ISpecificInterface extends IgenericInterface<MySubTypeOne, MySubTypeTwo> {
> @WebMethod
> public MySubTypeOne getTest();
> }
> When I implement ISpecificInterface in an implementation class, then add the @Webservice @WebResult and other @WebParam  and launch my server 
> I do see a web service with two methods in the wsdl
> getTest and getTypeFromType2.
> But the second method returns xml corresponding to the abstractType MyAbstracTypeOne and not MySubTypeOne
> PS : I launch the webservice serverside via : 
> Object webServiceImpl = webServiceClass.newInstance();
> Endpoint endpoint = Endpoint.create(webServiceImpl);
> endpoint.publish("/" + name);

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira