進行POC過程發現如果XML不是檔案,而是字串,JDOM如何去parse? 這以前晃兄有教過一次。
StringReader sr = new StringReader(xmlString);
Document doc = builder.build(sr);
Failed to load JavaHL Library.
These are the errors that were encountered:
no libapr-1 in java.library.path
no libapriconv-1 in java.library.path
D:\Soft\Ruby\bin\libeay32.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
D:\Soft\Ruby\bin\ssleay32.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
no libaprutil-1 in java.library.path
no libsasl in java.library.path
no libsvn_subr-1 in java.library.path
no libsvn_delta-1 in java.library.path
no libsvn_diff-1 in java.library.path
no libsvn_wc-1 in java.library.path
no libsvn_fs-1 in java.library.path
no libsvn_repos-1 in java.library.path
no libsvn_ra-1 in java.library.path
no libsvn_client-1 in java.library.path
no libsvnjavahl-1 in java.library.path
no svnjavahl-1 in java.library.path
no svnjavahl in java.library.path
java.library.path = …
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props);
session.setDebug(this.debug);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(this.from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(this.recipients));
msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(this.copyTos));
msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(this.blindCopyTo));
msg.setSubject(mailSubject,"UTF-8"); // 主旨轉UTF-8
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(this.mailContent, "text/html;charset=UTF-8");
mp.addBodyPart(mbp);
msg.setContent(mp);
msg.setContent(this.mailContent, "text/html;charset=UTF-8");
msg.setText(this.mailContent);
msg.setSentDate(new Date());
Transport.send(msg);
Transport transport = session.getTransport("smtp");
transport.connect(this.host, "", ""); // this.username, this.password);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props);
session.setDebug(this.debug); // boolean
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(this.from)); // 寄件者
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(this.recipients));
msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(this.copyTos));
msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(this.blindCopyTo));
msg.setSubject(this.mailSubject); // 標題
msg.setText(this.mailContext); // 內容
msg.setSentDate(new Date());
Transport transport = session.getTransport("smtp");
transport.connect(this.host, "", ""); // this.username, this.password);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
XMLOutputter outputter = new XMLOutputter();
String xml = outputter.outputString(element);
XMLOutputter outputter = new XMLOutputter();
fos = new FileOutputStream(filename);
Document doc = new Document(element.detach());
outputter.output(doc, fos);
fos.flush();
fos.close();
XMLOutputter outputter = new XMLOutputter();
fos = new FileOutputStream(filename);
Element root = new Element("root");
Document doc = new Document(root);
root.addContent(element.detach());
outputter.output(doc, fos);
fos.flush();
fos.close();
<dependency> <!-- 2008/4/15 -->
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- JSON -->
<dependency> <!-- 2009/7/11 -->
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<classifier>jdk15</classifier> <!-- 用於JDK 1.5 -->
</dependency>
public abstract class AbstractBaseDao<T> {
// … 略
protected RowMapper<T> getRowMapper() {
return ParameterizedBeanPropertyRowMapper.newInstance(T); // Error
}
}
Class clazz = (Class) ((java.lang.reflect.ParameterizedType)
getClass().getGenericSuperclass()
).getActualTypeArguments()[0];
估計0是第一個泛型,若有第二個則以此類推。而好像可以用java.lang.reflect.Type代替Class去接
public static<T> T getT(Class<T> clazz) throws Exception {
T obj = ac.getBean(clazz);
return obj;
}
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Call;
import javax.xml.namespace.QName;
import java.net.URL;
public class WsClient {
public static void main(String[] args) throws Exception {
String urlstr = "https://…/Security.asmx?wsdl"; // 後面加?wsdl
URL url = new URL(urlstr);
String ns = "http://tempuri.org/";
QName qname = new QName(ns, "Security"); // 查wsdl檔的<wsdl:service>的name屬性
QName port = new QName(ns, "SecuritySoap"); // 查wsdl檔的<wsdl:portType>的name屬性
QName operation = new QName(ns, "getConnection"); // 查wsdl檔的<wsdl:operation>的name屬性
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(url, qname);
Call call = service.createCall(port, operation);
System.out.println("output:" + call.invoke(new Object[] {"UserID", "Password"}));
}
}
import java.net.URL;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class DotNetWebService {
public static void main(String[] args) throws Exception {
String method = "getConnection";
Service service = new Service(
new URL("https://…/Security.asmx?wsdl"),
new QName("http://tempuri.org/", "Security"));
String ns = "http://tempuri.org/";
QName port = new QName(ns, "SecuritySoap");
QName operation = new QName(ns, "getConnection");
Call call = (Call) service.createCall(port, operation);
String ret = (String)call.invoke(new String[]{{"UserID", "Password" });
System.out.println(ret);
}
}