I have the XML file which starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<interface name="AccountAPING" owner="BDP" version="1.0.0" date="now()" namespace="com.betfair.account.api"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<description>Account API-NG</description>
...
afterward there are various blocks, such as:
<operation name="getDeveloperAppKeys" since="1.0.0">
<description>
Get all application keys owned by the given developer/vendor
</description>
<parameters>
<request/>
<simpleResponse type="list(DeveloperApp)">
<description>
A list of application keys owned by the given developer/vendor
</description>
</simpleResponse>
<exceptions>
<exception type="AccountAPINGException">
<description>Generic exception that is thrown if this operation fails for any reason.</description>
</exception>
</exceptions>
</parameters>
</operation>
........
<simpleType name="Status" type="string">
<validValues>
<value name="SUCCESS">
<description>Sucess status</description>
</value>
</validValues>
</simpleType>
........
<dataType name="TimeRange">
<description>TimeRange</description>
<parameter name="from" type="dateTime" mandatory="false">
<description>from, format: ISO 8601)</description>
</parameter>
<parameter name="to" type="dateTime" mandatory="false">
<description>to, format: ISO 8601</description>
</parameter>
</dataType>
How can I generate Java code from this using maven? I tried using "maven-jaxb2-plugin", but it can't parse this structure.
Please note
This is an XML file not not an xsd
I'm using Netbeans
First of all, you need the schema (xsd) that describes your xml sample. Without that schema you can not use Jaxb. You don't have a schema for the sample you shown xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is not the schema for your xml.
You can use free on-line tools to generate schemas from xml, but you can't rely on this tools without review the automated schema.
To generate Java code from a schema file use XJC, see here. Open a command prompt to the folder where you put your xsd file, and then generate java code you'll just need to type:
$ xjc nameOfSchemaFile.xsd
xjc is included with Java SDK.
Related
I have a problem while creating new project in soapUI and importing wsdl file from URL.It gives me the below exception
Error loading [http://localhost:8080/WS/PersonalDetails.xsd]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected end of file after null
My xsd include
<xsd:include schemaLocation="PersonalDetails.xsd" />
<xsd:include schemaLocation="PersonalRequest.xsd" />
Actual Location of the xsd
WS/src/main/webapp/schemas/PersonalDetails.xsd
WS/src/main/webapp/schemas/PersonalRequest.xsd
My spring-ws.xml
<bean id="MyWSService" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition" lazy-init="true">
<property name="schemaCollection">
<bean class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="inline" value="false" />
<property name="xsds">
<list>
<value>schemas/PersonalDetailsServiceOperations.xsd</value>
</list>
</property>
</bean>
</property>
<property name="portTypeName" value="MyWSEndpoint"/>
<property name="serviceName" value="MyWS" />
<property name="locationUri" value="/"/>
</bean>
My PersonalDetailsServiceOperations.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:person="http://MyWS.com/"
targetNamespace="http://MyWS.com/"
elementFormDefault="qualified">
<xsd:include schemaLocation="PersonalDetails.xsd" />
<xsd:include schemaLocation="PersonalRequest.xsd" />
</xsd:schema>
I'm using spring+Maven+xsd+jaxb
Please help
Many Thanks
Often this happens because you're not pasting in the correct location to the WSDL into SOAP UI. When you browse to your WSDL in a browser, spring-ws will serve it up on almost any url, so long as it ends in XYZService.wsdl (or whatever you have configured it to be). The downside to this is, when you have XSD imported using relative paths inside your schema somewhere, SOAP UI tries to to resolve the relative path based on the path you gave it, but like I said, that may not actually be the real path to the WSDL.
For example, in our application we have a Spring-ws web service call ProcessService. It's served up at http://localhost:11000/ws/service/process/ProcessService.wsdl and it contains an imported XSD using relative paths. If you paste this URL into SOAP UI and run it, it correctly resolves the path to XSD. However, you can browse to http://localhost:11000/hello-world/ProcessService.wsdl and it will still serve you up the WSDL even though the URL is not correct. Now if you take http://localhost:11000/hello-world/ProcessService.wsdl and paste it into SOAP UI it won't be able to resolve the relative path to imported XSD correctly because that's not the actual URL. In this case SOAP UI gives you that exact error.
I would browse to your XSD in the browser and make sure you can see it. Then I would check the URL you are pasting into SOAP UI and see if from the relative URLs actually resolve correctly. If not, you need to give the correct path to SOAP UI.
One of the legacy applications XML schema definition has two types defined with same name in different cases.
<xsd:complexType name="effectType">
<xsd:complexType name="EFFECTType">
Schema validation works fine. But when I use JAXB to generate Java objects, it complains that two classes can't be generated with same.
As this schema used by existing clients, I can't change it. Is there any workaround for it so that it will allow me to generate Java objects for the schema using JAXB?
You could use below bindings to change the name of generated class.
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:annox="http://annox.dev.java.net"
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
<bindings schemaLocation="../path of your xsd/schema.xsd">
<bindings node="//xsd:schema//xsd:complexType[#name='EFFECTType']">
<class name="EffectTypeTwo" />
</bindings>
</bindings>
</bindings>
I have a custom content model I created for Alfresco that has type with a d:date property. I am able to build the repository and share projects with seemingly no errors. However, I am unable to search by the properties using the data type d:date or d:int. I resolved the d:int problem by changing the data type to d:text and adding a regex constraint, but I'm not sure if that would be prudent for the d:date property.
Is there some additional configuration that I need to supply or create in order to search by properties that are not d:text?
Here is a snippet showing the type declaration:
<types>
<!-- Enterprise-wide generic document type -->
<type name="gl:x">
<title>Document</title>
<parent>cm:content</parent>
<properties>
<property name="gl:period">
<type>d:text</type>
</property>
<property name="gl:year">
<type>d:text</type>
<constraints>
<constraint ref="gl:documentYears" />
</constraints>
</property>
<property name="gl:docType">
<type>d:text</type>
<constraints>
<constraint ref="gl:documentTypeList" />
</constraints>
</property>
<property name="gl:date">
<type>d:date</type>
</property>
</properties>
</type>
</types>
The share search forms and properties forms seem to be rendering correctly, so I don't think that there is any problem within those.
The advanced search page accepts two types of parameters.
One is simply the "keywords" field. This performs a full text search, i.e. it looks for the provided keywords in ANY text property. There is no need to configure the full text search for custom types (e.g. your gl:x) - it automatically picks up any text property in any model in the system.
The other is the group of single parameters: name, title, description, mime-type, modified-date, modifier. These properties can be of any type. A d:date property would be perfectly acceptable here, as the modified-date parameter testifies.
But here custom properties are not picked-up automatically. They need to be configured explicitly.
Notice that in the upper part of the advanced search page is a drop-down called "Look for" with two options: content and folders. The best approach would be to add an option for your content type gl:x and to configure a search form for it.
You can find the definition of the two standard search forms in tomcat/webapps/share/WEB-INF/classes/alfresco/share-form-config.xml. The file is rather long so here are the two sections to look for:
<config evaluator="model-type" condition="cm:content">
<forms>
<!-- Default Create Content form -->
<form>
</form>
<!-- Document Library Create Google Doc form -->
<form id="doclib-create-googledoc">
</form>
<!-- Search form -->
<form id="search">
</form>
</forms>
</config>
<!-- cm:folder type (creating nodes) -->
<config evaluator="model-type" condition="cm:folder">
<forms>
<!-- Document Library Common form -->
<form id="doclib-common">
</form>
<!-- Search form -->
<form id="search">
</form>
</forms>
</config>
I've skipped the details, but what is important is that "cm:content" and "cm:folder" each defines a <form id="search"> with the desired search properties/parameters.
As an experiment you could modify share-form-config.xml directly and add your own definition:
<config evaluator="model-type" condition="gl:x">
<forms>
<!-- Search form -->
<form id="search">
<field-visibility>
<show id="gl:date" />
</field-visibility>
<appearance>
<field id="gl:date">
<control template="/org/alfresco/components/form/controls/daterange.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
Also you have to add the new search form to the AdvancedSearch configuration found in tomcat/webapps/share/WEB-INF/classes/alfresco/share-config.xml:
<config evaluator="string-compare" condition="AdvancedSearch">
<advanced-search>
<forms>
<form labelId="search.form.label.cm_content" descriptionId="search.form.desc.cm_content">cm:content</form>
<form labelId="search.form.label.cm_folder" descriptionId="search.form.desc.cm_folder">cm:folder</form>
<form labelId="search.form.label.gl_x" descriptionId="search.form.desc.gl_x">gl:x</form>
</forms>
</advanced-search>
</config>
Remember to restart alfresco after every change.
When you're satisfied with the results, it would be better to move your custom definitions to a separate share-config-custom.xml in your project (share-config.xml and share-form-config.xml should never be modified directly).
For more details: https://wiki.alfresco.com/wiki/Share_Advanced_Search
I have created a .jrxml file using iReport eclipse plugin. It takes json as an input. I have created jsonDataAdaptor inside the eclipse to export the report. Now I want to do the same using java, not iReport.
I have a .jrxml file and i am compiling the file using:
JasperCompileManager.compileReportToFile
In the .jrxml file I have created some fields for the json and have used in textField.
<field name="username" class="java.lang.String">
<fieldDescription><![CDATA[username]]></fieldDescription>
</field>
<field name="pwd" class="java.lang.String">
<fieldDescription><![CDATA[pwd]]></fieldDescription>
</field>
I am having the username and pwd's in the test.json that is placed in my local drive in the same path as the .jrxml file.
My dataAdapter(in the same folder as .jrxml file):
<?xml version="1.0" encoding="UTF-8" ?>
<jsonDataAdapter class="net.sf.jasperreports.data.json.JsonDataAdapterImpl">
<name>jsonDataAdaptor</name>
<fileName>C:\test\test.json</fileName>
<useConnection>false</useConnection>
<timeZone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
dirty="false" DSTSavings="0" raw-offset="19800000"
xsi:type="java:sun.util.calendar.ZoneInfo">
<ID>Asia/Calcutta</ID>
<display-name>India Standard Time</display-name>
</timeZone>
<locale country="US" language="en" />
<selectExpression></selectExpression>
<datePattern></datePattern>
<numberPattern></numberPattern>
</jsonDataAdapter>
The problem is, when I am exporting the same into html I am getting values as null.
Here is the link for jasper datasource adapter.
Any idea why this error is happening and how to fix it? I'm getting this error when trying to parse/load a config file:
Error
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this.
Error: URI=null Line=3: Document root element "persistence", must match DOCTYPE root "null".
Error: URI=null Line=3: Document is invalid: no grammar found.
null
[]
null
Main code
public static void main(String[] args) throws ConfigurationException {
config = new XMLPropertiesConfiguration(new File("META-INF/vamola.xml"));
System.out.println(config.getString("persitence-unit.provider"));
System.out.println(config.getList("persistence-unit.properties.name"));
}
XML FILE
<?xml version="1.0"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="dbBank" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>br.ufg.inf.server.Account</class>
<class>br.ufg.inf.server.UserBank</class>
<properties>
<property name="toplink.jdbc.user" value="derby" />
<property name="toplink.jdbc.password" value="senha" />
<property name="toplink.jdbc.url" value="jdbc:derby://192.168.80.125:1527/db/master/dbBank;create=true"/>
<property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
<property name="toplink.ddl-generation" value="create-tables" />
<property name="toplink.logging.level" value="OFF" />
<property name="toplink.target-database" value="Derby" />
</properties>
</persistence-unit>
</persistence>
If your parsing an XML document with validation turned on, you need to specify either a DTD or an XML schema in a DOCTYPE at the start of your XML document. Your parser is basically complaining that it doesn't know how to validate your document because no grammer has been specified to validate the mark up.
You already have an XML schema, so you probably want:
<!DOCTYPE schema PUBLIC "http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
If you want to turn off validation, you need something like:
spf.setValidating(false); (Where spf is a SaxParserFactory)
The exception says that an ErrorHandler wasn't set. This means that the parser uses its built-in error handler, which simply writes messages to the console. If you actually want to validate, you need to create an ErrorHandler implementation and attach it to the DocumentBuilder.
For more information, read this: http://www.kdgregory.com/index.php?page=xml.parsing (error handlers are about 1/3 of the way down).
Or, as other responses have suggested, you can just turn validation off.
The XML document defines the default namespace http://java.sun.com/xml/ns/persistence and includes a url, where the schema can be found (xsi:schemaLocation attribute, first value is the namespace, second the url or path).
Please double-check if this url is accessible at the time you parse it. An alternative is to download the schema, put it on the file system and modify the xsi:schemaLocation value.