SOAP parameters passed to Nav 2013 R2 cause error as if they are null - html

I`m trying to call a Nav 2013 R2 web service codeunit with a custom SOAP command and I get a response indicating that the parameters being passed are null, which they are not.
Does anyone have an answer as to why this is happening or could point me in a direction that could help solve this? Thanks!
Here is the SOAP request:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><TransferOrderCreate xmlns="urn:microsoft-dynamics-schemas/Codeunit/WebTestCodeunit"><ptext>this is some text</ptext><pint>999</pint></TransferOrderCreate></soap:Body></soap:Envelope>
Here is the SOAP response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Service.WebMetadata.ServiceBrokerException</faultcode><faultstring xml:lang="en-CA">Parameter ptext in method TransferOrderCreate in service WebTestCodeunit is null! </faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter ptext in method TransferOrderCreate in service WebTestCodeunit is null! </string></detail></s:Fault></s:Body></s:Envelope>
Here is the service as exposed by Nav:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit" debug="true">
<script id="FirebugLite" firebugIgnore="true" extension="Chrome"/>
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit">
<element name="TransferOrderCreate">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="ptext" type="string"/>
<element minOccurs="1" maxOccurs="1" name="pint" type="int"/>
</sequence>
</complexType>
</element>
<element name="TransferOrderCreate_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="TransferOrderCreate">
<part name="parameters" element="tns:TransferOrderCreate"/>
</message>
<message name="TransferOrderCreate_Result">
<part name="parameters" element="tns:TransferOrderCreate_Result"/>
</message>
<portType name="WebTestCodeunit_Port">
<operation name="TransferOrderCreate">
<input name="TransferOrderCreate" message="tns:TransferOrderCreate"/>
<output name="TransferOrderCreate_Result" message="tns:TransferOrderCreate_Result"/>
</operation>
</portType>
<binding name="WebTestCodeunit_Binding" type="tns:WebTestCodeunit_Port">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="TransferOrderCreate">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit:TransferOrderCreate" style="document"/>
<input name="TransferOrderCreate">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="TransferOrderCreate_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
</binding>
<service name="WebTestCodeunit">
<port name="WebTestCodeunit_Port" binding="tns:WebTestCodeunit_Binding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://lt0619.xx.xxxxxxxxx.xx:11047/Trunk/WS/7002/Codeunit/WebTestCodeunit"/>
</port>
</service>
</definitions>

Check namespaces in wsdl definition and your request. Namespaces are case sensitive.
wsdl:
urn:microsoft-dynamics-schemas/codeunit/WebTestCodeunit
reqest:
urn:microsoft-dynamics-schemas/Codeunit/WebTestCodeunit
This could throw the exception you see.

Related

Combine GeoServer ShapeFile with WMS Basemap on a Leaflet Client

I am trying to combine a WMS with an external ShapeFile uploaded to my GeoServer.
I got my WMS Map working fine with a leaflet client but I have no idea how to implement my Shapefile.
I uploaded my ShapeFile on my GeoServer in the Vectordata section.
When I do the WFS DescribeFeature request I get this answer:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Assignment11="http://localhost:8080/geoserver/Assignment11" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://localhost:8080/geoserver/Assignment11">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2/feature.xsd"/>
<xsd:complexType name="krankenhaeuserType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:PointPropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ID" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_TELEFON" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_URL" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="KH_ART" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="TRAEGER" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="RECHTSFOR" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BS_BEZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="PLZ" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ADRESSE" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ORT" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="DISZIPLIN" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="BETTENZAHL" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="krankenhaeuser" substitutionGroup="gml:_Feature" type="Assignment11:krankenhaeuserType"/>
</xsd:schema>
When I do the GetFeature Request with outputFormat=JSON (http://localhost:8080/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=Assignment11:krankenhaeuser&outputFormat=JSON) the answer is a complete FeatureCollection of all my features.
The thing I am missing now is that I want to add all those Features to my map as a marker for example.
Thats the main problem.
When I got that working, I want to hide all those Features and when I click the map I want the closest Feature to pop up.
This is my code so far:
<!DOCTYPE html>
<html>
<head>
<title>Assignment 11</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet#1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
</head>
<body>
<div id="mapid" style="width: 1400px; height: 700px;"></div>
<script>
var mymap = L.map('mapid').setView([51.28, 7.33], 8);
var nrwTopo = L.tileLayer.wms('http://www.wms.nrw.de/geobasis/wms_nw_dtk?', {
layers: 'WMS_NW_DTK',
format: 'image/png',
transparent: true
}).addTo(mymap);
</script>
</body>
</html>

Mule loses payload after data mapper call

I am using Mule 3.6.1 and have a flow that reads a CSV file and then splits the file and passes in each record to the datamapper. I can see that the record is present prior to data mapper but once the message leaves the datamapper, the payload is empty.
How can I fix this? Please note that the Choice will have 3 possible datamappers to select in the completed flow.
The flow is:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
<context:property-placeholder location="mule-app.properties" />
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<import class="org.mule.util.StringUtils" />
<import class="org.mule.util.ArrayUtils" />
</expression-language>
</configuration>
<data-mapper:config name="test_mapper" transformationGraphPath="csv_to_json_1.grf" doc:name="test_mapper"/>
<flow name="read-file" >
<file:inbound-endpoint path="${file.unprocessed.location}" moveToPattern="#[message.inboundProperties['originalFilename']]" moveToDirectory="${file.processed.location}" responseTimeout="10000" doc:name="Files" mimeType="text/csv" >
<file:filename-regex-filter pattern="test.csv" caseSensitive="true"/>
</file:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<splitter expression="#[rows=StringUtils.split(message.payload,'\n\r'); ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter"/>
<set-property propertyName="testFilename" value="#[flowVars.originalFilename]" doc:name="Set Filename"/>
<choice doc:name="Choice">
<when expression="#[message.outboundProperties.'testFilename'=='test.csv']">
<data-mapper:transform config-ref="CSV_To_JSON" doc:name="CSV To JSON"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<object-to-string-transformer doc:name="Object to String"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
and CSV input file:
DeptID,Dept,Staff
5LL/A,Human Resources,4.00
and GRF file showing data mappings:
<?xml version="1.0" encoding="UTF-8"?><Graph __version="3.5.0" author="" created="Wed May 25 14:20:34 BST 2016" description="CSV To JSON" guiVersion="3.4.4.P" id="1464184235950" licenseCode="Unlicensed" licenseType="Unknown" modified="Wed May 25 14:20:34 BST 2016" modifiedBy="" name="CSV_To_JSON" preview-file="C:/test.csv" revision="1.0" showComponentDetails="false">
<Global>
<Metadata __referenceCounter="1" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _type="Input" id="f79c6373-b266-4a78-91c9-3a731304eef1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field containerType="SINGLE" label="DeptID" name="DeptID" size="10" type="string"/>
<Field containerType="SINGLE" label="Dept" name="Dept" size="10" type="string"/>
<Field containerType="SINGLE" eofAsDelimiter="true" label="Staff" name="Staff" size="10" type="string"/>
<Field __artificialType="_id" auto_filling="global_row_count" name="__id" type="long"/>
</Record>
</Metadata>
<Metadata __index="0" __referenceCounter="1" __sourcePath="{}/test" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _id="__id" _type="Output" id="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
<Field __index="1" __sourcePath="{}/test/Dept" containerType="SINGLE" label="Dept" name="Dept" type="string"/>
<Field __index="0" __sourcePath="{}/test/DeptID" containerType="SINGLE" label="DeptID" name="DeptID" type="string"/>
<Field __index="2" __sourcePath="{}/test/Staff" containerType="SINGLE" label="Staff" name="Staff" type="string"/>
</Record>
</Metadata>
<Dictionary>
<Entry id="DictionaryEntry0" input="true" name="inputPayload" output="false" type="object"/>
<Entry id="DictionaryEntry1" input="false" name="outputPayload" output="true" type="object"/>
</Dictionary>
</Global>
<Phase number="0">
<Node charset="UTF-8" enabled="enabled" fileURL="dict:inputPayload" guiName="CSV READER" guiX="20" guiY="20" id="DATA_READER0" quoteCharacter="both" quotedStrings="true" skipRows="1" trim="true" type="DATA_READER">
<attr name="_data_format"><![CDATA[CSV]]></attr>
<attr name="__dataSourceDefinition"><![CDATA[C:/test.csv]]></attr>
</Node>
<Node enabled="enabled" guiName="Foreach 'test' -> 'test'" guiX="460" guiY="20" id="FOREACH_TEST_TEST" transformClass="com.mulesoft.datamapper.transform.MelRecordTransform" type="REFORMAT">
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = num2str(input.__id);
//END -> DO NOT REMOVE
output.DeptID = input.DeptID;
output.Dept = input.Dept;
output.Staff = input.Staff;
]]></attr>
</Node>
<Node cacheInMemory="true" charset="UTF-8" enabled="enabled" fileURL="dict:outputPayload" guiName="JSON WRITER" guiX="900" guiY="20" id="JSON_WRITER0" type="JSON_WRITER">
<attr name="mapping"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<clover:collection clover:name="test" xmlns:clover="http://www.cloveretl.com/ns/xmlmapping">
<item clover:inPort="0">
<DeptID>$0.DeptID</DeptID>
<Dept>$0.Dept</Dept>
<Staff>$0.Staff</Staff>
</item>
</clover:collection>]]></attr>
<attr name="_data_format"><![CDATA[JSON]]></attr>
</Node>
<Edge debugMode="true" fromNode="DATA_READER0:0" guiBendpoints="" id="Edge0" inPort="Port 0 (in)" metadata="f79c6373-b266-4a78-91c9-3a731304eef1" outPort="Port 0 (output)" toNode="FOREACH_TEST_TEST:0"/>
<Edge debugMode="true" fromNode="FOREACH_TEST_TEST:0" guiBendpoints="" id="Edge1" inPort="Port 0 (in)" metadata="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1" outPort="Port 0 (out)" toNode="JSON_WRITER0:0"/>
</Phase>
</Graph>
In the splitter your are already stripping of the header.
In DataMapper you have the option 'Rows to Ignore' set to "1".
Set that to "0", or change the expression in your splitter.
Because now you tell DataMapper to ignore your one and only row!
You are ignoring the row coming into the datamapper and hence there is no mapping being done remove "rows to ignore".Then the mapper will work on the row coming inside

SoapUI generates JSON property for namespace

I generate a WADL with CXF as described in CXF – Missing WADL method parameter element types with JSON JAX-RS services.
I tried to generate the JSON request body in SoapUI ("Recreates a default representation from the schema"), but I get the wrong JSON including namespace.
Code:
CXF configuration:
<bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
</bean>
<jaxrs:server address="/rest/1" id="test" staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="testResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
<ref bean="wadlGenerator" />
</jaxrs:providers>
</jaxrs:server>
WADL:
<?xml version="1.0"?>
<application xmlns:prefix1="http://www.test.com/test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import/>
<xs:element name="testModel" type="testModel"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:complexType name="testModel">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars>
<resources base="http://localhost:8080/test-app/services/rest/1">
<resource path="/test">
<method name="POST">
<request>
<representation mediaType="application/json" element="prefix1:testModel"/>
</request>
<response status="204"/>
</method>
</resource>
</resources>
</application>
JSON:
{
"#xmlns:test": "http://www.test.com/test",
"id": "?",
"name": "?"
}
Is that a bug/missing feature of SoapUI or is there something wrong with my WADL?

src-resolve.4.2: Error resolving component 'InputData'. It was detected that 'InputData' is in namespace 'http://www.w3.org/2001/XMLSchema'

I'm trying to make the input for my BPEL a complextype, but I get the error in object.
I hope someone is able to give me a hint. Thank you in advance.
This is my code:
<?xml version="1.0"?>
<definitions name="testBPEL2"
targetNamespace="http://test.bpel2"
xmlns:tns="http://test.bpel2"
xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TYPE DEFINITION - List of types participating in this BPEL process
The BPEL Designer will generate default request and response types
but you can define or import any XML Schema type and use them as part
of the message types.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<types>
<schema attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://test.bpel2"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="testBPEL2Request">
<complexType>
<sequence>
<element name="input" type="InputData"/>
</sequence>
</complexType>
</element>
<element name="testBPEL2Response">
<complexType>
<sequence>
<element name="result" type="OutPutData"/>
</sequence>
</complexType>
</element>
<complexType name="InputData">
<sequence>
<element name="citta" type="string"></element>
<element name="id_libro" type="int"></element>
</sequence>
</complexType>
<complexType name="OutputData">
<sequence>
<element name="libreria" type="string"></element>
<element name="prezzo" type="int"></element>
</sequence>
</complexType>
</schema>
</types>
I hope someone is able to give me a hint. Thank you in advance.
I guess
<sequence>
<element name="input" type="InputData"/>
</sequence>
should read
<sequence>
<element name="input" type="tns:InputData"/>
</sequence>

JAXB XML Object Marshalling without namespace prefixes

Im working on a java project where i need to read some objects from an XML file, do some processing which will alter the object´s atributes and then write the Object to another XML file. For that purpose, i am using JAXB with its marshalling and unmarshalling capabilities, each of them in a method, like this:
private MyObject unmarshallXMLFile(String file) {
MyObject t=null;
try {
jc = JAXBContext.newInstance("foo.bar");
Unmarshaller unmarshaller = jc.createUnmarshaller();
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
unmarshaller.setSchema(sf.newSchema(new File("MySchema.xsd")));
t = (Task) unmarshaller.unmarshal(new File(file));
} catch (JAXBException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
return t;
}
private void marshallXMLFile(String file) {
task.setReplay(Boolean.TRUE);
Marshaller marshaller;
try {
marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.marshal(task, new FileOutputStream(file));
} catch (JAXBException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
The problem is that automatically-generated namespace prefixes such as ns2 or ns3 keep appearing in the output file, and then when i want to reuse this files with the unmarshallXMLFile method (i will be using the output files as input again later) it wont get validated against the schema, and throws a org.xml.sax.SAXParseException. Here are the files i wrote:
XML Schema: MySchema.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/MySchema"
xmlns:spm="http://www.example.org/MySchema"
elementFormDefault="qualified"
attributeFormDefault="qualified">
<element name="task" >
<complexType>
<sequence>
<element name="replay" type="boolean" default="false"/>
<element name="threads" type="spm:spThread" maxOccurs="unbounded" minOccurs="1" />
</sequence>
</complexType>
</element>
<complexType name="spThread">
<sequence>
<element name="SPThreadID" type="int" />
<element name="durtime" minOccurs="0" default="0">
<simpleType>
<restriction base="int">
<minInclusive value="0" />
</restriction>
</simpleType>
</element>
<element name="minexecutions" minOccurs="0" default="0">
<simpleType>
<restriction base="int">
<minInclusive value="0" />
</restriction>
</simpleType>
</element>
<element name="numThreads" type="int" />
<element name="procedures" type="spm:procedure" minOccurs="1"
maxOccurs="unbounded" />
</sequence>
</complexType>
<complexType name="procedure">
<sequence>
<element name="id" type="int" minOccurs="1" />
<element name="name" type="string" minOccurs="1" />
<element name="weight" minOccurs="1">
<simpleType>
<restriction base="int">
<minInclusive value="0" />
<maxInclusive value="100" />
</restriction>
</simpleType>
</element>
<element name="parameterPool" type="spm:parameter" nillable="true"
minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
<complexType name="parameter">
<sequence>
<element name="name" type="string" minOccurs="1" />
<element name="dataType" type="spm:parameterDataType" default="integer"/>
<element name="parmType" type="spm:parameterType" default="in"
minOccurs="0" />
<element name="minValue" type="string"/>
<element name="maxValue" type="string"/>
<element name="value" type="string"/>
</sequence>
</complexType>
<simpleType name="parameterDataType">
<restriction base="string">
<enumeration value="integer" />
<enumeration value="varchar" />
<enumeration value="char" />
</restriction>
</simpleType>
<simpleType name="parameterType">
<restriction base="string">
<enumeration value="in" />
<enumeration value="out" />
<enumeration value="in_out" />
</restriction>
</simpleType>
</schema>
input file:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<task xmlns="http://www.example.org/MySchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/MySchema MySchema.xsd ">
<replay>true</replay>
<threads>
<SPThreadID>0</SPThreadID>
<durtime>10</durtime>
<minexecutions>2</minexecutions>
<numThreads>3</numThreads>
<procedures>
<id>1</id>
<name>run</name>
<weight>15</weight>
<parameterPool>
<name>energy</name>
<dataType>integer</dataType>
<parmType>in</parmType>
<minValue>10</minValue>
<maxValue>50</maxValue>
<value>11</value>
</parameterPool>
<parameterPool>
<name>speed</name>
<dataType>integer</dataType>
<parmType>in</parmType>
<minValue>12</minValue>
<maxValue>80</maxValue>
<value>13</value>
</parameterPool>
</procedures>
</threads>
</task>
output file (without any processing whatsoever: just unmarshalling and marshalling back with the methods mentioned earlier)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:task xmlns="http://www.example.org/MySchema" xmlns:ns2="http://www.example.org/MySchema.xsd">
<replay>true</replay>
<threads>
<SPThreadID>0</SPThreadID>
<durtime>10</durtime>
<minexecutions>2</minexecutions>
<numThreads>3</numThreads>
<procedures>
<id>1</id>
<name>run</name>
<weight>15</weight>
<parameterPool>
<name>energy</name>
<dataType>integer</dataType>
<parmType>in</parmType>
<minValue>10</minValue>
<maxValue>50</maxValue>
<value>11</value>
</parameterPool>
<parameterPool>
<name>speed</name>
<dataType>integer</dataType>
<parmType>in</parmType>
<minValue>12</minValue>
<maxValue>80</maxValue>
<value>13</value>
</parameterPool>
</procedures>
</threads>
</ns2:task>
exception (when using the ouput file again as an input):
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: The declaration of the element'ns3:task' could not be found.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:326)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:500)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:206)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:148)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:153)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:162)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:180)
at Test.main(Test.java:48)
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: The declaration of the element'ns3:task' could not be found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaValidatorHandler.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:85)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:113)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:202)
... 6 more
I´ve been reading about the subject and tried loads of related answers, but none of them seems to remove the prefixes. I went trough this guide but the version of jaxb i am using does not support NamespacePrefixMapper. I tried using annotations as described here to configure the prefixes but that wouldnt work.
Maybe there is a way of getting rid of this namespace prefixes: all the forums, answers and discussions i´ve found talk about customizing this prefixes, i just want to get rid of them. But somehow it makes me think that i´m missing something in both my input file and schema. Are they well written? I would say that right there is the problem, because it is the first time i work with xml and xsd at this depth, and what i´ve done is only based on what i´ve found online. Any tips on improving the xml and xsd designs would be highly appreciated
should i be using some kind of prefixes in the input file or in the schema so the JAXB framework wont generate random prefixes at time of marshalling?
thanks in advance, i hope you guys can help me.
--
Thank you very much for the answer. In that way i can use the NamespacePrefixMapper. However, when i use it, my code keeps throwing exceptions when i run it:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name javax.xml.bind.Messages, locale de_DE
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:863)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:832)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
at javax.xml.bind.Messages.format(Messages.java:47)
at javax.xml.bind.Messages.format(Messages.java:36)
at javax.xml.bind.PropertyException.<init>(PropertyException.java:99)
at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:349)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:527)
at Test.main(Test.java:95)
I found that it has to do something with a .properties file: i am not using anything like it, i havent changed anything.
Instead of specifying the #XmlElement's namespace attribute in every element, it's simpler to annotate at package level.
You do that by creating a file package-info.java just underneath the package you want to annotate.
For example, if you want to annotate the package org.example, then a file named package-info.java must be placed within the directory org/example with the following content:
#javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/StoredProceduresSchema", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.example;
It's important to note that you must annotate every package that contains classes that your plan to marshal or are referenced by those.
Hope this helps :)
Try using a NamespacePrefixMapper:
NamespacePrefixMapper mapper = new NamespacePrefixMapper() {
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return "";
}
};
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
Well, after some research, i tried using the #XMLElement tag on every attribute of the classes i am trying to serialize, specifying clearly what my namespace was, and using the same one on every attribute:
#XmlElement(required = true, name="myObjectPool", namespace="http://www.example.org/StoredProceduresSchema")
protected List<MyObject> myObjectPool;
It worked flawlessly: no more weird namespaces in the marshalled file.
I wanna thank for his answer: i tried that as well, but i got a weird language bundle related exception. Im glad this simpler approach solved the issue.
Then you might be using a different JAXB implementation then the reference. Read this article and try again: http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html (or if you are lazy: replace com.sun.xml.bind.namespacePrefixMapper with com.sun.xml.internal.bind.namespacePrefixMapper)
Java 7/8 solution
This problem is related to the default implementation JAXB Provider. I have found a solution using a different implementation: EclipseLink MOXy.
1. add the dependency in pom.xml
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.5.0</version>
</dependency>`
2. create a file jaxb.properties containing the following line
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
move the file into the package model
3. create package-file.java into the model package
#XmlSchema(xmlns = { #XmlNs(prefix = "video", namespaceURI = "http://www.google.com/schemas/sitemap-video/1.1"),
#XmlNs(prefix = "", namespaceURI = "http://www.sitemaps.org/schemas/sitemap/0.9")})
package it.my.sitemap.model;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlSchema;