Problems in Generating FIle by wsdl2java - cxf

there are some strange brain racked occurring to me.
In a given xsd file,we find a xml element that says as below:
<xsd:element name="getAllOperationsSystemsRequest">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
and a wsdl operation is linked to the element
<wsdl:operation name="getAllOperationsSystems">
<wsdl:input message="tns:getAllOperationsSystemsRequest"/>
<wsdl:output message="tns:getAllOperationsSystemsResponse"/>
<wsdl:fault name="getAllOperationsSystemsException" message="tns:getAllOperationsSystemsException"/>
</wsdl:operation>
Apparently , getAllOperationsSystemsRequest is not bound to any known type ( the attribute "type" is missing.
As the result,after we exeucte wsdl2java tool,we finally get a method definition :
public org.tmforum.mtop.mri.xsd.osr.v1.MultipleObjectsResponseType getAllOperationsSystems(
javax.xml.ws.Holder<org.tmforum.mtop.fmw.xsd.hdr.v1.Header> mtopHeader,
java.lang.**Object** mtopBody
)throws GetAllOperationsSystemsException
An Object instead of OperationsSystemsRequest is generated as the input parameter type,(actually the OperationsSystemsRequest never come into existence.
Finally ,we get a bold runtime error in marshall/unmarshall
Caused by: com.sun.istack.SAXException2: Instance of "javax.xml.bind.JAXBElement" is substituting "java.lang.Object", but "javax.xml.bind.JAXBElement" is bound to an anonymous type.
I am really appreciated anyone for information to solve it. Tnanks in advance.

Per XML Schema spec, the "type" for the getAllOperationsSystemsRequest element is an xsd:anyType. Basically, anything. That is why Object is generated in the code. The code generators generate for types, not elements (mostly). If the type is only represented in an element, then it would get an #XmlRootElement annotation, but for the most part, you have to think about the types.
I would recommend changing the schema to:
<xsd:element name="getAllOperationsSystemsRequest">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
That should generate a type and restrict the element to being an empty element.

Related

Problem importing XML file with hyphens in element names

I am pretty new to working with XML/XSD schemas etc. I am trying to use SQLXMLBulkLoad to load an XML file into SQL Server (the file to upload is greater than 2gb) and am having a problem as the source data has element names that contain hyphens, e.g. "first-name" or "start-date".
I have managed to get a few sample records imported into the database excluding those fields, but as soon as I add in any of the elements with a hyphen in the name, the import fails with an error message saying:
Schema: Invalid Value for 'column', Code: 80004005 Source: Schema Mapping
This only happens when there is a hyphen in an element name and I have no idea how to get around it. I have tried searching for the answer but can't find any reference to the issue I'm having.
The schema code is shown below:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="jobs" sql:is-constant="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="job" sql:relation="mytemptable" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" />
<xsd:element name="title" type="xsd:string" />
<xsd:element name="description" type="xsd:string" />
<xsd:element name="town" type="xsd:string" />
<xsd:element name="start-date" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I am unable to get the source data file amended to exclude the hyphens so I have to find a way to handle it in the import routine, but I am still not able to get it to work.

Importing time and heart rate data into SQL Server from TCX file via SSIS

I'm attempting to import a tcx file from Garmin connect into SQL Server with SSIS. Unfortunately, I'm at a complete loss as to how I would create an xsd in order to import the datapoints I want. The Garmin XSD is http://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd. And the parts I'm concerned about are only the elements here:
<xsd:complexType name="Trackpoint_t">
<xsd:sequence>
<xsd:element type="xsd:dateTime" name="Time"/>
<xsd:element type="Position_t" name="Position" minOccurs="0"/>
<xsd:element type="xsd:double" name="AltitudeMeters" minOccurs="0"/>
<xsd:element type="xsd:double" name="DistanceMeters" minOccurs="0"/>
<xsd:element type="HeartRateInBeatsPerMinute_t" name="HeartRateBpm" minOccurs="0"/>
<xsd:element type="CadenceValue_t" name="Cadence" minOccurs="0"/>
<xsd:element type="SensorState_t" name="SensorState" minOccurs="0"/>
<xsd:element type="Extensions_t" name="Extensions" minOccurs="0">
<xsd:annotation>
</xsd:element>
</xsd:sequence>
Any pointers on how to create the xsd would be helpful. Thanks
If you would like to import part of XML file without modifications, you do not have to design your own xsd. All you need to do is:
Take XSD file from Garmit (presuming it is valid and aligns with your data) and your XML file
In SSIS package, add dataflow task, XML source in it, select your XML file as source and Garmin XSD file as schema file
Alternatively, you can try this, XML Source can design (guess) XSD from XML provided. I would recommend this only as a starting point, since guessed XSD is very approximate and based only on the sample provided; it can misinterpret node and attribute types based on the sample.
XML Source usually produce multitude of outputs, so you have to check with data viewer which one contains data you need.
After playing with this prototype, you can transform package to your needs.
You did not provide your XML-file... But I found one sample of a TCX-file here and another one here. Reading this does not need a schema. I hope, that you can solve your problems, when you see the following example:
DECLARE #xml XML=
N'<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd">
<Activities>
<Activity Sport="Running">
<Id>2015-01-25T12:14:34Z</Id>
<Lap StartTime="2015-01-25T12:14:34Z">
<TotalTimeSeconds>507.0989990</TotalTimeSeconds>
<DistanceMeters>1000.0000000</DistanceMeters>
<MaximumSpeed>2.5790000</MaximumSpeed>
<Calories>95</Calories>
<AverageHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>155</Value>
</AverageHeartRateBpm>
<MaximumHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>173</Value>
</MaximumHeartRateBpm>
<Intensity>Resting</Intensity>
<TriggerMethod>Distance</TriggerMethod>
<Track>
<Trackpoint>
<Time>2015-01-25T12:14:34Z</Time>
<Position>
<LatitudeDegrees>50.8918607</LatitudeDegrees>
<LongitudeDegrees>16.7403161</LongitudeDegrees>
</Position>
<AltitudeMeters>233.1999969</AltitudeMeters>
<DistanceMeters>0.0000000</DistanceMeters>
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<Value>88</Value>
</HeartRateBpm>
<Extensions>
<TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
<Speed>0.0000000</Speed>
</TPX>
</Extensions>
</Trackpoint>
</Track>
<Track />
<Extensions>
<FatCalories xmlns="http://www.garmin.com/xmlschemas/FatCalories/v1">
<Value>0</Value>
</FatCalories>
<LX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
<AvgSpeed>1.9720000</AvgSpeed>
</LX>
</Extensions>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>';
WITH XMLNAMESPACES(DEFAULT 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2')
select Act.value(N'#Sport','nvarchar(max)') AS Activity_Sport
,Act.value(N'(Id)[1]','datetime') AS Activity_Id
,Lap.value(N'#StartTime','datetime') AS Lap_StartTime
,Lap.value(N'(TotalTimeSeconds)[1]','decimal(20,8)') AS Lap_TotalTimeSeconds
--more fields
,Lap.value(N'(Calories)[1]','int') AS Lap_TotalTimeSeconds
,Lap.value(N'(AverageHeartRateBpm/Value)[1]','int') AS Lap_AverageHeartRateBpm
,Lap.value(N'(MaximumHeartRateBpm/Value)[1]','int') AS Lap_MaximumHeartRateBpm
,Lap.value(N'(Intensity)[1]','nvarchar(max)') AS Lap_Intensity
--more fields
,TrP.value(N'(Time)[1]','datetime') AS Track_Trackpoint_Time
,TrP.value(N'(Position/LatitudeDegrees)[1]','decimal(20,8)') AS Track_Trackpoint_Position_LatitudeDegrees
--more fields
FROM #xml.nodes(N'/TrainingCenterDatabase/Activities/Activity') AS A(Act)
OUTER APPLY Act.nodes(N'Lap') AS B(Lap)
OUTER APPLY Lap.nodes(N'Track/Trackpoint') AS C(TrP)
The result
Activity_Sport Activity_Id Lap_StartTime Lap_TotalTimeSeconds ....
Running 2015-01-25 12:14:34.000 2015-01-25 12:14:34.000 507.09899900 ....

JAXB Example in camel

Can any one provide me simple example in camel with JAXB using spring XML? I searched on net but did not find anything.
I just want to create simple Student class with fields name, id and convert it into xml.
Not sure what in particular you're struggling with, but here are some snippets:
<util:map id="jaxbNamespacePrefixMap">
<!-- In my case, we dont want a prefix for our namespace; YMMV -->
<entry key="http://www.nmcourts.gov" value=""/>
</util:map>
<marshal>
<jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation.shared.odyssey"
partClass="generated.gov.nmcourts.ecitation.shared.odyssey.NMCitationEFileBatch" partNamespace="EFileBatch"
namespacePrefixRef="jaxbNamespacePrefixMap"/>
</marshal>
<unmarshal>
<jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation.shared.odyssey"
partClass="generated.gov.nmcourts.ecitation.shared.odyssey.NMCitationEFileBatch"
partNamespace="EFileBatch" namespacePrefixRef="jaxbNamespacePrefixMap" />
</unmarshal>
What do you need exactly?
http://camel.apache.org/jaxb shows perfectly well how to marshal to xml via spring.

How to XQuery an {http://schemas.xmlsoap.org/soap/encoding/}Array element

:
I'm trying to query a Array element with a XQuery Transformation in OSB OEPE, and put the queried elements in another Array element.
This is a example of what I need to query
<complexType name="QueryToneEvt">
<sequence>
...
<element name="allowedChannel" nillable="true" type="impl:ArrayOf_xsd_string"/>
...
</sequence>
</complexType>
The ArrayOf_xsd_string element is this:
<complexType name="ArrayOf_xsd_string">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</complexType>
Then, for a query over the allowedChannel element, I did this operation
for $i in $queryToneEvt/allowedChannel/?
return
¿?
From this, i have a few questions?
The Xpath route is correct for that element?
How I determine the type of the root Array member and the target Array member where I must put the queried Array member? (in the ¿? symbols) NOTE: The target Array have the same structure as the root, because it has the same type ArrayOf_xsd_string.
Likely not, because usually you need to provide a namespace. Or just use "any namespace":
for $i in $queryToneEvt/*:allowedChannel
I do not understand your question. If the source and the target of the same type, just copy the root element as-is, including the attributes.
Please provide the examples of source and target structures, it is easier to see once.

Avoid creation of JDK classes in Apache CXF wsdl2java task

I have a WSDL file with defines a java.io.Exception:
<xsd:schema xmlns:tns="http://io.java" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://io.java">
<xsd:complexType name="IOException">
<xsd:sequence/>
</xsd:complexType>
</xsd:schema>
When generating Java classes using the Apache CXf wsdl2java task, it generates a class like this (which causes compile errors, as it is not a valid java.io.IoException):
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "IOException")
public class IOException {
}
Is there a way to prevent CXF from generating JDK classes?
Thx! :)
You definitely need to change your namespace.
targetNamespace="http://io.java"
xmlns:tns="http://io.java"
If you have such namespace and the complex type named IOException of course there will a problem. And why in the world you named the namespace like this http://io.java?
Change the namespace for e.g.:
targetNamespace="http://yourcompany.com/yourservice"
xmlns:tns="http://yourcompany.com/yourservice"
You you'll be good.

Resources