67,515
社区成员
发帖
与我相关
我的任务
分享
@Service
public class TaskServiceImpl implements TaskService
{
private Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);
private HttpClient httpClient = null;
@Autowired
public TaskServiceImpl(TaskMappper taskMapper, Configure configure)
{
HttpParams params = new BasicHttpParams();
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
cm.setDefaultMaxPerRoute(50);
cm.setMaxTotal(50);
httpClient = new DefaultHttpClient(cm, params);
}
[Quote=引用 10 楼 wangmohan44 的回复:]@RequestMapping(value = "changeDocumentBookState", method = RequestMethod.POST)
public String changeDocumentBookState(@RequestParam("operator") int operator, @RequestParam("documentBookId") long documentBookId, HttpServletRequest request)
{
HttpSession session = request.getSession();
CPUser user = (CPUser)session.getAttribute(Constants.LOGIN_USER);
long cpId = user.getEntityID();
String usercodes =request.getParameter("usercodes");
MallInterfaceJson json =new MallInterfaceJson();
json.setCpid(cpId+"");
json.setMagid(documentBookId+"");
json.setItname(OperatorState.operatorStatus(operator).getName());
taskService.changeDocumentBookState(json);
}
public boolean changeDocumentBookState(MallInterfaceJson json)
{
String targetUrl = configure.getMallInterfaceAddress()+configure.getMallIfGoods();// 接口地址
HttpUriRequest httpUriRequest = null;
try
{
httpUriRequest = new HttpPost(targetUrl);
String abc = mapper.writeValueAsString(json);
((HttpPost) httpUriRequest).setEntity(new StringEntity(abc, HTTP.UTF_8));
HttpResponse remoteResponse = this.httpClient.execute(httpUriRequest);
int responseState = remoteResponse.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK == responseState)
{
// 请求成功
HttpEntity responseEntity = remoteResponse.getEntity();
if (responseEntity != null)
{// 返回信息
String strEntity = EntityUtils.toString(responseEntity, HTTP.UTF_8);
JsonNode node = mapper.readTree(strEntity);
String result =node.get("backstatus").toString();
result =result.substring(1,result.length()-1);
if (result.equalsIgnoreCase("1"))
{
return true;
}
}
}
} catch (Exception e)
{
e.printStackTrace();
logger.warn("调用接口失败{}", e.toString());
return false;
}
return false;
}
你参考参考可以试试