gcube-cms-suite/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ResponseCommons.java

22 lines
729 B
Java
Raw Normal View History

2022-03-07 13:59:24 +01:00
package org.gcube.application.geoportal.client;
import org.gcube.application.geoportal.client.utils.Serialization;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.rmi.RemoteException;
public class ResponseCommons {
protected static<R> R check(Response resp, Class<R> clazz) throws IOException {
String resString=resp.readEntity(String.class);
if(resp.getStatus()<200||resp.getStatus()>=300)
throw new RemoteException("RESP STATUS IS "+resp.getStatus()+". Message : "+resString);
2022-03-10 18:15:10 +01:00
if(clazz.equals(String.class))
return (R) resString;
2022-03-07 13:59:24 +01:00
if(clazz!=null)
return Serialization.read(resString, clazz);
else return null;
}
}