Search in sources :

Example 16 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project geotoolkit by Geomatys.

the class CSWClientDemo method main.

public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException, JAXBException {
    Demos.init();
    final MarshallerPool pool = CSWMarshallerPool.getInstance();
    final Unmarshaller um = pool.acquireUnmarshaller();
    final MarshallWarnings warnings = new MarshallWarnings();
    um.setProperty(XML.CONVERTER, warnings);
    // build a new CSW client
    final CatalogServicesClient cswServer = new CatalogServicesClient(new URL("http://catalog.data.gov/csw?"), "2.0.2");
    /**
     * make a getCapabilities request
     */
    final GetCapabilitiesRequest getCapa = cswServer.createGetCapabilities();
    InputStream is = getCapa.getResponseStream();
    // unmarshall the response
    Capabilities capabilities = (Capabilities) um.unmarshal(is);
    // print the title of the server
    System.out.println(capabilities.getServiceIdentification().getTitle());
    /**
     * make a getRecords request
     */
    final GetRecordsRequest getRecords = cswServer.createGetRecords();
    getRecords.setTypeNames("gmd:MD_Metadata");
    getRecords.setConstraintLanguage("CQL");
    getRecords.setConstraintLanguageVersion("1.1.0");
    getRecords.setConstraint("apiso:Title like '%'");
    getRecords.setElementSetName(ElementSetType.FULL);
    is = getRecords.getResponseStream();
    // unmarshall the response
    Object obj = um.unmarshal(is);
    GetRecordsResponseType response;
    if (obj instanceof ExceptionReport) {
        System.out.println("Error received:" + obj);
        return;
    } else {
        response = ((JAXBElement<GetRecordsResponseType>) obj).getValue();
    }
    // print the number of result matching the request
    System.out.println(response.getSearchResults().getNumberOfRecordsMatched());
    /**
     * retrieve results in dublin core
     */
    getRecords.setResultType(ResultType.RESULTS);
    is = getRecords.getResponseStream();
    obj = um.unmarshal(is);
    // unmarshall the response
    if (obj instanceof ExceptionReport) {
        System.out.println("Error received:" + obj);
        return;
    } else {
        response = ((JAXBElement<GetRecordsResponseType>) obj).getValue();
    }
    // print the first result (Dublin core)
    AbstractRecord record = (AbstractRecord) response.getSearchResults().getAny().get(0);
    System.out.println(record);
    /**
     * retrieve results in ISO 19139
     */
    getRecords.setOutputSchema("http://www.isotc211.org/2005/gmd");
    is = getRecords.getResponseStream();
    // unmarshall the response
    obj = um.unmarshal(is);
    // unmarshall the response
    if (obj instanceof ExceptionReport) {
        System.out.println("Error received:" + obj);
        return;
    } else {
        response = ((JAXBElement<GetRecordsResponseType>) obj).getValue();
    }
    // print the first result (ISO 19139)
    Metadata meta = (Metadata) response.getSearchResults().getAny().get(0);
    System.out.println(meta);
    final String identifier = meta.getFileIdentifier();
    /**
     * make a getRecordById request
     */
    final GetRecordByIdRequest getRecordById = cswServer.createGetRecordById();
    getRecordById.setOutputSchema("http://www.isotc211.org/2005/gmd");
    getRecordById.setIds(identifier);
    is = getRecordById.getResponseStream();
    // unmarshall the response
    obj = um.unmarshal(is);
    // unmarshall the response
    GetRecordByIdResponse responseBi;
    if (obj instanceof ExceptionReport) {
        System.out.println("Error received:" + obj);
        return;
    } else {
        responseBi = ((JAXBElement<GetRecordByIdResponse>) obj).getValue();
    }
    // print the result (same as getRecords first result)
    meta = (Metadata) responseBi.getAny().get(0);
    System.out.println(meta);
    pool.recycle(um);
}
Also used : GetRecordByIdResponse(org.geotoolkit.csw.xml.GetRecordByIdResponse) GetCapabilitiesRequest(org.geotoolkit.csw.GetCapabilitiesRequest) InputStream(java.io.InputStream) ExceptionReport(org.geotoolkit.ows.xml.v100.ExceptionReport) AbstractRecord(org.geotoolkit.csw.xml.AbstractRecord) Metadata(org.opengis.metadata.Metadata) CSWMarshallerPool(org.geotoolkit.csw.xml.CSWMarshallerPool) MarshallerPool(org.apache.sis.xml.MarshallerPool) GetRecordByIdRequest(org.geotoolkit.csw.GetRecordByIdRequest) URL(java.net.URL) GetRecordsRequest(org.geotoolkit.csw.GetRecordsRequest) CatalogServicesClient(org.geotoolkit.csw.CatalogServicesClient) Capabilities(org.geotoolkit.csw.xml.v202.Capabilities) GetRecordsResponseType(org.geotoolkit.csw.xml.v202.GetRecordsResponseType) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 17 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project web-feature-service by 3dcitydb.

the class QueryExecuter method getTruncatedResponse.

private TruncatedResponse getTruncatedResponse(WFSException wfsException, HttpServletRequest request) {
    WFSExceptionReportHandler reportHandler = new WFSExceptionReportHandler(cityGMLBuilder);
    ExceptionReport exceptionReport = reportHandler.getExceptionReport(wfsException, KVPConstants.GET_FEATURE, request, true);
    TruncatedResponse truncatedResponse = new TruncatedResponse();
    truncatedResponse.setExceptionReport(exceptionReport);
    return truncatedResponse;
}
Also used : ExceptionReport(net.opengis.ows._1.ExceptionReport) TruncatedResponse(net.opengis.wfs._2.TruncatedResponse) WFSExceptionReportHandler(vcs.citydb.wfs.exception.WFSExceptionReportHandler)

Example 18 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project web-feature-service by 3dcitydb.

the class QueryExecuter method getTruncatedResponse.

private TruncatedResponse getTruncatedResponse(WFSException wfsException, HttpServletRequest request) {
    WFSExceptionReportHandler reportHandler = new WFSExceptionReportHandler(cityGMLBuilder);
    ExceptionReport exceptionReport = reportHandler.getExceptionReport(wfsException, KVPConstants.GET_PROPERTY_VALUE, request, true);
    TruncatedResponse truncatedResponse = new TruncatedResponse();
    truncatedResponse.setExceptionReport(exceptionReport);
    return truncatedResponse;
}
Also used : ExceptionReport(net.opengis.ows._1.ExceptionReport) TruncatedResponse(net.opengis.wfs._2.TruncatedResponse) WFSExceptionReportHandler(vcs.citydb.wfs.exception.WFSExceptionReportHandler)

Aggregations

ExceptionReport (net.opengis.ows.v_1_0_0.ExceptionReport)9 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)5 IOException (java.io.IOException)4 StringReader (java.io.StringReader)4 JAXBException (javax.xml.bind.JAXBException)4 ExceptionReport (net.opengis.ows._1.ExceptionReport)4 InputStream (java.io.InputStream)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)3 URL (java.net.URL)2 TruncatedResponse (net.opengis.wfs._2.TruncatedResponse)2 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)2 ExceptionReport (org.geotoolkit.ows.xml.v110.ExceptionReport)2 WFSExceptionReportHandler (vcs.citydb.wfs.exception.WFSExceptionReportHandler)2 StringWriter (java.io.StringWriter)1