2017-05-01 1 views
0

SOAP 및 Java에서 NDFD NOAA 서버에 연결하고 XML 요청을 만들어 서버에서 정보를 가져와야합니다.Soap java FaultString : 24 시간마다 또는 12 시간마다 형식이 필요합니다.

다음은 내 코드이며 오류가 발생합니다. 오류가 난 얻고있다

 SOAPConnectionFactory lab3_factory = SOAPConnectionFactory.newInstance(); 
     SOAPConnection lab3_conn = lab3_factory.createConnection(); 
     MessageFactory factory = MessageFactory.newInstance(); 
     SOAPMessage msg = factory.createMessage(); 
     SOAPPart part = msg.getSOAPPart(); 

     SOAPEnvelope envelope = part.getEnvelope(); 

     Name xsi = envelope.createName("type","xsi","http://www.w3.org/2001/XMLSchema-instance"); 
     //QName xsi = new QName("xsi:type"); 
     Name xsd = envelope.createName("lab_3","xsd","http://www.w3.org/2001/XMLSchema"); 
     String ns6244_serverURI = "http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl"; 
     envelope.addNamespaceDeclaration("ns6244",ns6244_serverURI); 
     //String xsi_serverURI = "http://www.w3.org/2001/XMLSchema-instance"; 
     //envelope.addNamespaceDeclaration("xsi",xsi_serverURI); 


     envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); 
     SOAPBody body = envelope.getBody(); 


     SOAPElement soapBodyElem = body.addChildElement("NDFDgenByDay", "ns6244"); 
     //String encoding_string = "http://schemas.xmlsoap.org/soap/encoding/"; 
     //soapBodyElem.setEncodingStyle(encoding_string); 

     Name latitude = envelope.createName("latitude"); 

     SOAPElement soapBodyElem1 = body.addChildElement(latitude); 
     soapBodyElem1.addAttribute(xsi,"xsd:decimal"); 
     BigDecimal x = new BigDecimal(35.4); 
     soapBodyElem1.setValue(x.toString()); 

     Name longitude = envelope.createName("longitude"); 

     SOAPElement soapBodyElem2 = body.addChildElement(longitude); 
     soapBodyElem2.addAttribute(xsi,"xsd:decimal"); 
     BigDecimal y = new BigDecimal(-97.6); 
     soapBodyElem2.setValue(y.toString()); 

     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     Date date = new Date(); 

     GregorianCalendar c = new GregorianCalendar(); 
     c.setTime(date); 
     XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
     String upd_date = "\0"; 
     String d2 = date2.toString(); 
     for(String d:d2.split("T")) 
     { 
      upd_date = d; 
      break; 
     } 
     Name startDate = envelope.createName("startDate"); 
     SOAPElement soapBodyElem4 = body.addChildElement(startDate); 
     soapBodyElem4.addAttribute(xsi,"xsd:date"); 
     soapBodyElem4.setValue(upd_date); 


     Name numDays = envelope.createName("numDays"); 
     SOAPElement soapBodyElem5 = body.addChildElement(numDays); 
     soapBodyElem5.addAttribute(xsi,"xsd:integer"); 
     soapBodyElem5.setValue("3"); 



     Name format = envelope.createName("format"); 

     SOAPElement soapBodyElem3 = body.addChildElement(format); 
     soapBodyElem3.addAttribute(xsi,"dwml:formatType"); 
     soapBodyElem3.addNamespaceDeclaration("dwml","http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd"); 
     soapBodyElem3.setValue("12 hourly"); 


     SOAPHeader header = envelope.getHeader(); 


     /* 
     SOAPBodyElement element = body.addBodyElement(envelope.createName("JAVA", "training", "http://JitendraZaa.com/blog")); 
     element.addChildElement("WS").addTextNode("Training on Web service"); 

     SOAPBodyElement element1 = body.addBodyElement(envelope.createName("JAVA", "training", "http://JitendraZaa.com/blog")); 
     element1.addChildElement("Spring").addTextNode("Training on Spring 3.0"); 
     */ 
     msg.writeTo(System.out); 
     msg.saveChanges(); 

     FileOutputStream fOut = new FileOutputStream("SoapMessage.xml"); 
     msg.writeTo(fOut); 

     String getdata_url = "https://graphical.weather.gov:443/xml/SOAP_server/ndfdXMLserver.php"; 

     String url_header = "http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl"; 

     MimeHeaders headers = msg.getMimeHeaders(); 
     headers.addHeader("SOAPAction", url_header + "NDFDgenByDay"); 


     SOAPMessage msg_reply = lab3_conn.call(msg,getdata_url); 

     msg_reply.writeTo(System.out); 

     System.out.println(); 
     System.out.println("SOAP msg created"); 

입니다 ..

</SOAP-ENV:Envelope><?xml version="1.0" encoding="ISO-8859-1"?> 
    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SERVER</faultcode><faultactor xsi:type="xsd:string"> 

    </faultactor><faultstring xsi:type="xsd:string">format needs to be either 24 hourly or 12 hourly</faultstring> 
    <detail xsi:type="xsd:string">input format was &quot;&quot;</detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope> 

도움의 모든 종류가 감사합니다.

답변

0

코드에 많은 문제가 있으며 webservice 호출에 필요한 형식으로 SOAP SOAP 봉투를 작성하지도 않습니다. 코드 아래

시도

SOAPConnectionFactory lab3_factory = SOAPConnectionFactory.newInstance(); 
     SOAPConnection lab3_conn = lab3_factory.createConnection(); 
     MessageFactory factory = MessageFactory.newInstance(); 
     SOAPMessage msg = factory.createMessage(); 
     SOAPPart part = msg.getSOAPPart(); 

     SOAPEnvelope envelope = part.getEnvelope(); 

     Name xsi = envelope.createName("type","xsi","http://www.w3.org/2001/XMLSchema-instance"); 
     //QName xsi = new QName("xsi:type"); 
     Name xsd = envelope.createName("lab_3","xsd","http://www.w3.org/2001/XMLSchema"); 
     String ns6244_serverURI = "http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl"; 
     envelope.addNamespaceDeclaration("ns6244",ns6244_serverURI); 
     envelope.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); 
     SOAPBody body = envelope.getBody(); 

     SOAPElement soapBodyElem = body.addChildElement("NDFDgenByDay", "ns6244"); 

     SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(new QName("latitude"));   
     BigDecimal x = new BigDecimal(35.4); 
     soapBodyElem1.setValue(x.toString()); 
     SOAPElement soapBodyElem2 = soapBodyElem.addChildElement(new QName("longitude"));   
     BigDecimal y = new BigDecimal(-97.6); 
     soapBodyElem2.setValue(y.toString()); 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     Date date = new Date(); 
     GregorianCalendar c = new GregorianCalendar(); 
     c.setTime(date); 
     XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
     String upd_date = "\0"; 
     String d2 = date2.toString(); 
     for(String d:d2.split("T")) 
     { 
      upd_date = d; 
      break; 
     } 

     SOAPElement soapBodyElem4 = soapBodyElem.addChildElement(new QName("startDate"));   
     soapBodyElem4.setValue(upd_date);   
     SOAPElement soapBodyElem5 = soapBodyElem.addChildElement(new QName("numDays"));   
     soapBodyElem5.setValue("3"); 
     SOAPElement soapBodyElem6 = soapBodyElem.addChildElement(new QName("Unit")); 
     soapBodyElem6.setValue("e");   
     SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(new QName("format")); 
     soapBodyElem3.setValue("12 hourly"); 
     SOAPHeader header = envelope.getHeader();  
     msg.writeTo(System.out); 
     msg.saveChanges(); 
     String getdata_url = "https://graphical.weather.gov:443/xml/SOAP_server/ndfdXMLserver.php"; 
     String url_header = "http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl"; 
     MimeHeaders headers = msg.getMimeHeaders(); 
     headers.addHeader("SOAPAction", url_header + "NDFDgenByDay"); 
     SOAPMessage msg_reply = lab3_conn.call(msg,getdata_url); 

     msg_reply.writeTo(System.out); 

     System.out.println(); 
관련 문제