cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Malisetti, Ramanjaneyulu" <Ramanjaneyulu.Malise...@ca.com>
Subject RE: No message body writer has been found.
Date Thu, 07 Jul 2011 11:43:01 GMT
Thank you.

Regards
Raman
-----Original Message-----
From: amazoone [mailto:amazoone@free.fr] 
Sent: Thursday, July 07, 2011 3:25 PM
To: users@cxf.apache.org
Subject: No message body writer has been found.

Hi !

I try to produce audio/x-mpeg.

I have a methode getRingTone() wich return a MediaResponse.
The Object MediaResponse contains a byte[] parameter.

If my methode return directly a byte[], i get the MP3 in my navigator
But
If my methode return directly a MediaResponse, i get the error below :

/No message body writer has been found for response class MediaResponse./



this is my code :


the code wich works perfectly :


/**
	 * Provides a service wich allows to get a specific waiting music
	 * @author mickaël.camelot
	 */
	@GET
	@Path("/media")
	@Produces("audio/x-mpeg")
	public byte[] getRingTone() {
		final String uri;
		byte[] mediaConverted = null;
		
		try {
			// Récupération du Business Media
			iMediaBusiness = (IMediaBusiness)
applicationContext.getBean(MEDIA_BUSINESS_IMPL);
			if (iMediaBusiness != null) {
				uri = iMediaBusiness.findMediaUri();
			} else {
				uri = StringUtils.EMPTY_STRING;
			}
			
			// Vérification de l'URI
			if (!StringUtils.EMPTY_STRING.equals(uri)) {
				final java.io.File mediaFile = new File(uri);
				final FileInputStream mediaStream = new FileInputStream(mediaFile);
				mediaConverted = FileUtils.inputStreamToByteArray(mediaStream);
			} else {
				LOG.info("URI : " + uri);
				throw new Exception("getRingTone() -> Media non trouvé");
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
		}
		
		return mediaConverted ;
	}

 
now the code wich doesn't work


/**
	 * Provides a service wich allows to get a specific waiting music
	 * @author mickaël.camelot
	 */
	@GET
	@Path("/media")
	@Produces("audio/x-mpeg")
	public MediaResponse getRingTone() {
		final String uri;
		final MediaResponse response = newMediaResponse();
		final byte[] mediaConverted;
		
		try {
			// Récupération du Business Media
			iMediaBusiness = (IMediaBusiness)
applicationContext.getBean(MEDIA_BUSINESS_IMPL);
			if (iMediaBusiness != null) {
				uri = iMediaBusiness.findMediaUri();
			} else {
				uri = StringUtils.EMPTY_STRING;
			}
			
			// Vérification de l'URI
			if (!StringUtils.EMPTY_STRING.equals(uri)) {
				
				final java.io.File mediaFile = new File(uri);
				final FileInputStream mediaStream = new FileInputStream(mediaFile);
				mediaConverted = FileUtils.inputStreamToByteArray(mediaStream);
				
				response.setmedia(mediaConverted);
				response.setStatus("0");
				
			} else {
				LOG.info("URI : " + uri);
				throw new Exception("getRingTone() -> Media non trouvé");
			}
		} catch (Exception e) {
			LOG.error(e.getMessage());
			response.setStatus("1");
		}
		
		return response;
	}

and now my Class MediaResponse


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "status",
    "media"
})
@XmlRootElement(name = "MediaResponse")
public class MediaResponse {

    @XmlElement(required = true)
    protected String status;
    @XmlElement(required = true)
    protected byte[] media;

    /**
     * Gets the value of the status property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getStatus() {
        return status;
    }

    /**
     * Sets the value of the status property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setStatus(String value) {
        this.status = value;
    }

    /**
     * Gets the value of the media property.
     * 
     * @return
     *     possible object is
     *     byte[]
     */
    public byte[] getmedia() {
        returnmedia;
    }

    /**
     * Sets the value of the media property.
     * 
     * @param value
     *     allowed object is
     *     byte[]
     */
    public void setmedia(byte[] value) {
        this.media = ((byte[]) value);
    }

}

--
View this message in context: http://cxf.547215.n5.nabble.com/No-message-body-writer-has-been-found-tp4560538p4560538.html
Sent from the cxf-user mailing list archive at Nabble.com.
Mime
View raw message