public class XMLLoader extends Thread {
boolean success =false;
public XMLLoader(SoapConnection con, String xmlPath) {
try {
System.out.println("Laoding the XML...");
File file = new File(xmlPath);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);
String xmlString = null;
DOMSource domSource = new DOMSource(document);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
xmlString = writer.toString();
InboundCaseXmlResponse cResponse = con.LoadXmlCase(xmlString);
System.out.println("SOAP Response == "+cResponse);
if(cResponse.getHasErrors()== false)
{
success = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public boolean getStatus()
{
return success;
}
} ..
private static boolean loadXml(SoapConnection con, String xmlPath) {
boolean success =false;
FileInputStream file=null;
try {
System.out.println("Loading the XML...");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
file = new FileInputStream(xmlPath);
Document document = builder.parse(file);
System.out.println(document.hasChildNodes());
String xmlString = null;
DOMSource domSource = new DOMSource(document);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
xmlString = writer.toString();
InboundCaseXmlResponse cResponse = con.LoadXmlCase(xmlString);
System.out.println("SOAP Response == "+cResponse);
if(cResponse.getHasErrors()== false)
{
success = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
try{
file.close();
}
catch(Exception ex)
{
e.printStackTrace();
}
}
return success;
}
당신은 예외를 잡을 필요 캐치에 당신은 폴더를 오류 XML을 이동해야합니다. 문제의 코드를 업데이트하십시오. – vels4j
언어 또는 특정 기술을 명시하지 않았으므로 우리가 할 수있는 것은 추측입니다. 예외적 인 경우에 무언가가 적시에 정리되지 않을 가능성이 있습니다. 예를 들어,'finally' 블록이나'using' 절을 적절하게 사용하면 언어가 지원하는 경우이를 수정할 수 있습니다. –
안녕하세요 vels4j, 난 code.thanks –