锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
璁劇疆鐜鍙橀噺MAVEN_OPTS=-Xms64m -Xmx128m -Dfile.encoding=UTF-8
2.榪愯mvn test鏃朵貢鐮侊紙IDE涓婅繍琛孴estCase鏃禣K錛屼絾鏄繍琛宮aven test涔辯爜,緇撴灉嫻嬭瘯涓嶉氳繃錛変慨鏀筽om.xml澧炲姞濡備笅鍐呭鍗沖彲
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>target/cobertura/cobertura.ser</value>
</property>
</systemProperties>
</configuration>
</plugin>
]]>
綞撻亷鍒嗘瀽鏁寸悊錛屾垜鍊戠櫦鐝懼晱欏屽嚭鍦?QueryString 鐨勮В鏋愶紝浠ュ墠鍦?Tomcat 4.x 鏅備唬錛岀劇璜?SUBMIT 鏅傛帯鐢?GET or POST錛孴omcat server 灝?parameters 鐨勮檿鐞嗛兘鎺$敤鐩稿悓鐨勭法紕鹼紝浣嗗湪 Tomcat 5.x 鐗堬紝涓嶇煡浣曟晠錛屽嵒灝?QueryString 鐨勮В鏋愮崹绔嬪嚭渚嗭紝鐩墠紕鴻獚錛孎orm 鐨?Method 鎺$敤 GET 鍙婄洿鎺ュ皣鍙冩暩瀵湪 URL 涓婄殑涓枃錛屼笂鍌沖埌 Tomcat 鏅傦紝鐒¤珫濡備綍杞夌⒓錛岄兘鏈冭畩鎴愪簜紕鹼紝閭f曚綘浜嬪厛浣滈亷 URLEncode 涔熶竴妯c?br/>
綞茬珯涓婏紝鏈変漢閲濆皪閫欏嬪晱欏岋紝寤鴻灝囨墍鏈変腑鏂囨敼鎺$敤 base64 綬ㄧ⒓錛屽埌浜?server 涓婏紝紼嬪紡灝囪嚜琛屽湡 base64 decode 鍥炰締錛岀⒑淇濅腑鏂囦笉鏈冪櫦鐢熷晱欏屻傞欐ǎ浣滄硶鐣剁劧鍙互瑙f焙閫欏嬪晱欏岋紝浣嗘槸鎵鏈夌恫闋佽畩鎴愰檺瀹氳鎺$敤 POST錛屼笖紼嬪紡璦▓甯闅ㄦ檪鍒嗘竻妤氾紝閭e嬪弮鏁告槸鎺$敤 GET 涓婂偝錛岄偅鍊嬪弮鏁告槸鎺$敤 POST 涓婂偝錛岀劧寰屽啀閲濆皪涓嶅悓鐨勬柟寮忔帯鐢ㄤ笉鍚岀殑瑙f瀽錛岄欐ǎ鐨勭▼寮忎竴榛炲厭縐繪鎬ч兘娌掓湁錛屾洿鍒ユ彁璺ㄥ鉤鍙般佽法鍦嬮殯瑾炶█浜嗐?br/>
鐮旂┒ Tomcat 鐨勬枃浠跺強鍘熷紕鹼紝鎴戝戞壘鍒頒簡鍟忛鎵鍦ㄥ強瑙f焙鐨勬柟娉曪紝鍙湁鎸夎憲浠ヤ笅鐨勪綔娉曪紝鎵嶈兘浣?Form submit 鐨勮硣鏂欏畬鍏ㄦ寜钁?ISO8859-1 鐨勭法紕鹼紝鐣剁劧錛岃嫢鏄叏鐓ц憲 Tomcat 鐨勬枃浠惰鏄庡幓浣滐紝鑲畾閭勬槸涓嶈錛屼綘閭勬槸寰楀姞涓婇欏嬪弮鏁稿埌 server.xml 涓墠琛屻?br/>
瑙f焙鏂規
璜嬪厛鐮旂┒ $TOMCAT_HOME/webapps/tomcat-docs/config/http.html 閫欏嬭鏄庢獢錛屾摲閷勯噸榛炲涓嬶細
URIEncoding錛歍his specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
useBodyEncodingForURI錛歍his specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding. This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitely set using Request.setCharacterEncoding method was also used for the parameters from the URL. The default value is false.
涓婅堪浜屽?Tomcat 鍙冩暩錛屾槸璦畾鍦?server.xml 涓殑 http <Connector /> 鍗濉婏紝瑕佽В姹?QueryString 涓枃璁婃垚浜傜⒓鐨勫晱欏岋紝浣犲繀闋堣嚦灝戣ō瀹氶欎簩鍊嬪弮鏁稿叾涓箣涓銆?br/>URIEncoding 璜嬭ō瀹氱偤 URIEncoding="ISO-8859-1" 鎸囧畾鐐?"ISO-8859-1" 綬ㄧ⒓錛岃畵 QueryString 鐨勫瓧鍏冪法紕艱垏 post body 鐩稿悓銆?br/>useBodyEncodingForURI 閫欐槸鐢ㄤ締鐩稿 Tomcat 4.x 鐗堢殑錛岃ō瀹氱殑鍊兼槸 "true" or "false"錛屾剰鎬濇槸鎸?"瑕佷笉瑕佽畵 QueryString 鑸?POST BODY 鎺$敤鐩稿悓鐨勫瓧鍏冪法紕??"錛岃嫢鏄ō鎴?true錛岄偅涔熷彲閬斿埌 "ISO-8859-1" 綬ㄧ⒓鐨勯渶姹傘?br/>寤鴻錛屾帯鐢?URIEncoding 鐨勮ō瀹氾紝鐣㈢珶 useBodyEncodingForURI 鐨勪綔娉曟槸鐐轟簡鐩稿 Tomcat 4.X銆備笉閬庤嫢鐓у師鏂囩殑瑾槑錛岀悊璜栦笂閫欎簩鍊嬪弮鏁擱兘涓嶈ō錛孴omcat 涔熻┎鎺$敤 "ISO-8859-1" 鐨勭法紕鹼紝閭g偤浠楹奸倓鏄渻鏈夊晱欏屽憿 ? 鎴戝戠敱 Tomcat Source Code 渚嗙湅灝辨竻妤氫簡銆?br/>
1 |
// 閫欎竴孌電⒓鏄?Tomcat 鐢ㄤ締瑙?QueryString 鐨勭▼寮忥紝 // 鍦?org.apache.tomcat.util.http.Parameters 閫欏?class 瑁°?private String urlDecode(ByteChunk bc, String enc) throws IOException { if( urlDec==null ) { urlDec=new UDecoder(); } urlDec.convert(bc); String result = null; if (enc != null) { bc.setEncoding(enc); result = bc.toString(); } else { CharChunk cc = tmpNameC; cc.allocate(bc.getLength(), -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); for (int i = 0; i < bc.getLength(); i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } cc.setChars(cbuf, 0, bc.getLength()); result = cc.toString(); cc.recycle(); } return result; } |
1 |
<Connector debug="0" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="80" redirectPort="8443" enableLookups="false" minSpareThreads="25" maxSpareThreads="75" maxThreads="150" maxPostSize="0" URIEncoding="ISO-8859-1" > </Connector> |
鍒嗘瀽浜嗕竴涓媍ommons mail鐨勬簮鐮佹壘鍒頒簡鍘熷洜銆傛簮鐮佸涓?
public class SimpleEmail extends Email
{
public Email setMsg(String msg) throws EmailException, MessagingException
{
if (EmailUtils.isEmpty(msg))
{
throw new EmailException("Invalid message supplied");
}
setContent(msg, TEXT_PLAIN);
return this;
}
}
Email浠g爜鐗囨
public void setContent(Object aObject, String aContentType)
{
this.content = aObject;
if (EmailUtils.isEmpty(aContentType))
{
this.contentType = null;
}
else
{
// set the content type
this.contentType = aContentType;
// set the charset if the input was properly formed
String strMarker = "; charset=";
int charsetPos = aContentType.toLowerCase().indexOf(strMarker);
if (charsetPos != -1)
{
// find the next space (after the marker)
charsetPos += strMarker.length();
int intCharsetEnd =
aContentType.toLowerCase().indexOf(" ", charsetPos);
if (intCharsetEnd != -1)
{
this.charset =
aContentType.substring(charsetPos, intCharsetEnd);
}
else
{
this.charset = aContentType.substring(charsetPos);
}
}
}
}
email.send();鐨剆end鏂規硶灝嗚皟鐢?br/>public void buildMimeMessage() throws EmailException
{
try
{
this.getMailSession();
this.message = new MimeMessage(this.session);
if (EmailUtils.isNotEmpty(this.subject))
{
if (EmailUtils.isNotEmpty(this.charset))
{
this.message.setSubject(this.subject, this.charset);
}
else
{
this.message.setSubject(this.subject);
}
}
// ========================================================
// Start of replacement code
if (this.content != null)
{
this.message.setContent(this.content, this.contentType);
}
// end of replacement code
// ========================================================
else if (this.emailBody != null)
{
this.message.setContent(this.emailBody);
}
else
{
this.message.setContent("", Email.TEXT_PLAIN);
}
if (this.fromAddress != null)
{
this.message.setFrom(this.fromAddress);
}
else
{
throw new EmailException("Sender address required");
}
if (this.toList.size() + this.ccList.size() + this.bccList.size() == 0)
{
throw new EmailException(
"At least one receiver address required");
}
if (this.toList.size() > 0)
{
this.message.setRecipients(
Message.RecipientType.TO,
this.toInternetAddressArray(this.toList));
}
if (this.ccList.size() > 0)
{
this.message.setRecipients(
Message.RecipientType.CC,
this.toInternetAddressArray(this.ccList));
}
if (this.bccList.size() > 0)
{
this.message.setRecipients(
Message.RecipientType.BCC,
this.toInternetAddressArray(this.bccList));
}
if (this.replyList.size() > 0)
{
this.message.setReplyTo(
this.toInternetAddressArray(this.replyList));
}
if (this.headers.size() > 0)
{
Iterator iterHeaderKeys = this.headers.keySet().iterator();
while (iterHeaderKeys.hasNext())
{
String name = (String) iterHeaderKeys.next();
String value = (String) headers.get(name);
this.message.addHeader(name, value);
}
}
if (this.message.getSentDate() == null)
{
this.message.setSentDate(getSentDate());
}
if (this.popBeforeSmtp)
{
Store store = session.getStore("pop3");
store.connect(this.popHost, this.popUsername, this.popPassword);
}
}
catch (MessagingException me)
{
throw new EmailException(me);
}
}
鐢變唬鐮佸彲浠ョ煡閬撶函鏂囨湰鏂瑰紡鏈緇堣皟鐢ㄤ簡Java Mail鐨?br/>message.setContent(this.content, this.contentType);
content鏄唴瀹?br/>contentType鏄被鍨嬶紝濡倀ext/plain,
(鎴戜滑鍙互璇曡瘯鐩存帴鐢↗ava mail鍙戦偖浠訛紝璁劇疆鏂囨湰鍐呭涓嶄嬌鐢╯etText鏂規硶錛屼篃浣跨敤setContent("嫻嬭瘯", "text/plain")鏂瑰紡錛屼綘鍙互鐪嬪埌鍐呭涔熸槸涔辯爜)
鍏抽敭灝卞湪浜巘ext/plain錛屾垜浠敼鎴恡ext/plain;charset=gb2312錛宱k涔辯爜瑙e喅浜嗐傚湪commons mail鎴戜滑鐪婼impleEmail 綾諱腑setMsg鏂規硶璋冪敤鐨勫氨鏄?setContent(msg, TEXT_PLAIN);鎴戜滑鍙渶瑕佸皢Email綾諱腑鐨勫父閲廡EXT_PLAIN淇敼涓涓嬪姞鍏?charset=浣犵殑瀛楃闆?錛岄噸鏂版墦鍖卝ar錛岃繖鏍峰氨鍙互浜?br/>
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class TestMail {
public final static String SMTPSERVER = "smtp.163.com";
public final static String POPSERVER = "pop.163.com";
public final static String ACCOUNT = "test";
public final static String PWD = "test";
public final static String MAILADDR = "test@163.com";
public void sendMail(String to, String from, String subject, String body) throws AddressException, MessagingException {
Properties pro = System.getProperties();
pro.put("mail.smtp.host", SMTPSERVER);
pro.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(pro, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, InternetAddress.parse(to, false)[0]);
msg.setSubject(subject);
msg.setText(body);
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
Transport transport = session.getTransport("smtp");
System.out.println("connecting...");
transport.connect(SMTPSERVER, ACCOUNT, PWD);
System.out.println("Sending message");
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
}
public static void main(String[] args) {
TestMail test = new TestMail();
try {
test.sendMail(MAILADDR, MAILADDR, "test", "鎴戠殑涓涓祴璇?);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
鍦╡clipse涓嬪紑鍙戝熀浜巃xis鐨刉ebService鍏跺疄寰堢畝鍗曪紝浣嗕篃鏈変笉灝戞楠わ紝浠ヤ笅瀵規瘡涓楠よ繘琛岃鏄?/p>
/**
*
* @author honghao
* @axis.service scope = "Request" urn = "TestService"
*/
public class TestService {
/**
* @param name
* @axis.method
*/
public String test(String name){
return "hello " + name;
}
}
鍏朵腑@axis.service琛ㄧずTestService浣滀負鏈嶅姟綾伙紝@axis.method琛ㄧず杈撳嚭test()鏂規硶浣滀負WebService
4) 閰嶇疆xdoclet
鎵撳紑project->properties錛屽湪XDoclet Configurations涓坊鍔犱竴涓柊鐨勯厤緗紝鍙互浠繪剰鍙栧悕錛屾澶勪負"webservice"錛屽湪榪欎釜閰嶇疆涓坊鍔爀jbdoclet,鍦ㄥ叾涓啀娣誨姞fileset鐢ㄤ簬鎸囧畾瀵瑰摢浜涙枃浠舵墽琛寈doclet(瑕佹寚鏄庢枃浠剁殑璺緞)錛屽拰axisdeploy錛宎xisdeploy涓嶇敤榪涜浠諱綍璁劇疆銆傚湪ejbdoclet涓渶瑕佹寚瀹歞estdir鐢熺敤浜庢寚紺虹敓鎴愮殑鏂囦歡鎵鍦ㄧ殑璺緞銆?/span>
5) 榪愯xdoclet.鍙沖嚮欏圭洰宸ョ▼錛屾墽琛孯un Xdoclet鑿滃崟錛屽鏋滈厤緗病鏈夐敊璇殑璇濓紝搴旇鍦ㄧ洰鏍囪礬寰勪笅鐢熸垚deploy-TestService.xml,榪欐槸涓涓猘xis鐢ㄤ簬鐢熸垚server-config.wsdd鏂囦歡鐨勯儴緗叉枃浠躲?br/>榪欓噷闇瑕佹敞鎰忕殑鏄紝濡傛灉綾繪枃浠舵槸鏀懼湪鏌愪釜鍖呬笅鐨勬椂鍊欙紝鎴戞棤娉曠敓鎴?/span>deploy-TestService.xml鏂囦歡錛屼絾鏄皢綾繪枃浠舵斁鍦ㄦ牴璺緞涓嬪氨鍙互鐢熸垚浜嗭紝鍘熷洜涓嶅悕.
6) 鐢熸垚server-config.wsdd閮ㄧ講鏂囦歡.榪欎釜鏂囦歡鍏跺疄鏄敱axis鐨勪竴涓伐鍏風敓鎴愮殑錛屼絾鏄洿鎺ヨ繍琛岃繖涓伐鍏峰お楹葷儲錛屾墍浠ユ垜浠繕闇瑕佺敓鎴愪竴涓猘nt鏋勫緩鏂囦歡錛屼嬌鍏惰兘鑷姩鐢熸垚錛?br/>鍦╳eb欏圭洰鐨勬牴璺緞涓嬫柊寤篵uild.xml錛岃緭鍏ヤ互涓嬫枃鏈細
<?xml version="1.0" encoding="UTF-8"?>
<property name="axis_lib_path" value="${axis.lib}"/>
<property name="wsdl.dir" location="wsdl" />
<path id="axis.lib.path">
<fileset dir="${axis_lib_path}">
<include name="*.jar" />
</fileset>
</path>
<path id="project.classpath">
<pathelement location="wsdl"/>
</path>
<target name="deploy">
<java classname="org.apache.axis.utils.Admin" fork="true" dir="WEB-INF"> <!--dir瀵瑰簲鐢熸垚鏂囦歡鐨勪綅緗?->
<classpath refid="axis.lib.path" />
<arg value="server" />
<arg value="${wsdl.dir}/deploy-TestHandler.xml" /> <!--TestHandler瀵瑰簲涓婇潰鐨剎ml鏂囦歡鍚峊estService-->
</java>
</target>
</project>
娉ㄦ剰錛歸sdl鏄垰鎵嶇敓鎴愮殑deploy-TestService.xml鎵鍦ㄧ殑鐩綍,org.apache.axis.utils.Admin鏄痑xis鎻愪緵鐨勫伐鍏風被錛屽叾浠栬礬寰勮緗鏍規嵁瀹為檯欏圭洰榪涜閫傚綋璋冩暣銆?br/>淇濆瓨鍚庯紝鍙沖嚮build.xml鎵цRun->Ant 鏋勫緩錛屽鏋滈厤緗紜紝鍒欎細鍦╓EB-INF鐩綍涓嬬敓鎴恠erver-config.wsdd鏂囦歡
榪樻湁ant緙栬瘧鐨勬椂鍊欓渶瑕乤xis鐨刲ib銆?br/>
7) 浠塊燼xis鎻愪緵鐨剆ample宸ョ▼鍦╰omcat涓繘琛岄儴緗詫紝鍦ㄦ祻瑙堝櫒涓緭鍏?br/>http://localhost:8080/axis/services
浼氬垪鍑烘墍鏈夌殑WebService
杈撳叆http://localhost:8080/axis/services/TestService?wsdl
浼氳緭鍑虹浉搴旂殑wsdl鍐呭
鐒跺悗灝卞彲浠ョ敤鐩稿簲鐨勫伐鍏瘋繘琛屾祴璇曚簡銆?br/>