Search in sources :

Example 1 with EnrollTemplateType

use of org.xipki.ca.client.shell.loadtest.jaxb.EnrollTemplateType in project xipki by xipki.

the class CaLoadTestTemplateEnroll method parse.

// method nextCertRequests
public static EnrollTemplateType parse(InputStream configStream) throws InvalidConfException {
    ParamUtil.requireNonNull("configStream", configStream);
    Object root;
    synchronized (jaxbUnmarshallerLock) {
        try {
            if (jaxbUnmarshaller == null) {
                JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
                jaxbUnmarshaller = context.createUnmarshaller();
                final SchemaFactory schemaFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
                URL url = ObjectFactory.class.getResource("/xsd/loadtest.xsd");
                jaxbUnmarshaller.setSchema(schemaFact.newSchema(url));
            }
            root = jaxbUnmarshaller.unmarshal(configStream);
        } catch (SAXException ex) {
            throw new InvalidConfException("parsing profile failed, message: " + ex.getMessage(), ex);
        } catch (JAXBException ex) {
            throw new InvalidConfException("parsing profile failed, message: " + XmlUtil.getMessage(ex), ex);
        }
    }
    try {
        configStream.close();
    } catch (IOException ex) {
        LOG.warn("could not close xmlConfStream: {}", ex.getMessage());
    }
    if (root instanceof JAXBElement) {
        return (EnrollTemplateType) ((JAXBElement<?>) root).getValue();
    } else {
        throw new InvalidConfException("invalid root element type");
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) EnrollTemplateType(org.xipki.ca.client.shell.loadtest.jaxb.EnrollTemplateType) JAXBException(javax.xml.bind.JAXBException) InvalidConfException(org.xipki.common.InvalidConfException) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) JAXBElement(javax.xml.bind.JAXBElement) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Example 2 with EnrollTemplateType

use of org.xipki.ca.client.shell.loadtest.jaxb.EnrollTemplateType in project xipki by xipki.

the class CaLoadTestTemplateEnrollCmd method execute0.

@Override
protected Object execute0() throws Exception {
    if (numThreads < 1) {
        throw new IllegalCmdParamException("invalid number of threads " + numThreads);
    }
    EnrollTemplateType template = CaLoadTestTemplateEnroll.parse(new FileInputStream(templateFile));
    int size = template.getEnrollCert().size();
    String description = StringUtil.concatObjectsCap(200, "template: ", templateFile, "\nmaxRequests: ", maxRequests, "\nunit: ", size, " certificate", (size > 1 ? "s" : ""), "\n");
    CaLoadTestTemplateEnroll loadTest = new CaLoadTestTemplateEnroll(caClient, template, maxRequests, description);
    loadTest.setDuration(duration);
    loadTest.setThreads(numThreads);
    loadTest.test();
    return null;
}
Also used : EnrollTemplateType(org.xipki.ca.client.shell.loadtest.jaxb.EnrollTemplateType) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) FileInputStream(java.io.FileInputStream)

Aggregations

EnrollTemplateType (org.xipki.ca.client.shell.loadtest.jaxb.EnrollTemplateType)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 InvalidConfException (org.xipki.common.InvalidConfException)1 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)1 SAXException (org.xml.sax.SAXException)1