以图片路径为参数的接口:
@GET
@Path("/vcardBean/{path}")
@Produces({"application/json","application/xml"})
public VCardBean getVCardBean(@PathParam("path") String path) {
//path ="D://1.png";
BufferedImage image = null;
try {
image = ImageIO.read(new File(path));
ImageTextService imageTextService = new ImageTextService();
String str = imageTextService.getImageText(image, "x.png", true);
System.out.println(str);
VCardBean vCardBean = new VCardBean();
vCardBean.setvCardStr(str);
vCardBean.dealVcardContent();
return vCardBean;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
客户端代码:
private static void testGet(final String format) {
BufferedImage image = null;
try {
image = ImageIO.read(new File(PATH));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
byte[] bytes = baos.toByteArray();
WebClient client = WebClient.create(CATEGORY_URL);
VCardBean vCardBean = client.path("/vtwservice/vcardBean/"+PATH).accept(format).type(format).get(VCardBean.class);
System.out.println(vCardBean.getvCardStr());
System.out.println("链接成功!!!");
} catch (IOException e) {
e.printStackTrace();
}
}