List of usage examples for javax.xml.bind Marshaller JAXB_FRAGMENT
String JAXB_FRAGMENT
To view the source code for javax.xml.bind Marshaller JAXB_FRAGMENT.
Click Source Link
From source file:mx.bigdata.sat.cfdi.CFDv33.java
@Override public void guardar(OutputStream out) throws Exception { Marshaller m = context.createMarshaller(); m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes)); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, getSchemaLocation()); byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8"); out.write(xmlHeaderBytes);/*from www . j av a2s. co m*/ m.marshal(document, out); }
From source file:ee.ria.xroad.proxy.serverproxy.MetadataServiceHandlerImpl.java
private static void marshal(Object object, Node out) throws Exception { Marshaller marshaller = JAXB_CTX.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.marshal(object, out);//from ww w .jav a2s . c o m }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * create an xml representation for the given <T> instance * // w ww. ja v a 2 s . c o m * @param instance * - the instance to convert to xml * @return a xml representation of the given <T> instance * @throws JAXBException */ @Override public String asXML(T instance) throws JAXBException { Marshaller marshaller = getMarshaller(instance); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); if (fragment) { marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); } String result = getString(marshaller, instance); return result; }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
public static Marshaller getMarshaller(boolean isFragment, Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, isFragment); return m;/*from w w w . j av a2 s . c o m*/ }
From source file:com.dgwave.osrs.OsrsClient.java
protected String getString(OsrsRequest request) throws OsrsException { OPSEnvelope envelope = getEmptyEnvelope(); Map<String, Object> attrs = request.getAttributes(); Item pro = oj.createItem();// ww w. j a v a2s .co m pro.setKey("protocol"); pro.setStringValue(this.protocol); Item obj = oj.createItem(); obj.setKey("object"); obj.setStringValue(request.getObject()); Item act = oj.createItem(); act.setKey("action"); act.setStringValue(request.getAction()); Item att = oj.createItem(); att.setKey("attributes"); att.addDtAssoc(processAttrs(attrs)); DtAssoc c = oj.createDtAssoc(); c.addItem(pro); c.addItem(act); c.addItem(obj); c.addItem(att); ((List<Object>) envelope.getBody().getDataBlock().getDtAass()).add(c); try { Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty("com.sun.xml.internal.bind.xmlHeaders", "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n" + "<!DOCTYPE OPS_envelope SYSTEM '" + OSRSDIR + OSRSCONFIG + "ops.dtd'>"); //StringWriter writer = new StringWriter(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(envelope, baos); return baos.toString(); } catch (Exception e) { throw new OsrsException("Error creating envelope from request", e); } }
From source file:it.txt.access.capability.revocation.test.RevocationServiceTest.java
@Test public void testPost() throws UnsupportedEncodingException, IOException, JAXBException, ParserConfigurationException, NullPointerException, CapabilitySchemaFactoryException, CapabilitySchemaValidationHandlerException, DatatypeConfigurationException, GeneralSecurityException, InterruptedException { IoTTestForPOST testa = new IoTTestForPOST(); System.out.println("**********************************************************"); System.out.println("* CRP450 : CERTIFCATo *"); System.out.println("**********************************************************"); StringEntity input = new StringEntity(readFileAsString(System.getProperty("REVOCATION_FIRST"))); String result = testa.testPost(input); assertEquals(StatusCode.CRP450, result); System.out.println("**********************************************************"); System.out.println("* CRP451 : MISSING ID *"); System.out.println("**********************************************************"); StringEntity input0 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP451"))); String result0 = testa.testPost(input0); assertEquals(StatusCode.CRP451, result0); System.out.println("**********************************************************"); System.out.println("* CRP452 : MISSING ISSUER *"); System.out.println("**********************************************************"); StringEntity input1 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP452"))); String result1 = testa.testPost(input1); assertEquals(StatusCode.CRP452, result1); System.out.println("************************************************************************************"); System.out.println("*CRP453 : BAD ISSUER(the capRev issuer must be the subject of the authorising auCap*"); System.out.println("************************************************************************************"); StringEntity input2 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP453"))); String result2 = testa.testPost(input2); assertEquals(StatusCode.CRP453, result2); System.out.println("************************************************************************************"); System.out.println("* CRP454 : BAD AUTHORISING CAPABILITY(w.r.t. the syntactic validity *"); System.out.println("************************************************************************************"); StringEntity input3 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP454"))); String result3 = testa.testPost(input3); assertEquals(StatusCode.CRP454, result3); ///* w w w. ja va 2s.c o m*/ // // // System.out.println("************************************************************************************"); // // // // // System.out.println("* CRP455 : BAD SIGNER (the capRev issuer must be the certificate signer) *"); // // // // // System.out.println("************************************************************************************"); // System.out.println("************************************************************************************"); System.out.println("* CRP456 : BAD VALIDITY TIME FRAME *"); System.out.println("************************************************************************************"); StringEntity input5 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP456"))); String result5 = testa.testPost(input5); assertEquals(StatusCode.CRP456, result5); System.out.println( "********************************************************************************************************************"); System.out.println( "*CRP457 : BAD REVOKED (this happens when the revoked auCap is the same revocation or resolving its pending status)*"); System.out.println( "********************************************************************************************************************"); StringEntity input6 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP457"))); String result6 = testa.testPost(input6); assertEquals(StatusCode.CRP457, result6); System.out.println("************************************************************************************"); System.out.println("* CRP458 : EXIPERED AUTHORISING CAPABILITY *"); System.out.println("************************************************************************************"); //create two capability with the String revID = null; try { // Required initialization CapabilitySchemasLoader loader = new CapabilitySchemasLoader(null); String schemasPath = System.getProperty("PATH_CAPABILITY_SCHEMA"); loader.loadCapabilityEntities(schemasPath); CapabilitySchemaFactory.getInstance(schemasPath); creator = new RevocationCreationByHand(); creator.setAuthorisingCapability(new File(System.getProperty("AUCAP_CRP458"))); creator.setAuthorisingCapabilityExpiration(new Date(new Date().getTime() + 2000)); creator.setCertificatePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setKeystore(new File(System.getProperty("KEYSTORE"))); creator.setKeystorePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setNotificationEmail("donato.andrisani@network.txtgroup.com"); creator.setReason("Why? Because..."); creator.setRevocationScope("ALL"); creator.setRevokedCapability(new File(System.getProperty("REVCAP_CRP458"))); creator.setRevokedCapabilityExpiration(new Date(new Date().getTime() + 10000)); creator.setRevokedSinceDateTime(new Date()); CreatedTokens tokens = creator.createRevocation(); JAXBContext context = JAXBContext.newInstance(AccessRightsCapabilityType.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); System.out.println("#####----- Modified authorising capability -----#####"); Document xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getAuthorisingCapability(), xmlDocument); assertTrue("The signature of the authorising capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); System.out.println("#####----- Modified revoked capability -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevokedCapability(), xmlDocument); assertTrue("The signature of the revoked capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); context = JAXBContext.newInstance(CapabilityRevocationType.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); System.out.println("#####----- Revocation -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevocationToken(), xmlDocument); assertTrue("The signature of the revocation is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####"); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getAuthorisingCapability()); DataMapper insertCapability1 = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getRevokedCapability()); context = JAXBContext.newInstance(CapabilityRevocationType.class); revID = tokens.getRevocationToken().getRevocationID(); Writer writer = new FileWriter( "D:/PC-DONATO/workspace/RevocationService/revocationTest/revocationPOSTTest/output_458.xml"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); try { marshaller.marshal(tokens.getRevocationToken(), writer); System.out.println("CREATO FILE"); } finally { writer.close(); } } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (CapabilitySchemaFactoryException e) { e.printStackTrace(); } catch (CapabilitySchemaValidationHandlerException e) { e.printStackTrace(); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } StringEntity input7 = new StringEntity(readFileAsString(System.getProperty("OUTPUT_458"))); String result7 = testa.testPost(input7); Thread.sleep(4000); PendingRevocationsManagement p = new PendingRevocationsManagement(); p.processPendingCapabilityRevocation(); ODatabaseDocumentTx capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; List<ODocument> rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); ODocument element = rev.get(0); assertEquals(element.field(Constants.STATUS), "REJECTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP458); ODatabaseDocumentTx auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelPen = "select statusCode, status, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; List<ODocument> pen = auCapDb.command(new OCommandSQL(querySelPen)).execute(); ODocument element0 = pen.get(0); assertEquals(element0.field(Constants.STATUS), "REJECTED"); assertEquals(element0.field(Constants.STATUS_CODE), StatusCode.CRP458); assertNotNull(element0.field(Constants.RESOLVED_ON)); create.clearAll(); System.out.println("************************************************************************************"); System.out.println("* CRP459 : EXPIRED REVOKED CAPABILITY *"); System.out.println("************************************************************************************"); try { // Required initialization CapabilitySchemasLoader loader = new CapabilitySchemasLoader(null); String schemasPath = System.getProperty("PATH_CAPABILITY_SCHEMA"); loader.loadCapabilityEntities(schemasPath); CapabilitySchemaFactory.getInstance(schemasPath); creator = new RevocationCreationByHand(); creator.setAuthorisingCapability(new File(System.getProperty("AUCAP_CRP458"))); creator.setAuthorisingCapabilityExpiration(new Date(new Date().getTime() + 10000)); creator.setCertificatePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setKeystore(new File(System.getProperty("KEYSTORE"))); creator.setKeystorePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setNotificationEmail("alice@acme.com"); creator.setReason("Why? Because..."); creator.setRevocationScope("ALL"); creator.setRevokedCapability(new File(System.getProperty("REVCAP_CRP458"))); creator.setRevokedCapabilityExpiration(new Date(new Date().getTime() + 1000)); creator.setRevokedSinceDateTime(new Date()); CreatedTokens tokens = creator.createRevocation(); JAXBContext context = JAXBContext.newInstance(AccessRightsCapabilityType.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); System.out.println("#####----- Modified authorising capability -----#####"); Document xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getAuthorisingCapability(), xmlDocument); assertTrue("The signature of the authorising capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); System.out.println("#####----- Modified revoked capability -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevokedCapability(), xmlDocument); assertTrue("The signature of the revoked capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); context = JAXBContext.newInstance(CapabilityRevocationType.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); System.out.println("#####----- Revocation -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevocationToken(), xmlDocument); assertTrue("The signature of the revocation is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####"); OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(false); OGlobalConfiguration.CACHE_LEVEL1_ENABLED.setValue(false); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getAuthorisingCapability()); DataMapper insertCapability1 = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getRevokedCapability()); context = JAXBContext.newInstance(CapabilityRevocationType.class); revID = tokens.getRevocationToken().getRevocationID(); Writer writer = new FileWriter( "D:/PC-DONATO/workspace/RevocationService/revocationTest/revocationPOSTTest/output_459.xml"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); try { marshaller.marshal(tokens.getRevocationToken(), writer); System.out.println("CREATO FILE"); } finally { writer.close(); } } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (CapabilitySchemaFactoryException e) { e.printStackTrace(); } catch (CapabilitySchemaValidationHandlerException e) { e.printStackTrace(); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } StringEntity input8 = new StringEntity(readFileAsString(System.getProperty("OUTPUT_459"))); String result8 = testa.testPost(input8); Thread.sleep(5000); // PendingRevocationsManagement p = new PendingRevocationsManagement(); p.processPendingCapabilityRevocation(); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "REJECTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP459); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelPen = "select statusCode, status, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; pen = auCapDb.command(new OCommandSQL(querySelPen)).execute(); element0 = pen.get(0); assertEquals(element0.field(Constants.STATUS), "REJECTED"); assertEquals(element0.field(Constants.STATUS_CODE), StatusCode.CRP459); assertNotNull(element0.field(Constants.RESOLVED_ON)); assertEquals(StatusCode.CRP459, RevocationOutCome.code); create.clearAll(); System.out.println("************************************************************************************"); System.out.println("* CRP400 : BAD REVOCATION (w.r.t. the compliance with the XML SCHEMA) *"); System.out.println("************************************************************************************"); StringEntity input9 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP400"))); String result9 = testa.testPost(input9); assertEquals(StatusCode.CRP400, result9); System.out.println( "**********************************************************************************************************"); System.out.println( "*CRP403 : FORBIDDEN(AFTER RESOLUTION: the authorising auCAp has not the right thr revoke the given auCap)*"); System.out.println( "**********************************************************************************************************"); StreamSource xml = new StreamSource(System.getProperty("CAPABILITY1")); AccessRightsCapabilityType aucap = unMarshall(xml); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); xml = new StreamSource(System.getProperty("CAPABILITY2")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); StringEntity input10 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP403"))); String result10 = testa.testPost(input10); Thread.sleep(4000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP403, RevocationOutCome.code); insertCapability.clearAll(); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP201 : ACCEPTED (side POST) *"); System.out.println( "**********************************************************************************************************"); StringEntity input11 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); String result11 = testa.testPost(input11); assertEquals(StatusCode.CRP202, result11); create.clearAll(); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP409 : DUPLICATED *"); System.out.println( "**********************************************************************************************************"); StringEntity prov = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP409"))); String test = testa.testPost(prov); assertEquals(StatusCode.CRP202, test); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP201 : ACCEPTED (side RESOLUTION PENDING) *"); System.out.println( "**********************************************************************************************************"); xml = new StreamSource(System.getProperty("CAPABILITY22")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); xml = new StreamSource(System.getProperty("CAPABILITY33")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); input11 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); result11 = testa.testPost(input11); Thread.sleep(4000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP201, RevocationOutCome.code); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP201); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); String queryPend = "select statusCode, status, capabilityID, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; List<ODocument> res = auCapDb.command(new OCommandSQL(queryPend)).execute(); ODocument elem = res.get(0); String Revoked_Index_Sel = "select from index:" + Constants.REVOKED_INDEX_NAME; List<ODocument> Revoked_Index = auCapDb.command(new OCommandSQL(Revoked_Index_Sel)).execute(); assertEquals(elem.field(Constants.STATUS), "ACCEPTED"); assertEquals(elem.field(Constants.STATUS_CODE), StatusCode.CRP201); assertNotNull(elem.field(Constants.RESOLVED_ON)); assertNotNull(Revoked_Index); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP200 : WAS ACCEPTED *"); System.out.println( "**********************************************************************************************************"); xml = new StreamSource(System.getProperty("CAPABILITY11")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); StringEntity input12 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP200"))); String result12 = testa.testPost(input12); Thread.sleep(5000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP200, RevocationOutCome.code); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_a1192622c7f69af47a906ef7ef1a4b15'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "WAS_ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP200); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); queryPend = "select statusCode, status, capabilityID, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '_a1192622c7f69af47a906ef7ef1a4b15'"; res = auCapDb.command(new OCommandSQL(queryPend)).execute(); elem = res.get(0); assertEquals(elem.field(Constants.STATUS), "WAS_ACCEPTED"); assertEquals(elem.field(Constants.STATUS_CODE), StatusCode.CRP200); assertNotNull(elem.field(Constants.RESOLVED_ON)); // System.out.println("**********************************************************************************************************"); // System.out.println("* CRP500 : INTERNAL SERVER ERROR *"); // System.out.println("**********************************************************************************************************"); // // OServerAdmin admin = new // OServerAdmin(System.getProperty("REVOCATION_DB_PATH_ERRATO")); // admin.connect(Constants.iUserName, Constants.iUserPassword); // admin.dropDatabase(); // // StringEntity input13 = new // StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP500"))); // String result13 = testa.testPost(input13); // assertEquals(StatusCode.CRP500, result13); create.clearAll(); }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
public static Marshaller getMarshaller(Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE); return m;//from w w w. jav a 2 s .c om }
From source file:net.di2e.ecdr.commons.endpoint.rest.AbstractRestSearchEndpoint.java
@GET @Path("/osd.xml") @Produces("application/opensearchdescription+xml") public Response getOSD() { OpenSearchDescription osd = new OpenSearchDescription(); osd.setShortName(SystemInfo.getSiteName()); osd.setDescription(getServiceDescription()); osd.setTags("ecdr opensearch cdr ddf"); if (StringUtils.isNotBlank(SystemInfo.getOrganization())) { osd.setDeveloper(SystemInfo.getOrganization()); }/*from w w w . j a va2s . c o m*/ if (StringUtils.isNotBlank(SystemInfo.getSiteContatct())) { osd.setContact(SystemInfo.getSiteContatct()); } Query query = new Query(); query.setRole("example"); query.setSearchTerms("test"); osd.getQuery().add(query); osd.setSyndicationRight(SyndicationRight.OPEN); osd.getLanguage().add(MediaType.MEDIA_TYPE_WILDCARD); osd.getInputEncoding().add(StandardCharsets.UTF_8.name()); osd.getOutputEncoding().add(StandardCharsets.UTF_8.name()); // url example for (QueryLanguage lang : queryLanguageList) { Url url = new Url(); url.setType(MediaType.APPLICATION_ATOM_XML); url.setTemplate(generateTemplateUrl(lang)); osd.getUrl().add(url); } addSourceDescriptions(osd); StringWriter writer = new StringWriter(); InputStream is = null; try { JAXBContext context = JAXBContext.newInstance(OpenSearchDescription.class, SourceDescription.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.marshal(osd, writer); is = getClass().getResourceAsStream("/templates/osd_info.template"); if (is != null) { String osdTemplate = IOUtils.toString(is); osdTemplate = replaceTemplateValues(osdTemplate); String responseStr = osdTemplate + writer.toString(); return Response.ok(responseStr, MediaType.APPLICATION_XML_TYPE).build(); } else { return Response.serverError().entity("COULD NOT LOAD OSD TEMPLATE.").build(); } } catch (JAXBException | IOException e) { LOGGER.warn("Could not create OSD for client due to exception.", e); return Response.serverError().build(); } finally { IOUtils.closeQuietly(is); } }
From source file:ddf.catalog.registry.federationadmin.service.impl.FederationAdminServiceImpl.java
public void setParser(Parser parser) { this.configurator = parser.configureParser( Arrays.asList(RegistryObjectType.class.getPackage().getName(), net.opengis.ogc.ObjectFactory.class.getPackage().getName(), net.opengis.gml.v_3_1_1.ObjectFactory.class.getPackage().getName()), FederationAdminServiceImpl.class.getClassLoader()); this.configurator.addProperty(Marshaller.JAXB_FRAGMENT, true); this.parser = parser; }
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public Marshaller getMarshaller(boolean isFragment, Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, isFragment); return m;/*from ww w . ja v a 2s .c o m*/ }