/* * NOSA HEADER START * * The contents of this file are subject to the terms of the NASA Open * Source Agreement (NOSA), Version 1.3 only (the "Agreement"). You may * not use this file except in compliance with the Agreement. * * You can obtain a copy of the agreement at * docs/NASA_Open_Source_Agreement_1.3.txt * or * http://cdaweb.gsfc.nasa.gov/WebServices/NASA_Open_Source_Agreement_1.3.txt. * * See the Agreement for the specific language governing permissions * and limitations under the Agreement. * * When distributing Covered Code, include this NOSA HEADER in each * file and include the Agreement file at * docs/NASA_Open_Source_Agreement_1.3.txt. If applicable, add the * following below this NOSA HEADER, with the fields enclosed by * brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * NOSA HEADER END * * Copyright (c) 2008-2010 United States Government as represented by * the National Aeronautics and Space Administration. No copyright is * claimed in the United States under Title 17, U.S.Code. All Other * Rights Reserved. * */ package gov.nasa.gsfc.spdf.helm.test; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.net.Authenticator; import java.net.URL; import java.net.URLEncoder; import java.net.HttpURLConnection; import java.net.PasswordAuthentication; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.Map; import java.util.SimpleTimeZone; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; import org.w3._1999.xhtml.*; import org.spase_group.data.schema.Contact; import org.spase_group.data.schema.EnumPhenomenonType; import org.spase_group.data.schema.EnumRole; import org.spase_group.data.schema.ResourceHeader; import org.spase_group.data.schema.TimeSpan; import gov.nasa.gsfc.helm.data.schema.Event; import gov.nasa.gsfc.helm.data.schema.Eventlist; /** * This class represents an example client of Heliophysics Event List * Manager (HELM) Web services. It utilizes the basic * java.net.HttpURLConnection class. A similar example * could be implemented using any of the other competing APIs. * * @version $Revision: $ * @author B. Harris */ public class WsExample { /** * Address of web services. */ private String endpoint = "http://helm.gsfc.nasa.gov/WS/cdasr/1"; /** * JAXB context for HELM XML data. */ private JAXBContext helmJaxbContext = JAXBContext.newInstance("gov.nasa.gsfc.helm.data.schema"); /** * JAXB context for XHTML data. */ private JAXBContext xhtmlJaxbContext = JAXBContext.newInstance(Html.class); /** * Eventlist Object Factory. */ private gov.nasa.gsfc.helm.data.schema.ObjectFactory eventlistFactory = new gov.nasa.gsfc.helm.data.schema.ObjectFactory(); /** * Spase Object Factory. */ private org.spase_group.data.schema.ObjectFactory spaseFactory = new org.spase_group.data.schema.ObjectFactory(); /** * XML Datatype Factory. */ private DatatypeFactory datatypeFactory = null; /** * HTTP User-Agent value to use. */ private static final String USER_AGENT = "WsExample"; /** * A UTC TimeZone. */ private static final SimpleTimeZone UTC_TIME_ZONE = new SimpleTimeZone(0, "UTC"); /** * Creates a WsExample. * * @throws JAXBException if unable to instantiate the required * JAXB contexts */ public WsExample(String endpoint) throws JAXBException, DatatypeConfigurationException { this.endpoint = endpoint; try { datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { System.err.println( "DatatypeConfigurationException: " + e.getMessage()); throw e; } } /** * Executes this example. * * @param listname name of eventlist to get */ public void execute(String listname) throws Exception { System.out.println("Java SE Example"); InputStream responseStream = getOptions(); print(System.out, responseStream); System.out.println(); Eventlist eventlist = getXmlEventlist(listname); System.out.println("Eventlist (response entity):"); marshal(System.out, eventlist); System.out.println(); Eventlist exampleEventlist = createExampleEventlist(); System.out.println("Example Eventlist:"); marshal(System.out, exampleEventlist); System.out.println(); Eventlist shiftedEventlist = shiftTimes(exampleEventlist, "PT1H"); System.out.println("shiftedEventlist (response entity):"); marshal(System.out, shiftedEventlist); System.out.println(); Html lists = getEventlistsByXPath( "//spase:StartDate[" + "node()>xs:dateTime('2005-01-01T00:00:00') and " + "node()