Editing WSDL so that #XmlRootElement is created in generated class - soap

Given this WSDL file:
<?xml version="1.0" encoding="UTF-8”?>
<wsdl: definitions targetNamespace="http://mycompany.net/request/“
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://mycompany.net/request/“
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsd="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<xsd: complexType name=“MyReq”>
<xsd: complexContent>
<xsd: extension base="jisi: ServiceRequest">
<xsd: sequence>
<xsd: element name=“…” type="tns: …” minOccurs="O" nillable="true" />
// more elements defined
</xsd: sequence>
</xsd: extension>
</xsd: complexContent>
</xsd: complexType>
<xsd: element name=“MyRq" type="tns: MyReg" />
The following class is generated:
#XmLAccessorType (XmLAccessType.FIELD)
#XmLType (name= “MyReq”, namespace=“"http://mycompany.net/request/“ propOrder={
…
})
public class MyReq extends ServiceRequest {
…
}
An ObjectFactory class is also generated which contains a method createMyRq.
This returns an instance of the MyReq class wrapped in a JAXBElement.
Our existing application passes the JAXBElement wrapper to a WebServiceTemplate.
I am trying to migrate to WebFlux, and replace WebServiceTemplate with the reactive WebClient.
I have not got this to work using JAXBElement, and indeed the examples I have seen which use SOAP with WebClient wrap the request object in a Soap Envelope, not a JAXBElement.
For example:
https://github.com/danielyinanc/spring-guides/blob/master/soap-service/src/main/java/io/spring/guides/gs_producing_web_service/GetCountryRequest.java,
When I wrap the generated MyReq object in a SOAP envelope, an error is returned that the request class is not annotated with #XmlRootElement.
I tried to fix this by editing the WSDL and wrapping the complexType in an element, as follows:
<xsd: element name=“MyReq”>
<xsd: complexType>
<xsd: complexContent>
<xsd: extension base="jisi: ServiceRequest">
<xsd: sequence>
...
<xsd: sequence>
</xsd: extension>
<xsd: complexContent>
<xsd: complexType>
</xsd: element>
but the complier complains on this line
<xsd: element name=“MyRq" type="tns:MyReg" />
that it cannot resolve tns:MyReg
I cannot just delete that line, because MyRg is used in other parts of the WSDL, as follows:
<wsdl: message name=“myReq”>
<wsdl: part name="request" element="tns:MyRg" />
</wsdl:messages
Is there a way to change the WSDL so that the generated MyReq class is annotated with #XmlRootElement?
Thanks

Related

XMLSerialization issue

I need to generate the XML file which will be consumed by the external application. And I have observed that it depends on ordering of the namespace defined in the XML. Since the xml is consumed by external application, I don't have the exact error details.
Below is the sample code
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.32990")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://mycompany.com/2010/package")]
[System.Xml.Serialization.XmlRootAttribute("Catalog", Namespace="http://mycompany.com/2010/package", IsNullable=false)]
public partial class PackageT : System.ComponentModel.INotifyPropertyChanged {
}
Extension class written in order to include custom schemalocation
public partial class PackageT
{
[XmlAttributeAttribute("schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string xsiSchemaLocation = "http://mycompany.com/2010/catalog.xsd";
}
Code to serialize the object to XML
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("xml", "http://www.w3.org/XML/1998/namespace");
namespaces.Add("test", "http://mycompany.com/2010/package");
XmlSerializer serializer = new XmlSerializer(typeof(PackageT));
TextWriter writer = new StreamWriter("package.xml");
serializer.Serialize(writer, catalog, namespaces);
writer.Flush();
writer.Close();
Generated XML ( not working)
<?xml version="1.0" encoding="utf-8"?>
<test:Catalog
xmlns:xml="http://www.w3.org/XML/1998/namespace"
d1p1:schemaLocation="http://mycompany.com/2010/catalog.xsd"
xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:test="http://mycompany.com/2010/package">
....
</test:Catalog>
EXpected XML which is working
<?xml version="1.0" encoding="utf-8"?>
<test:Catalog d1p1:schemaLocation="http://mycompany.com/2010/catalog.xsd"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:test="http://mycompany.com/2010/package">
....
</test:Catalog>
Please help me!!
If you specify the element name and namespace for the root you can generate the XML you're looking for. Modify PackageT as below:
[XmlRoot(ElementName = "Catalog", Namespace = "http://mycompany.com/2010/package") ]
public partial class PackageT
{
[XmlAttribute("schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string xsiSchemaLocation = "http://mycompany.com/2010/catalog.xsd";
}
and the output becomes:
<?xml version="1.0" encoding="utf-8"?>
<test:Catalog xmlns:xml="http://www.w3.org/XML/1998/namespace"
d1p1:schemaLocation="http://mycompany.com/2010/catalog.xsd"
xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://mycompany.com/2010/package" />

"Type class is not known to the MapperRegistry" in MyBatis

My Problem
I'm getting the error Type class myPackage.MyClass is not known to the MapperRegistry.
I successfully acquired a session, and upon debugging I can see that it otherwise appears to be configured correctly so the interface association seems to be working; therefor I'm confident this error is distinct from the stack-overflow-suggested Type interface is not known... question.
I'm new to myBatis but from the documentation I understood that the following was all that was required to get resultType auto-mapping to work.
Update: This also happens when mapping the mapper resources by xml file instead of by class.
My Mapper
public interface MyClassMapper{
MyClass getMyClass(Integer id);
}
My Model
public class MyClass{
private String itemValue;
public String getItemValue() {
return itemValue;
}
public void setItemValue(String itemValue) {
this.itemValue = itemValue;
}
}
My Sql Map
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="myPackage.orm.sqlMap.MyClassMapper" >
<select id="getMyClass" resultType="myPackage.MyClass" >
select itemValue
from SOME_TABLE
WHERE id = #{id}
</select>
</mapper>
My mybatis-config.xml
...
<mappers>
<mapper class="myPackage.MyClass" />
</mappers>
...
Fixed:
public MyClass getMyClassValue(Integer id) throws Exception{
SqlSession session = MyBatisSessionFactory.openSession();
MyClassMapper mapper = (MyClassMapper) session.getMapper(MyClass.class);
return mapper.getMyClass(id);
}
Here is the code I was using to execute the query, discovered that I was looking up the mapper in the mapper registry by the model class name, rather than the mapper interface name. Works just fine now.
In your mapper.xml file mapper's namespace should be the path to the mapper interface.
for example:
<mapper namespace="com.mapper.LineMapper">
<select id="selectLine" resultType="com.jiaotong114.jiaotong.beans.Line">
select * from bus_line where id = #{id}
</select>
</mapper>
your mapper interface should be in com.mapper package and the name of it is LineMapper.
hope help.
I solved this issue by adding the mapper XML to the mybatis xml configuration file
<mappers>
<mapper resource="com/java/Mapper.xml"/>
</mappers>

f:viewAction does not invoke action method

I can't get an action method with the f:viewAction tag to work.
Here's the jsf page:
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:repeat var="genreType" value="#{navigation.genreTypeList}">
<f:metadata>
<f:viewParam name="nameEn" value="#{genreType.name_en}" required="true" />
<f:viewAction action="#{search.searchByGenreType}" />
</f:metadata>
<h:link value="#{genreType.name_de}" outcome="index" includeViewParams="true" /><br />
</ui:repeat>
</ui:composition>
It produces links like this:
[...]/index.jsf;jsessionid=635562E66C7F2FA54504B53D5DAA114C?nameEn=fiction
And here's the bean:
#ManagedBean
#RequestScoped
public class Search implements Serializable {
private static final long serialVersionUID = -5193732222381183093L;
private String nameEn;
public String getNameEn() {
return this.nameEn;
}
public void setNameEn(String nameEn) {
this.nameEn = nameEn;
}
// action methods
public String searchByGenreType() {
System.out.println("searchByGenreType");
return "index";
}
}
I'm using JSF 2.2.5 with Tomcat 7.0.42, IDE is Eclipse Kepler (4.3.1).
I've tried different variations (#PostConstruct in bean, explicit navigation in faces-config.xml, old and new namespaces).
There should be no problem with namespaces since this is fixed since JSF 2.2.5.
This code isn't making any sense. You seem to be confusing <f:viewParam> with <f:param>. You need <f:param> to add HTTP request parameters to links. The <f:viewParam> is to be used to set incoming HTTP request parameters as bean properties.
Given the concrete functional requirement of having a list of links with parameters which in turn should on the target page set the parameter as a bean property and invoke a bean action, here's how you should be implementing it:
The source page with the list of links:
<ui:repeat var="genreType" value="#{navigation.genreTypeList}">
<h:link value="#{genreType.name_de}" outcome="index">
<f:param name="nameEn" value="#{genreType.name_en}" />
</h:link>
<br />
</ui:repeat>
In the target page, apparently index.xhtml, put this somewhere in top, right before <h:head>:
<f:metadata>
<f:viewParam name="nameEn" value="#{search.nameEn}" required="true" />
<f:viewAction action="#{search.searchByGenreType}" />
</f:metadata>
Inside the searchByGenreType() method you can just access that nameEn property directly.
See also:
What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
When using <ui:composition> templating, where should I declare the <f:metadata>?

How to enable a command only when the selected element has certain property?

I'm building am eclipse plugin and I have a tree representation where I display the structure of an element of type A(see below).
Class A{
List<B> children;
}
Abstract Class B{
...
}
Class C extend B{
...
}
Class D extend B{
...
}
I have a command which can start only when the selected element in the three is an instance of A.
This is the expression I'm using.
<extension point="org.eclipse.core.expressions.definitions">
<definition id="SelectionOfA">
<with variable="selection">
<and>
<count value="1"></count>
<iterate ifEmpty="false" operator="or">
<instanceof value="A"></instanceof>
</iterate>
</and>
</with>
</definition>
</extension>
Now I would like to refine this condition. I would like to enable the command only when an instance of A is selected and the list children contains at least an element which is instance of C.
I tried by keeping this expression and defining a new one. Then I will enable the command only if both the expressions are true. I started from the expression reported above and I tried to replace the tag instanceof with the tags with, iterate and adapt without a good result.
How can I do it?
I would implement a property tester to check if the condition is met.
Something like this should do the work:
public class YourConditionTester extends PropertyTester {
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
if (property.equals("isA_and_hasC")) {
return (true if your condition is met, otherwise false)
}
return false;
}
}
Then, instead of instanceof use test with property set (e.g.) to "isA_and_hasC".
Look here for more info about property testers.

liferay-6.1 - Implement own service

Hey I have create my own service.xml with student. Now o want to add my own searchByName method for student. can you please explain me what to write in StudentLocalServiceImpl.
public class StudentLocalServiceImpl extends StudentLocalServiceBaseImpl {
/*
* NOTE FOR DEVELOPERS:
*
*/
public List<Student> getAll() throws SystemException {
return studentPersistence.findAll();
}
public Student getStudentByName(String name) {
return studentPersistence.
}
// I have created one method getAll. I need help for the another one.
Thanks in Advance.
You would first declare this as a "finder" element in the service.xml within the entity you defined.
e.g.
<finder name="Name" return-type="Student">
<finder-column name="name" />
</finder>
The return-type could also be Collection if wanting a List<Student> as the return type, if name is not unique.
<finder name="Name" return-type="Collection">
<finder-column name="name" />
</finder>
You can also state a comparison operator for the column:
<finder name="NotName" return-type="Collection">
<finder-column name="name" comparator="!=" />
</finder>
A finder can actually declare a unique index as well to be generated on this relation (will be applied to the DB table) by specifying the unique="true" attribute on the finder:
<finder name="Name" return-type="Student" unique="true">
<finder-column name="name" />
</finder>
With this definition and after re-runing ant build-service the studentPersistence will contain new methods using the name of the finder found in the xml element appended with a prefix: countBy, findBy, fetchBy, removeBy, etc.
Finally, your serice method would only need to contain the following (based on the above):
public Student getStudentByName(String name) throws SystemException {
return studentPersistence.findByName(name);
}
HTH