Search in sources :

Example 86 with ObjectFactory

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory in project ddf by codice.

the class XacmlClient method marshal.

/**
 * Marshalls the XACML request to a string.
 *
 * @param xacmlRequestType The XACML request to marshal.
 * @return A string representation of the XACML request.
 */
private String marshal(RequestType xacmlRequestType) throws PdpException {
    if (null == parser) {
        throw new IllegalStateException("XMLParser must be configured.");
    }
    String xacmlRequest = null;
    try {
        List<String> ctxPath = new ArrayList<>(1);
        ctxPath.add(ResponseType.class.getPackage().getName());
        ParserConfigurator configurator = parser.configureParser(ctxPath, XacmlClient.class.getClassLoader());
        configurator.addProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ObjectFactory objectFactory = new ObjectFactory();
        parser.marshal(configurator, objectFactory.createRequest(xacmlRequestType), os);
        xacmlRequest = os.toString("UTF-8");
    } catch (ParserException | UnsupportedEncodingException e) {
        String message = "Unable to marshal XACML request.";
        LOGGER.info(message, e);
        throw new PdpException(message, e);
    }
    LOGGER.debug("\nXACML 3.0 Request:\n{}", xacmlRequest);
    return xacmlRequest;
}
Also used : ParserConfigurator(org.codice.ddf.parser.ParserConfigurator) ParserException(org.codice.ddf.parser.ParserException) ObjectFactory(oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 87 with ObjectFactory

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory 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(), mock(SecurityLogger.class));
    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) SecurityLogger(ddf.security.audit.SecurityLogger) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Example 88 with ObjectFactory

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory in project axis-axis2-java-core by apache.

the class MtomSampleByteArrayTests method testAttachmentByteArrayAPI11.

/*
     * Enable attachment Optimization through the SOAPBinding method 
     * -- setMTOMEnabled([true|false])
     * Using SOAP11
     */
@Ignore
@Test
public void testAttachmentByteArrayAPI11() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    Service svc = Service.create(QNAME_SERVICE);
    svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, getEndpoint());
    JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
    Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
    SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
    binding.setMTOMEnabled(true);
    Image image = ImageIO.read(new File(imageResourceDir + File.separator + "test.jpg"));
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(image);
    setText(imageDepot);
    // Create a request bean with imagedepot bean as value
    ObjectFactory factory = new ObjectFactory();
    Invoke request = factory.createInvoke();
    request.setInput(imageDepot);
    SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
    // Repeat to verify behavior
    response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
}
Also used : ObjectFactory(org.apache.axis2.jaxws.sample.mtom1.ObjectFactory) ImageDepot(org.apache.axis2.jaxws.sample.mtom1.ImageDepot) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) JAXBContext(javax.xml.bind.JAXBContext) SendImageResponse(org.apache.axis2.jaxws.sample.mtom1.SendImageResponse) File(java.io.File) Invoke(org.apache.axis2.jaxws.sample.mtom1.Invoke) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 89 with ObjectFactory

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory in project axis-axis2-java-core by apache.

the class MtomSampleByteArrayTests method testAttachmentByteArrayProperty11.

/*
     * Enable attachment optimization using the SOAP11 binding
     * property for MTOM.
     */
@Test
public void testAttachmentByteArrayProperty11() throws Exception {
    TestLogger.logger.debug("----------------------------------");
    String imageResourceDir = IMAGE_DIR;
    Service svc = Service.create(QNAME_SERVICE);
    svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_MTOM_BINDING, getEndpoint());
    JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
    Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
    Image image = ImageIO.read(new File(imageResourceDir + File.separator + "test.jpg"));
    ImageDepot imageDepot = new ObjectFactory().createImageDepot();
    imageDepot.setImageData(image);
    setText(imageDepot);
    // Create a request bean with imagedepot bean as value
    ObjectFactory factory = new ObjectFactory();
    Invoke request = factory.createInvoke();
    request.setInput(imageDepot);
    SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
    // Repeat to verify behavior
    response = (SendImageResponse) dispatch.invoke(request);
    assertNotNull(response);
    assertNotNull(response.getOutput().getImageData());
    checkText(response.getOutput());
}
Also used : ObjectFactory(org.apache.axis2.jaxws.sample.mtom1.ObjectFactory) ImageDepot(org.apache.axis2.jaxws.sample.mtom1.ImageDepot) Service(javax.xml.ws.Service) JAXBContext(javax.xml.bind.JAXBContext) SendImageResponse(org.apache.axis2.jaxws.sample.mtom1.SendImageResponse) File(java.io.File) Invoke(org.apache.axis2.jaxws.sample.mtom1.Invoke) Test(org.junit.Test)

Example 90 with ObjectFactory

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.ObjectFactory in project clinical_quality_language by cqframework.

the class Main method main.

public static void main(String[] args) throws IOException, JAXBException {
    OptionParser parser = new OptionParser();
    OptionSpec<File> schemaOpt = parser.accepts("schema").withRequiredArg().ofType(File.class).required();
    OptionSpec<String> modelOpt = parser.accepts("model").withRequiredArg().ofType(String.class);
    OptionSpec<File> configOpt = parser.accepts("config").withOptionalArg().ofType(File.class);
    OptionSpec<File> outputOpt = parser.accepts("output").withRequiredArg().ofType(File.class);
    OptionSpec<String> normalizePrefixOpt = parser.accepts("normalize-prefix").withRequiredArg().ofType(String.class);
    OptionSpec<ModelImporterOptions.ChoiceTypePolicy> choiceTypeOpt = parser.accepts("choicetype-policy").withRequiredArg().ofType(ModelImporterOptions.ChoiceTypePolicy.class);
    OptionSpec<ModelImporterOptions.SimpleTypeRestrictionPolicy> stRestrictionsOpt = parser.accepts("simpletype-restriction-policy").withRequiredArg().ofType(ModelImporterOptions.SimpleTypeRestrictionPolicy.class);
    OptionSpec<ModelImporterOptions.ElementRedeclarationPolicy> redeclarationsOpt = parser.accepts("element-redeclaration-policy").withRequiredArg().ofType(ModelImporterOptions.ElementRedeclarationPolicy.class);
    OptionSpec<ModelImporterOptions.VersionPolicy> versionPolicyOpt = parser.accepts("version-policy").withRequiredArg().ofType(ModelImporterOptions.VersionPolicy.class);
    OptionSpec<File> optionsFileOpt = parser.accepts("options-file").withRequiredArg().ofType(File.class);
    OptionSet options = parser.parse(args);
    File schemaFile = schemaOpt.value(options);
    InputStream is = new FileInputStream(schemaFile);
    XmlSchemaCollection schemaCol = new XmlSchemaCollection();
    schemaCol.setBaseUri(schemaFile.getParent());
    XmlSchema schema = schemaCol.read(new StreamSource(is));
    ModelImporterOptions importerOptions;
    if (options.has(optionsFileOpt)) {
        importerOptions = ModelImporterOptions.loadFromProperties(optionsFileOpt.value(options));
    } else {
        importerOptions = new ModelImporterOptions();
    }
    if (options.has(modelOpt)) {
        importerOptions.setModel(modelOpt.value(options));
    }
    if (options.has(choiceTypeOpt)) {
        importerOptions.setChoiceTypePolicy(choiceTypeOpt.value(options));
    }
    if (options.has(stRestrictionsOpt)) {
        importerOptions.setSimpleTypeRestrictionPolicy(stRestrictionsOpt.value(options));
    }
    if (options.has(redeclarationsOpt)) {
        importerOptions.setElementRedeclarationPolicy(redeclarationsOpt.value(options));
    }
    if (options.has(versionPolicyOpt)) {
        importerOptions.setVersionPolicy(versionPolicyOpt.value(options));
    }
    if (options.has(normalizePrefixOpt)) {
        importerOptions.setNormalizePrefix(normalizePrefixOpt.value(options));
    }
    ModelInfo config = null;
    if (configOpt != null) {
        File configFile = configOpt.value(options);
        if (configFile != null) {
            config = JAXB.unmarshal(configFile, ModelInfo.class);
        }
    }
    ModelInfo modelInfo = ModelImporter.fromXsd(schema, importerOptions, config);
    JAXBContext jc = JAXBContext.newInstance(ModelInfo.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    File outputfile;
    if (!options.has(outputOpt) || outputOpt.value(options).isDirectory()) {
        // construct output filename using modelinfo
        String name = String.format("%s-modelinfo.xml", modelInfo.getTargetQualifier());
        String basePath = options.has(outputOpt) ? outputOpt.value(options).getAbsolutePath() : schemaFile.getParent();
        outputfile = new File(basePath + File.separator + name);
    } else {
        outputfile = outputOpt.value(options);
    }
    if (outputfile.equals(schemaFile)) {
        throw new IllegalArgumentException("input schema file and output file must be different!");
    }
    OutputStream os = new FileOutputStream(outputfile, false);
    try {
        OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
        marshaller.marshal(new ObjectFactory().createModelInfo(modelInfo), writer);
    } finally {
        os.close();
    }
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) JAXBContext(javax.xml.bind.JAXBContext) OptionParser(joptsimple.OptionParser) ObjectFactory(org.hl7.elm_modelinfo.r1.ObjectFactory) Marshaller(javax.xml.bind.Marshaller) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) XmlSchema(org.apache.ws.commons.schema.XmlSchema) OptionSet(joptsimple.OptionSet)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)35 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)26 Marshaller (javax.xml.bind.Marshaller)24 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 StringWriter (java.io.StringWriter)19 JAXBContext (javax.xml.bind.JAXBContext)19 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 ObjectFactory (no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory)16 QName (javax.xml.namespace.QName)15 BigInteger (java.math.BigInteger)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ObjectFactory (slash.navigation.kml.binding22.ObjectFactory)12 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11