List of usage examples for javax.xml.bind JAXBElement JAXBElement
public JAXBElement(QName name, Class<T> declaredType, T value)
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java
@SuppressWarnings("unchecked") private <N extends BinaryTemporalOperator> void cqlTemporalQuery(String expectedAttr, String cqlSpatialDwithinQuery, Class<N>[] classes) throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException { GetRecordsType grr = createDefaultPostRecordsRequest(); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<QName>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames);//from w ww.j a va 2s . com QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(cqlSpatialDwithinQuery); query.setConstraint(constraint); JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery(); N temporal = null; if (classes.length > 1) { assertThat(frameworkQuery.getFilter(), instanceOf(Or.class)); int i = 0; for (Filter filter : ((Or) frameworkQuery.getFilter()).getChildren()) { assertThat(filter, instanceOf(classes[i++])); temporal = (N) filter; } } else { assertThat(frameworkQuery.getFilter(), instanceOf(classes[0])); temporal = (N) frameworkQuery.getFilter(); } assertThat(((AttributeExpressionImpl) temporal.getExpression1()).getPropertyName(), is(expectedAttr)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java
/** * Creates default GetRecordsType POST request, with no sections specified * * @return Vanilla valid GetRecordsType object *///from ww w . ja v a 2s. c om private GetRecordsType createDefaultPostRecordsRequest() { GetRecordsType grr = new GetRecordsType(); grr.setOutputFormat(CswConstants.OUTPUT_FORMAT_XML); grr.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<QName>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames); JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); return grr; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
/** * Test Valid GetRecords request, no exceptions should be thrown *//* ww w . jav a 2 s. c om*/ @Test public void testPostGetRecordsValidElementNames() throws CswException { GetRecordsType grr = createDefaultPostRecordsRequest(); QueryType query = new QueryType(); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); List<QName> elementNameList = Arrays.asList(new QName("brief"), new QName("summary"), new QName("full")); query.setElementName(elementNameList); grr.setAbstractQuery(jaxbQuery); csw.getRecords(grr); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
@Test public void testPostGetRecordsResults() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.RESULTS); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames);// ww w .ja v a 2s .co m QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); ElementSetNameType esnt = new ElementSetNameType(); esnt.setValue(ElementSetType.SUMMARY); query.setElementSetName(esnt); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); final String EXAMPLE_SCHEMA = CswConstants.CSW_OUTPUT_SCHEMA; grr.setOutputSchema(EXAMPLE_SCHEMA); final String EXAMPLE_MIME = "application/xml"; grr.setOutputFormat(EXAMPLE_MIME); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getMimeType(), is(EXAMPLE_MIME)); assertThat(collection.getOutputSchema(), is(EXAMPLE_SCHEMA)); assertThat(collection.getSourceResponse(), notNullValue()); assertThat(collection.getResultType(), is(ResultType.RESULTS)); assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
@Test public void testPostGetRecordsGmdCswOutputSchema() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.RESULTS); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(GmdMetacardType.GMD_NAMESPACE, GmdMetacardType.GMD_LOCAL_NAME, GmdMetacardType.GMD_PREFIX)); query.setTypeNames(typeNames);/* w w w . j a v a 2 s.com*/ QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(GMD_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); ElementSetNameType esnt = new ElementSetNameType(); esnt.setValue(ElementSetType.SUMMARY); query.setElementSetName(esnt); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); final String EXAMPLE_SCHEMA = CswConstants.CSW_OUTPUT_SCHEMA; grr.setOutputSchema(EXAMPLE_SCHEMA); final String EXAMPLE_MIME = "application/xml"; grr.setOutputFormat(EXAMPLE_MIME); when(catalogFramework.query(argument.capture())).thenReturn(getQueryResponse()); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getMimeType(), is(EXAMPLE_MIME)); assertThat(collection.getOutputSchema(), is(EXAMPLE_SCHEMA)); assertThat(collection.getSourceResponse(), notNullValue()); assertThat(collection.getResultType(), is(ResultType.RESULTS)); assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
@Test public void testPostGetRecordsHits() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.HITS);//from ww w. j a v a2 s . c o m QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames); QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); when(catalogFramework.query(argument.capture())).thenReturn(getQueryResponse()); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getCswRecords(), is(empty())); assertThat(collection.getResultType(), is(ResultType.HITS)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
@Test public void testPostGetRecordsValidate() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException { GetRecordsType grr = createDefaultPostRecordsRequest(); grr.setResultType(ResultType.VALIDATE); QueryType query = new QueryType(); List<QName> typeNames = new ArrayList<>(); typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX)); query.setTypeNames(typeNames);//from ww w. jav a 2s . c om QueryConstraintType constraint = new QueryConstraintType(); constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY); query.setConstraint(constraint); JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query); grr.setAbstractQuery(jaxbQuery); when(catalogFramework.query(argument.capture())).thenReturn(getQueryResponse()); CswRecordCollection collection = csw.getRecords(grr); assertThat(collection.getCswRecords(), is(empty())); assertThat(collection.getNumberOfRecordsMatched(), is(0L)); assertThat(collection.getNumberOfRecordsReturned(), is(0L)); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
/** * Tests to see that JAXB configuration is working */// w w w . j a va 2 s .c o m @Test public void testMarshallDescribeRecord() { DescribeRecordResponseType response = new DescribeRecordResponseType(); List<SchemaComponentType> schemas = new ArrayList<>(); SchemaComponentType schemaComponentType = new SchemaComponentType(); schemas.add(schemaComponentType); response.setSchemaComponent(schemas); JAXBContext context; try { context = JAXBContext .newInstance("net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<DescribeRecordResponseType> wrappedResponse = new JAXBElement<>(cswQnameOutPutSchema, DescribeRecordResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("\nResponse\n" + sw.toString() + "\n\n"); } catch (JAXBException e) { fail("Could not marshall message, Error: " + e.getMessage()); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.TestCswEndpoint.java
private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) { // Verify the response will marshal try {//from w w w . j a v a 2 s. co m JAXBContext context = JAXBContext.newInstance(contextPath); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName, TransactionResponseType.class, response); marshaller.marshal(wrappedResponse, sw); LOGGER.info("\nResponse\n" + sw.toString() + "\n\n"); } catch (JAXBException e) { fail("Could not marshal message, Error: " + e.getMessage()); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.source.TestCswSourceBase.java
protected String getGetRecordsTypeAsXml(GetRecordsType getRecordsType, String cswVersion) { Writer writer = new StringWriter(); try {/*from www. jav a2 s . c om*/ JAXBContext jaxbContext = JAXBContext.newInstance( "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0"); Marshaller marshaller = jaxbContext.createMarshaller(); JAXBElement<GetRecordsType> jaxbElement = null; if (CswConstants.VERSION_2_0_2.equals(cswVersion)) { // QName("http://www.opengis.net/cat/csw/2.0.2", ""GetRecords") jaxbElement = new JAXBElement<GetRecordsType>( new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.GET_RECORDS), GetRecordsType.class, getRecordsType); } else { // CSW 2.0.1 // QName("http://www.opengis.net/cat/csw", ""GetRecords") LOGGER.debug("Called 2.0.1"); jaxbElement = new JAXBElement<GetRecordsType>( new QName("http://www.opengis.net/cat/csw", CswConstants.GET_RECORDS), GetRecordsType.class, getRecordsType); } marshaller.marshal(jaxbElement, writer); } catch (JAXBException e) { String message = "Unable to marshall " + GetRecordsResponseType.class + " to XML."; LOGGER.debug(message, e); } return writer.toString(); }