22 lines
729 B
Java
22 lines
729 B
Java
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);
|
|
if(clazz.equals(String.class))
|
|
return (R) resString;
|
|
if(clazz!=null)
|
|
return Serialization.read(resString, clazz);
|
|
else return null;
|
|
}
|
|
}
|