List of usage examples for javax.xml.bind JAXB marshal
public static void marshal(Object jaxbObject, Result xml)
From source file:org.ebayopensource.turmeric.services.monitoringservice.junit.AbstractSOAQueryMetricsTest.java
/** * Test get metrics data./*from w w w .java2 s . c o m*/ * * @param requestXmlPath * the request xml path * @param respXmlPath * the resp xml path * @throws Exception * the exception */ public void testGetMetricsData(String requestXmlPath, String respXmlPath) throws Exception { ClassLoader cl = AbstractSOAQueryMetricsTest.class.getClassLoader(); InputStreamReader requestis = new InputStreamReader(cl.getResourceAsStream(requestXmlPath)); InputStreamReader responseis = new InputStreamReader(cl.getResourceAsStream(respXmlPath)); GetMetricsRequest req = JAXB.unmarshal(requestis, GetMetricsRequest.class); GetMetricsResponse resp = consumer.getMetricsData(req); ByteArrayOutputStream xmlResp = new ByteArrayOutputStream(); JAXB.marshal(resp, xmlResp); StringReader str = new StringReader(xmlResp.toString()); System.out.println(xmlResp.toString()); assertXMLEqual(responseis, str); }
From source file:org.ebayopensource.turmeric.tools.library.builders.CodeGenTypeLibraryGenerator.java
private static String getXJCArgs(String xsdFileName, String dependentJarPath, Set<String> depLibraries, TypeLibraryCodeGenContext codeGenCtx) { TypeLibraryInputOptions inputOptions = codeGenCtx.getTypeLibraryInputOptions(); String projectRoot = TypeLibraryUtilities.normalizePath(inputOptions.getProjectRoot()); String libraryName = inputOptions.getTypeLibraryName(); String xsdSrcPath = null;//from w w w. j ava 2 s . c om String typesNewSrcPath = TypeLibraryUtilities .normalizePath(TypeLibraryUtilities.getNewTypesFolderLocation(codeGenCtx, libraryName)); String genJavaDestPath = TypeLibraryUtilities .normalizePath(TypeLibraryUtilities.getGenSrcFolder(codeGenCtx, libraryName)); String xsdSrcnewPath = typesNewSrcPath + xsdFileName; File xsdinNewPath = new File(xsdSrcnewPath); //check if xsd exist in new structure if (xsdinNewPath.exists()) { xsdSrcPath = xsdSrcnewPath; } //support for existing typeLibs with older structure, search in older structure if xsd not found in new structure if (xsdSrcPath == null) { String typesSrcPath = TypeLibraryUtilities .normalizePath(TypeLibraryUtilities.getTypesFolder(codeGenCtx, libraryName)); xsdSrcPath = typesSrcPath + xsdFileName; } String episodeDestpath = TypeLibraryUtilities .normalizePath(TypeLibraryUtilities.getEpisodeFolder(codeGenCtx, libraryName)); String typeName = TypeLibraryUtilities.getTypeNameFromFileName(xsdFileName); String episodePath = episodeDestpath + typeName + ".episode"; /******************* populating arguments *****************/ StringBuilder xjcArg = new StringBuilder(); xjcArg.append("-extension").append(","); xjcArg.append("-nv").append(","); //-nv is to avoid throwing an error if a complex type has both an element as well as xs:any element if (!TypeLibraryUtilities.isEmptyString(episodePath)) { xjcArg.append("-episode").append(",").append(episodePath).append(","); } if (!TypeLibraryUtilities.isEmptyString(genJavaDestPath)) { xjcArg.append("-d").append(",").append(genJavaDestPath).append(","); } if (!TypeLibraryUtilities.isEmptyString(xsdSrcPath)) { xjcArg.append(xsdSrcPath).append(","); } String populateClasspath = populateClasspath(codeGenCtx); if (populateClasspath != null) { xjcArg.append(populateClasspath); } Set<String> depLibJarSet = new HashSet<String>(); if (!TypeLibraryUtilities.isEmptyString(dependentJarPath)) { String[] depLibrariesJarPath = dependentJarPath.split(","); for (String jarfile : depLibrariesJarPath) depLibJarSet.add(jarfile); String dependentJar = populateClasspathForDepJars(depLibJarSet); if (dependentJar != null) { xjcArg.append(dependentJar); } } /* preparing the episode file for -b option , this is not just a union of the sun-jaxb.episode files of dependent library, * but it has more intelligence built into it for handling multiple namespace, simple types java file creation issue. */ if (depLibraries.size() > 0) { try { File preProcessedMasterEpisodeFile = File.createTempFile("ebay", ".episode"); preProcessedMasterEpisodeFile.deleteOnExit(); Bindings masterEpisodeBindings = createMasterEpisodeBinding(codeGenCtx); JAXB.marshal(masterEpisodeBindings, preProcessedMasterEpisodeFile); File processedMasterEpisodeFile = getPostProcessedMasterEpisodeFile(preProcessedMasterEpisodeFile); xjcArg.append("-b"); xjcArg.append(","); xjcArg.append(processedMasterEpisodeFile); xjcArg.append(","); } catch (IOException e) { getLogger().log(Level.INFO, "Error while creating the master episode file for library " + libraryName); } } return xjcArg.toString(); }
From source file:org.ebayopensource.turmeric.tools.library.builders.CodeGenTypeLibraryGenerator.java
private static String getXJCArgsForPlugin(String dependentJarPath, String episodePath, String genJavaDestPath, String xsdSrcPath, String libraryName, Set<String> depLibraries, TypeLibraryCodeGenContext codeGenCtx) { StringBuilder xjcArg = new StringBuilder(); xjcArg.append("-extension").append(","); xjcArg.append("-nv").append(","); //-nv is to avoid throwing an error if a complex type has both an element as well as xs:any element if (!TypeLibraryUtilities.isEmptyString(episodePath)) { xjcArg.append("-episode").append(",").append(episodePath).append(","); }//from w ww . j a va 2s .c o m if (!TypeLibraryUtilities.isEmptyString(genJavaDestPath)) { xjcArg.append("-d").append(",").append(genJavaDestPath).append(","); } if (!TypeLibraryUtilities.isEmptyString(xsdSrcPath)) { xjcArg.append(xsdSrcPath).append(","); } String populateClasspath = populateClasspath(codeGenCtx); if (populateClasspath != null) { xjcArg.append(populateClasspath); } String dependentJar = populateClasspathForDepJars(depJarsAndPaths); if (dependentJar != null) { xjcArg.append(dependentJar); } /* * PREPARING THE episode file which is a union of all the dependent sun-jaxb.episode files */ if (depLibraries.size() > 0) { try { File preProcessedMasterEpisodeFile = File.createTempFile("ebay", ".episode"); preProcessedMasterEpisodeFile.deleteOnExit(); Bindings masterEpisodeBindings = createMasterEpisodeBinding(codeGenCtx); JAXB.marshal(masterEpisodeBindings, preProcessedMasterEpisodeFile); File processedMasterEpisodeFile = getPostProcessedMasterEpisodeFile(preProcessedMasterEpisodeFile); xjcArg.append("-b"); xjcArg.append(","); xjcArg.append(processedMasterEpisodeFile); xjcArg.append(","); } catch (IOException e) { getLogger().log(Level.INFO, "Error while creating the master episode file for library " + libraryName); } } xjcArg.append("-verbose"); return xjcArg.toString(); }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Authenticates a user with crowd. If authentication failed, raises a <code>RemoteException</code> * @param username/*from w w w .j a v a 2s . c o m*/ * @param password * @throws RemoteException */ public void authenticate(String username, String password) throws RemoteException { username = JID.unescapeNode(username); if (LOG.isDebugEnabled()) LOG.debug("authenticate '" + String.valueOf(username) + "'"); PostMethod post = new PostMethod( crowdServer.resolve("authentication?username=" + urlEncode(username)).toString()); AuthenticatePost creds = new AuthenticatePost(); creds.value = password; try { StringWriter writer = new StringWriter(); JAXB.marshal(creds, writer); post.setRequestEntity(new StringRequestEntity(writer.toString(), APPLICATION_XML, "UTF-8")); int httpCode = client.executeMethod(post); if (httpCode != 200) { handleHTTPError(post); } } catch (IOException ioe) { handleError(ioe); } finally { post.releaseConnection(); } LOG.info("authenticated user:" + username); }
From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
public void writeJmxConfigFile(JmxDatacollectionConfig jmxDatacollectionConfigModel, String outFile) { logger.debug("start marshalling"); JAXB.marshal(jmxDatacollectionConfigModel, new File(outFile)); logger.debug("finished marshalling"); }
From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java
public void writeJmxConfigFile(JmxDatacollectionConfig jmxDatacollectionConfigModel, String outFile) { JAXB.marshal(jmxDatacollectionConfigModel, new File(outFile)); }
From source file:sernet.verinice.service.commands.SyncCommand.java
/** * Works like/*from ww w. j ava 2s . c om*/ * {@link #SyncCommand(String, boolean, boolean, boolean, byte[])} but does * the JAXB serialization under the hood automatically. * * Called by ImportCSVWizard * * @param insert * @param update * @param delete * @param sr */ public SyncCommand(SyncParameter parameter, SyncRequest sr) { this.parameter = parameter; ByteArrayOutputStream bos = new ByteArrayOutputStream(); JAXB.marshal(sr, bos); this.fileData = bos.toByteArray(); this.stationId = ChangeLogEntry.STATION_ID; }