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;
}
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;
}
}
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;
}
}
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());
}
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);
}
Aggregations