Muleã§ã¡ã¼ã«éä¿¡ã®WEBãµã¼ãã¹ãèµ·åãã¦ã¿ã
æ¨æ¥ã®Muleã®ç¶ãã§ãã
æ¢åã®Javaè³ç£ãããã°ãMuleã使ç¨ãããã¨ã§Happyã«ãªãããããï¼ã®ã§ãã¡ã¼ã«ã®éä¿¡ããã°ã©ã ã¨ããJavaã®è³ç£ãããã¨ä»®å®ãã¦ãã©ãã ãã®æéã§WEBãµã¼ãã¹ãæä¾ã§ããã試ãã¦ã¿ã¾ãããã¾ãã¯ã以ä¸ã®ãããªã¡ã¼ã«éä¿¡ç¨ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®ç¾©ãã¾ãã
package jp.co.jsol.basis.sample.mule; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public interface IMailTransfer { @WebResult(name="result") public String SendMail( ãããã@WebParam(name="address") String address, ãã@WebParam(name="fromAddress") String fromAddress, ãã@WebParam(name="fromAddressName") String fromAddressName); }
次ã«å®è£ ãè¡ãã¾ãããã®å®è£ é¨åã¯å®éã«ã¯Javaã®è³ç£ãæµç¨ãã¾ããä»åã¯ãã®ã¾ã¾å®è£ ãã¦ãã¾ã£ã¦ãã¾ããã
public class MailTransfer implements IMailTransfer{ public String SendMail(String address, String fromAddress, String fromAddressName) { Properties objPrp = new Properties(); objPrp.put("mail.smtp.host", "192.168.0.1"); // SMTPãµã¼ãå objPrp.put("mail.host", "192.168.0.1"); // æ¥ç¶ãããã¹ãå // ã¡ã¼ã«ã»ãã·ã§ã³ãç¢ºç« Session session = Session.getDefaultInstance(objPrp, null); // éä¿¡ã¡ãã»ã¼ã¸ãçæ MimeMessage objMsg = new MimeMessage(session); String ret = "NG"; try { // éä¿¡å ï¼TOã®ã»ããCCãBCCãè¨å®å¯è½ï¼ objMsg.setRecipients(Message.RecipientType.TO,address); // Fromããã InternetAddress objFrm = new InternetAddress(fromAddress, fromAddressName); objMsg.setFrom(objFrm); objMsg.setSubject("ã¡ã¼ã«ãã¹ã", "ISO-2022-JP"); // 件å objMsg.setText("ããã«ã¡ã¯", "ISO-2022-JP"); // æ¬æ Transport.send(objMsg);//ã¡ã¼ã«éä¿¡ ret = new String("OK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } return ret; } }
æå¾ã«Muleèµ·åç¨ã®XMLå®ç¾©ãæ¸ãã¾ããããã§ã¯ããã¡ã¤ã«åãmail-config.xmlã¨ãã¾ããï¼âé©å½ãªååã§OKï¼
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.2" xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.2" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd http://www.mulesource.org/schema/mule/axis/2.2 http://www.mulesource.org/schema/mule/axis/2.2/mule-axis.xsd http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd"> <model name="mailSample"> <service name="MailUMO"> <inbound> <axis:inbound-endpoint address="http://localhost:65081/services"> <soap:http-to-soap-request-transformer/> </axis:inbound-endpoint> </inbound> <component class="jp.co.jsol.basis.sample.mule.MailTransfer"> <method-entry-point-resolver> <include-entry-point method="SendMail" /> </method-entry-point-resolver> </component> </service> </model> </mule>
ã³ãã³ãããã³ãããã以ä¸ã®ããã«æã¡è¾¼ã¿ã¾ãã
ããã¨ä»¥ä¸ã®ããã«Muleãèµ·åãã¾ãã
C:\> mule -config mail-config.xml
試ãã«Webãã©ã¦ã¶ã§ãXMLå®ç¾©ã§æå®ããURL+ãµã¼ãã¹å+?wsdlï¼http://localhost:65081/services/MailUMO?wsdlï¼ã«ã¢ã¯ã»ã¹ãã¦ã¿ãã¨ã以ä¸ã®ããã«WSDLãåå¾ã§ãã¾ãã