我正在使用jersey创建一个宁静的Web服务,该服务接受bigdecimal,bigdecimal和date作为输入。我从客户端传递了所有这三个作为String的字符串,并且在服务中我试图将它们转换为Bigdecimal和Date并将其发送给DB获取数据。
这是我的客户代码:
public class GenerateRaObjSiteCSVClient
{
public static final String BASE_URI = "http://localhost:8080/PegaBaseWebServices_ARND";
public static final String PATH_NAME = "/GenerateCSV/";
public static final String PATH_ADDRESS = "/GenerateCSV/";
public static void main( String[] args)
{
BigDecimal radioObjId = new BigDecimal( 10000);
BigDecimal suchId = new BigDecimal( 9090);
String cutOffDate = "2007-06-27";
ClientConfig config = new DefaultClientConfig();
Client client = Client.create( config);
WebResource resource = client.resource( BASE_URI);
WebResource clientResource = resource.path( "rest").path( PATH_NAME)
.queryParam( "radioObjId", radioObjId.toString()).queryParam( "suchId", suchId.toString())
.queryParam( "cutOffDate", cutOffDate);
System.out.println( "Client Response \n" + getClientResponse( clientResource));
}
/**
* Returns client response as:- GET http://localhost:8080/ARNDWebServices/rest/GetExampleService/name/Arun
*
* @param service
* @return
*/
private static String getClientResponse( WebResource resource)
{
System.out.println( resource);
return resource.accept( "text/csv").get( ClientResponse.class).toString();
}
这是服务:
@GET
@Produces( "text/csv")
public Response getData( @QueryParam( "radioObjId") String radioObjId, @QueryParam( "suchId") String suchId,
@QueryParam( "cutOffDate") String cutOffDate)
{
String errValue = null;
BigDecimal radObjID = new BigDecimal( radioObjId);
BigDecimal suchID = new BigDecimal( suchId);
RadioObjectDAO radioObjectDAO = new RadioObjectDAO();
DateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd");
try
{
Date parsedDate = formatter.parse( cutOffDate);
dataList = radioObjectDAO.getCSVData( radObjID, suchID, SqlUtil.DBDatum( parsedDate));
}
catch (ParseException e1)
{
e1.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
所以我的问题是这是否是处理请求和验证错误输入(对于日期和大十进制都适用)的正确方法。 处理疯狂的日期格式和大十进制输入的最佳方法是什么