/**
  * Ensures that the response has a "success" status code {@code 2xx}.
  *
  * @throws HttpResponseException if the response does not have a {@code 2xx} status code
  * @throws IOException if the response entity parsing has failed
  */
 public void ensure2xxStatus() throws HttpResponseException, IOException {
   if (response.getStatus() / 100 != 2) {
     final String message;
     if (MediaType.TEXT_PLAIN_TYPE.equals(response.getMediaType())) {
       message = response.readEntity(String.class);
     } else if (MediaType.TEXT_XML_TYPE.equals(response.getMediaType())
         || MediaType.APPLICATION_XML_TYPE.equals(response.getMediaType())
         || MediaType.APPLICATION_JSON_TYPE.equals(response.getMediaType())) {
       message = response.readEntity(AcknowlegementType.class).getMessage();
     } else {
       message = response.toString();
     }
     throw new HttpResponseException(response.getStatus(), message);
   }
 }
 @Override
 public String marshal(Object obj, MediaType mediaType)
     throws MarshalException, UnsupportedMediaTypeException {
   if (mediaType != null) {
     if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)
         || MediaType.TEXT_XML_TYPE.isCompatible(mediaType)) {
       return marshalToXML(obj);
     } else if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
       return marshalToJSON(obj);
     }
   }
   // If we get here then we deal with an unknown media type
   throw new UnsupportedMediaTypeException(
       "Unsupported media type: "
           + mediaType
           + ". Cannot marshal the given input to this media type.");
 }
  /* (non-Javadoc)
   * @see sif3.infra.common.conversion.UnmarshalFactory#unmarschal(java.lang.String, java.lang.Class, javax.ws.rs.core.MediaType)
   */
  @Override
  public Object unmarshal(String payload, Class<?> clazz, MediaType mediaType)
      throws UnmarshalException, UnsupportedMediaTypeException {
    if (mediaType != null) {
      //			if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType) ||
      // MediaType.TEXT_XML_TYPE.isCompatible(mediaType)  ||
      //	MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType))
      if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)
          || MediaType.TEXT_XML_TYPE.isCompatible(mediaType)) {
        return unmarshalFromXML(payload, clazz);
      } else if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
        return unmarshalFromJSON(payload, clazz);
      }
    }

    // If we get here then we deal with an unknown media type
    throw new UnsupportedMediaTypeException(
        "Unsupported media type: "
            + mediaType
            + ". Cannot unmarshal the given input from this media type.");
  }