Search in sources :

Example 91 with Marshaller

use of javax.xml.bind.Marshaller in project midpoint by Evolveum.

the class Main method createUserQuery2.

private static QueryType createUserQuery2(String username) throws JAXBException {
    QueryType query = new QueryType();
    SearchFilterType filter = new SearchFilterType();
    PropertyComplexValueFilterClauseType fc = new PropertyComplexValueFilterClauseType();
    ItemPathType path = new ItemPathType();
    path.setValue("declare namespace c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\"; c:name");
    fc.setPath(path);
    fc.getValue().add(username);
    ObjectFactory factory = new ObjectFactory();
    JAXBElement<PropertyComplexValueFilterClauseType> equal = factory.createEqual(fc);
    JAXBContext jaxbContext = JAXBContext.newInstance("com.evolveum.midpoint.xml.ns._public.common.api_types_3:" + "com.evolveum.midpoint.xml.ns._public.common.common_3:" + "com.evolveum.prism.xml.ns._public.annotation_3:" + "com.evolveum.prism.xml.ns._public.query_3:" + "com.evolveum.prism.xml.ns._public.types_3:");
    Marshaller marshaller = jaxbContext.createMarshaller();
    DOMResult result = new DOMResult();
    marshaller.marshal(equal, result);
    filter.setFilterClause(((Document) result.getNode()).getDocumentElement());
    query.setFilter(filter);
    return query;
}
Also used : Marshaller(javax.xml.bind.Marshaller) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) DOMResult(javax.xml.transform.dom.DOMResult) ObjectFactory(com.evolveum.prism.xml.ns._public.query_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PropertyComplexValueFilterClauseType(com.evolveum.prism.xml.ns._public.query_3.PropertyComplexValueFilterClauseType) JAXBContext(javax.xml.bind.JAXBContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 92 with Marshaller

use of javax.xml.bind.Marshaller in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomToolTipsHandler method SaveCustomToolTips.

/**
   * Save customtooltips to disk, overwriting any existing xml file
   *
   * @return
   */
public boolean SaveCustomToolTips() {
    try {
        JAXBContext tJaxbCtx = JAXBContext.newInstance(CustomToolTips.class);
        Marshaller jaxMarsh = tJaxbCtx.createMarshaller();
        jaxMarsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxMarsh.marshal(_mCustomToolTips, new FileOutputStream(_mConfigFileName, false));
        _mLogger.debug("[CTT.SaveCustomToolTips] Config file written");
        return true;
    } catch (Exception e) {
        _mLogger.error("[CTT.SaveCustomToolTips] Unable to create new CustomToolTips.xml. What did you do??");
        e.printStackTrace();
        return false;
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) FileOutputStream(java.io.FileOutputStream) JAXBContext(javax.xml.bind.JAXBContext)

Example 93 with Marshaller

use of javax.xml.bind.Marshaller in project NewHorizonsCoreMod by GTNewHorizons.

the class CustomFuelsHandler method SaveCustomFuels.

public boolean SaveCustomFuels() {
    try {
        JAXBContext tJaxbCtx = JAXBContext.newInstance(CustomFuels.class);
        Marshaller jaxMarsh = tJaxbCtx.createMarshaller();
        jaxMarsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxMarsh.marshal(_mCustomFuels, new FileOutputStream(_mConfigFileName, false));
        _mLogger.debug("Config file written");
        return true;
    } catch (Exception e) {
        _mLogger.error("Unable to create new CustomFuels.xml. What did you do??");
        e.printStackTrace();
        return false;
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) FileOutputStream(java.io.FileOutputStream) JAXBContext(javax.xml.bind.JAXBContext)

Example 94 with Marshaller

use of javax.xml.bind.Marshaller in project webservices-axiom by apache.

the class TestGetSAXResultJAXB method runTest.

@Override
protected void runTest() throws Throwable {
    List<OrderItem> items = new ArrayList<OrderItem>(2);
    OrderItem item = new OrderItem();
    item.setPartId("P85-137-19");
    item.setQuantity(2);
    items.add(item);
    item = new OrderItem();
    item.setPartId("O85-554-66");
    item.setQuantity(1);
    items.add(item);
    Order order = new Order();
    order.setCustomerId("73107481");
    order.setItems(items);
    Marshaller marshaller = JAXBContext.newInstance(Order.class).createMarshaller();
    StringWriter out = new StringWriter();
    marshaller.marshal(order, out);
    OMDocument document = metaFactory.getOMFactory().createOMDocument();
    marshaller.marshal(order, document.getSAXResult().getHandler());
    assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs(out.toString());
}
Also used : Order(org.apache.axiom.ts.om.document.jaxb.Order) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) OrderItem(org.apache.axiom.ts.om.document.jaxb.OrderItem) ArrayList(java.util.ArrayList) OMDocument(org.apache.axiom.om.OMDocument)

Example 95 with Marshaller

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

the class XacmlClientTest method testWrapperpoliciesdirectorypolicyadded.

@Test
public void testWrapperpoliciesdirectorypolicyadded() throws Exception {
    LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_policy_added");
    File policyDir = folder.newFolder("tempDir");
    XacmlClient.defaultPollingIntervalInSeconds = 1;
    // Perform Test
    XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), new XmlParser());
    File srcFile = new File(projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, policyDir);
    Thread.sleep(2000);
    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);
    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);
    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);
    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);
    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);
    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);
    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);
    // Verify - The policy was loaded to allow a permit decision
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);
    FileUtils.deleteDirectory(policyDir);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) Marshaller(javax.xml.bind.Marshaller) AttributeValueType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType) JAXBContext(javax.xml.bind.JAXBContext) ResponseType(oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) StringWriter(java.io.StringWriter) AttributeType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType) AttributesType(oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Aggregations

Marshaller (javax.xml.bind.Marshaller)280 JAXBContext (javax.xml.bind.JAXBContext)162 JAXBException (javax.xml.bind.JAXBException)100 StringWriter (java.io.StringWriter)82 Test (org.junit.Test)33 JAXBElement (javax.xml.bind.JAXBElement)32 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 File (java.io.File)29 Unmarshaller (javax.xml.bind.Unmarshaller)21 IOException (java.io.IOException)20 FileOutputStream (java.io.FileOutputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)15 QName (javax.xml.namespace.QName)14 Element (org.w3c.dom.Element)14 HashMap (java.util.HashMap)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)11 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7