Search in sources :

Example 61 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.

@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
    GetRecordsType query = new GetRecordsType();
    query.setResultType(ResultType.VALIDATE);
    query.setMaxRecords(BigInteger.valueOf(6));
    query.setStartPosition(BigInteger.valueOf(4));
    SourceResponse sourceResponse = createSourceResponse(query, 22);
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
    args.put(CswConstants.GET_RECORDS, query);
    BinaryContent content = transformer.transform(sourceResponse, args);
    String xml = new String(content.getByteArray());
    JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
    AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
    assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
    JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
    assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) BinaryContent(ddf.catalog.data.BinaryContent) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 62 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionHits.

@Ignore
public void testMarshalRecordCollectionHits() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    collection.setResultType(ResultType.HITS);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(0));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 63 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class MetacardMarshaller method getRegistryPackageFromMetacard.

/**
     * Converts the metacards metadata into a RegistryPackageType object
     *
     * @param mcard A metacard with ebrim metadata
     * @return A RegistryPackageType object created from the ebrim metadata
     * @throws ParserException
     */
public RegistryPackageType getRegistryPackageFromMetacard(Metacard mcard) throws ParserException {
    JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement;
    String metadata = mcard.getMetadata();
    try (InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(StandardCharsets.UTF_8))) {
        registryObjectTypeJAXBElement = parser.unmarshal(unmarshalConfigurator, JAXBElement.class, inputStream);
    } catch (IOException e) {
        throw new ParserException("Error parsing metacards xml as ebrim", e);
    }
    if (registryObjectTypeJAXBElement == null) {
        throw new ParserException("Error parsing metacards xml as ebrim");
    }
    RegistryPackageType registryPackage = (RegistryPackageType) registryObjectTypeJAXBElement.getValue();
    if (registryPackage == null) {
        throw new ParserException("Error parsing metacards xml as ebrim. No value");
    }
    return registryPackage;
}
Also used : ParserException(org.codice.ddf.parser.ParserException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType)

Example 64 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class TestRegistryStore method testCreateNoExistingMetacard.

@Test
public void testCreateNoExistingMetacard() throws Exception {
    Metacard mcard = getDefaultMetacard();
    Csw csw = mock(Csw.class);
    TransactionResponseType responseType = mock(TransactionResponseType.class);
    InsertResultType insertResultType = mock(InsertResultType.class);
    BriefRecordType briefRecord = mock(BriefRecordType.class);
    JAXBElement identifier = mock(JAXBElement.class);
    SimpleLiteral literal = mock(SimpleLiteral.class);
    when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
    when(identifier.getValue()).thenReturn(literal);
    when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
    when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
    when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
    when(factory.getClientForSubject(any())).thenReturn(csw);
    when(csw.transaction(any())).thenReturn(responseType);
    when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
    queryResults.add(new ResultImpl(mcard));
    CreateRequest request = new CreateRequestImpl(mcard);
    CreateResponse response = registryStore.create(request);
    assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
Also used : Metacard(ddf.catalog.data.Metacard) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) ResultImpl(ddf.catalog.data.impl.ResultImpl) JAXBElement(javax.xml.bind.JAXBElement) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 65 with JAXBElement

use of javax.xml.bind.JAXBElement in project ddf by codice.

the class RegistryPackageConverter method setSlotGeoAttribute.

private static void setSlotGeoAttribute(SlotType1 slot, String metacardAttributeName, MetacardImpl metacard) throws RegistryConversionException {
    if (slot.isSetValueList()) {
        net.opengis.cat.wrs.v_1_0_2.ValueListType valueList = (net.opengis.cat.wrs.v_1_0_2.ValueListType) slot.getValueList().getValue();
        List<AnyValueType> anyValues = valueList.getAnyValue();
        for (AnyValueType anyValue : anyValues) {
            if (anyValue.isSetContent()) {
                for (Object content : anyValue.getContent()) {
                    if (content instanceof JAXBElement) {
                        JAXBElement jaxbElement = (JAXBElement) content;
                        AbstractGeometryType geometry = (AbstractGeometryType) jaxbElement.getValue();
                        String convertedGeometry = getWKTFromGeometry(geometry, jaxbElement);
                        if (StringUtils.isNotBlank(convertedGeometry)) {
                            metacard.setAttribute(metacardAttributeName, convertedGeometry);
                        }
                    }
                }
            }
        }
    }
}
Also used : AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) JAXBElement(javax.xml.bind.JAXBElement) AnyValueType(net.opengis.cat.wrs.v_1_0_2.AnyValueType)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)650 QName (javax.xml.namespace.QName)194 Element (org.w3c.dom.Element)124 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)95 ArrayList (java.util.ArrayList)93 MessageImpl (org.apache.cxf.message.MessageImpl)92 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 Test (org.junit.Test)87 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 JAXBException (javax.xml.bind.JAXBException)81 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 JAXBContext (javax.xml.bind.JAXBContext)75 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 Unmarshaller (javax.xml.bind.Unmarshaller)65 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58