import javax.xml.soap.*;
import java.io.ByteArrayOutputStream;
/**
Example client for the EOP webservice of the IERS Central Bureau
*/
public class EOPClient{
public static void main(String args[]) throws Exception {
String result = getEOPValue("x_pole", "Bulletin A", "56000");
//Do something with the result value ....
System.out.println(result);
}
/** Get the value of param (e.g. "x_pole") for series (e.g. "Bulletin A") and mjd
@praram param Valid options for param: "x_pole", "sigma_x_pole", "y_pole", "sigma_y_pole", "UT1-UTC", "sigma_UT1-UTC", "LOD", "sigma_LOD", "dPsi", "sigma_dPsi", "dEpsilon", "sigma_dEpsilon", "dX", "sigma_dX", "dY", "sigma_dY"
@pram series Valid options for series:"Finals All (IAU2000)", "Finals Daily (IAU2000)", "Finals Data (IAU2000)", "Finals All (IAU1980)","Finals Daily (IAU1980)","Finals Data (IAU1980)","EOP 08 C04 (IAU1980)","EOP 08 C04 (IAU2000)","EOP 14 C04 (IAU1980)","EOP 14 C04 (IAU2000)","GPS Rapid","GPS Rapid Daily","Bulletin A","Bulletin B","EOP C01"
@param mjd Modified Julian Date
@return a single EOP value, unit of retrun value: msec for "UT1-UTC", "sigma_UT1_UTC","LOD" and "sigma_LOD"; marcsec for all other parameters.
*/
public static String getEOPValue(String param, String series, String mjd) throws Exception{
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "https://data.iers.org/eris/webservice/eop/eopServer.php";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(param, series, mjd), url);
// print SOAP Response
//Convert the response into xml String
ByteArrayOutputStream out = new ByteArrayOutputStream();
soapResponse.writeTo(out);
String strMsg = new String(out.toByteArray());
//extract the result value from the xml string
int resultStart = strMsg.indexOf("", resultStart);
int resultEnd = strMsg.indexOf("");
String result = strMsg.substring(resultStart+1,resultEnd);
soapConnection.close();
return result;
}
//Create the SOAP request message
private static SOAPMessage createSOAPRequest(String param, String series, String mjd) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "https://data.iers.org/eris/webservice/eop/eopServer.php";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("example", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("readEOP", "example");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("param", "example");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("series", "example");
SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("mjd", "example");
soapBodyElem1.addTextNode(param);
soapBodyElem2.addTextNode(series);
soapBodyElem3.addTextNode(mjd);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "readEOP");
soapMessage.saveChanges();
/*
Constructed SOAP Request Message:
x
Bulletin A
56000
*/
return soapMessage;
}
}