| | |
| | | package org.springblade.mdm.commons.service; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.cxf.transport.http.HTTPConduit; |
| | | import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.apache.cxf.endpoint.Client; |
| | |
| | | |
| | | public void send(String fromid,String toids, String ccids, String bccids, String subject, String content, String[] paths) { |
| | | try { |
| | | |
| | | // 创建动态客户端工厂 |
| | | JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); |
| | | |
| | |
| | | //Client client = dcf.createClient("http://localhost:8080/services/EmailService?wsdl"); |
| | | Object[] result; |
| | | try (Client client = dcf.createClient(internalEmailProperties.getMailServiceAddr())) { |
| | | // 获取 HTTPConduit 并配置策略 |
| | | HTTPConduit conduit = (HTTPConduit) client.getConduit(); |
| | | HTTPClientPolicy policy = new HTTPClientPolicy(); |
| | | |
| | | // 设置连接超时(毫秒) |
| | | policy.setConnectionTimeout(10000); |
| | | // 设置接收响应超时(毫秒) |
| | | policy.setReceiveTimeout(10000); |
| | | // 设置重传次数 |
| | | policy.setMaxRetransmits(2); |
| | | conduit.setClient(policy); |
| | | |
| | | // 调用方法 |
| | | result = client.invoke("sendInternalMail", fromid, toids, ccids, bccids, subject, content, null); |
| | | |
| | | // 处理响应 |
| | | if (result != null && result.length > 0) { |
| | | System.out.println("响应: " + result[0]); |
| | | log.info("发送邮件响应:{} " ,result[0]); |
| | | } |
| | | } |
| | | }catch(Exception e) { |