2017-05-01 20 views
0

私はNDFD NOAAサーバーに接続してXMLリクエストを作成し、サーバーから情報を取得する必要があるSOAPとJavaで作業しています。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エンベロープを作成していません。

コード

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(); 
の下に試してみてください
関連する問題