Element does not have a match in class - simple-framework

I am working with Simple XML framework, and just renamed some XML layouts, which now don't seem to work any more.
This is my XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<orderListReply id="R000000000006">
<order orderid="12" type="outbound" state="available">
<todo>2</todo>
<done>0</done>
<lines>1</lines>
<erporderid>0</erporderid>
</order>
</orderListReply>
And this is my code class definition:
#Root(name="orderListReply")
public class OrderListReplyTelegram extends Telegram {
#ElementList(name="order", inline=true, required=false)
private List<OrderListItem> orders;
...
This is the error I get:
org.simpleframework.xml.core.ElementException: Element 'order' does not have a match in class nl.minerall.sapphire.pocket.telegrams.OrderListReplyTelegram at line 1

Unfortunately, debugging Simple XML Framework isn't easy, but some trial and error helped me.
My OrderListItem class had this header:
#Element(name="order")
public class OrderListItem {
when changed to this:
#Root(name="order")
public class OrderListItem {
it worked. Strange thing is, in other code, the #Element annotation seemed to work (this code comes from another, working, tree).

Related

How to generate header using SoapJaxbDataFormat

First I have generated pojo class using jsonschema2pojo plugin using WSDL file.
My WSDL file contains Header and Body.
Body Root Pojo looks like this:
public class SubmitCustomerOrderRequest {
#XmlElement(required = true)
protected List<Order> order;
}
Header looks like this:
public class MessageHeader {
.....
}
Now in a process class of camel i am putting SubmitCustomerOrderRequest (Here this pojo only consider body not header) into body like this:
submitCustomerOrderRequest.setOrder(orderList);
exchange.getIn().setBody(submitCustomerOrderRequest);
Now in the route i am marshalling using this concept
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("org.com.model",
new ServiceInterfaceStrategy(order.class, true));
And marshalling into xml like this:
.marshal(soapDF)
Now here the problem here is, its generating xml but without header, how to include header also in the process class so that while converting into xml, its generates header also with body
Its generating like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Envelope xmlns:ns2="org.com" xmlns:ns3="org.com.something">
<ns2:Body>
<ns3:submitCustomerOrderV3Request>
</ns3:submitCustomerOrderV3Request>
</ns2:Body>
</ns2:Envelope>
whereas i need like this with header:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=org.com>
<SOAP-ENV:Header>
<messageHeader xmlns=org.om>
</messageHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:submitCustomerOrderV3Request xmlns:ns2=org.com>
</ns2:submitCustomerOrderV3Request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Any help would be appreciable.

No consumers available on endpoint: Endpoint[direct://LookUpRoute]

I'm new to Apache Camel. I'm trying to send an exchange from a java method to a route but it gives me "Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint" error. I want to understand what exactly this error is and when do we get this?
#EndpointInject(uri = "direct:reportRoute")
private ProducerTemplate templatereportRoute;
public void saveDataFromExchange(Map<String, Object> DataMap){
List<Map<String, Object>> paramList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> rows = templatereportRoute.requestBody("direct:reportReport", DataMap, List.class);
<from uri="direct:reportRoute"/>
<log message=" - ${body}" loggingLevel="INFO"/>
<setProperty propertyName="DataMap">
<simple>${body}</simple>
</setProperty>
The error you encounter means that you are sending to a direct endpoint that does not exist in the Camel Context.
Since you posted an XML fragment that defines the route in question there are two possible problems (as already commented by #claus-ibsen):
The XML you posted is not in use. You are starting a Camel Context but it does not use your XML code. Are you using Spring? Then you can define your Camel routes in Spring XML.
Your setup is fine but your Java code sends the message too early, i.e. before the direct endpoint is up and running. You can put this code in a Test class and run it after the Camel context is started and ready.
Try put in public class from routerBuilder implemention the anotation #Component from Spring context
Ex:
#Component //<<<<---- This
public class RouterClass extends RouteBuilder {
#Override
public void configure() throws Exception {
}
}//class closure

How to use internationalization in JSF that retrieve the data from DB

I want to use the standard internationalization from JSF (in property files )and the possibility to switch to database. Is it possible to replace JSF internationalization with own implementation that retrieve the data from DB, so I can configure it ? Or is in this case another aproach better ?
I've found the following example: http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/ . In this example the own resource bundle class is defined. To use it only the reference in xml to implementation class is replaced.
As BalusC pointed, you need to create a ResourceBundle and register it to the app or individually per page.
Simple example:
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<h:body>
<h:outputText value="[helloworld]: #{msgs.helloworld}" />
</h:body>
</html>
faces-config.xml
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<resource-bundle>
<base-name>com.myproject.CustomResourceBundle</base-name>
<var>msgs</var>
</resource-bundle>
</application>
</faces-config>
CustomResourceBundle.java
package com.myproject;
import java.util.ListResourceBundle;
public class CustomResourceBundle extends ListResourceBundle {
#Override
protected Object[][] getContents() {
return getMapOfWordsFromDatabase();
}
private Object[][] getMapOfWordsFromDatabase() {
// TODO get key and words relation from database!
return map;
}
}
Theory:
http://docs.oracle.com/javaee/5/tutorial/doc/bnaxv.html
http://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.html

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.

Error in custom repository interface

I'm trying to set up my first Java application using Spring Data for MongoDB in a multi-module Maven 3 project. Here are the relevant versions:
Java 7
mongodb-win32-x86_64-2.2.0
Spring Data 1.1.1.RELEASE
Spring 3.2.0.RELEASE
I'm getting the following runtime error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'actorFacade': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private es.mi.casetools.praetor.persistence.springdata.repositories.ActorRepository es.mi.casetools.praetor.facade.impl.DefaultActorFacade.actorRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'actorRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property insert found for type void
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:106)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:57)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 30 more
Searching in google I found people with the same issue and it seems to be related with custom repositories.
Here is the entity I want to store as a mongo document.
public class Actor {
public enum ActorStereotype {
SYSTEM,
PERSON
}
private String id;
private String code; // unique
private ActorStereotype stereotype;
private String title; // Short title for the actor
private String description;
private String projectId; // project this actor belongs to
// getters & setters
The standard repository interface.
public interface ActorRepository extends MongoRepository<Actor, String>, ActorRepositoryCustom {
}
The custom interface (where I think the error lives).
#NoRepositoryBean
public interface ActorRepositoryCustom {
void updateSingleActor(Actor actor);
void insertActor(Actor actor);
}
The custom interface implementation.
public class ActorRepositoryCustomImpl implements ActorRepositoryCustom {
#Autowired
private MongoTemplate mongoTemplate;
#Override
public void updateSingleActor(Actor actor) {
if(actor.getId() != null)
throw new MissingIdException();
// TODO change to Spring Converter
DBObject dbo = (DBObject)mongoTemplate.getConverter().convertToMongoType(actor);
mongoTemplate.updateFirst(query(where("_id").is(actor.getId())),
Update.fromDBObject(dbo, new String[]{}),
Actor.class);
}
#Override
public void insertActor(Actor actor) {
if(actor.getId() != null)
throw new IdProvidedException();
mongoTemplate.save(actor);
}
}
And finally, the application context.
<context:annotation-config/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/test.properties</value>
</list>
</property>
</bean>
<!-- mongodb configuration -->
<mongo:repositories base-package="es.mi.casetools.praetor.persistence.springdata.repositories"
mongo-template-ref="mongoTemplate" repository-impl-postfix="Impl">
<repository:exclude-filter type="annotation" expression="org.springframework.data.repository.NoRepositoryBean"/>
</mongo:repositories>
<mongo:mongo id="mongotest" host="${mongo.host}" port="${mongo.port}" write-concern="SAFE">
</mongo:mongo>
<mongo:db-factory dbname="${mongo.dbname}" mongo-ref="mongotest"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<bean id="actorFacade" class="es.mi.casetools.praetor.facade.impl.DefaultActorFacade">
</bean>
</beans>
I also have a little Spring test that fails loading the above application context giving the exception I listed near the top.
I tried adding the following but I get the same exception.
<bean id="actorRepositoryCustomImpl" class="es.mi.casetools.praetor.persistence.springdata.repositories.ActorRepositoryCustomImpl"></bean>
Has someone got a clue of what the error may be?
Miguel's comment solved the problem. I had given the wrong name to the implementing class. I've seen similar questions around so I'll try to clarify the solution in the hope that it helps someone else.
I have the following interface definition
public interface ActorRepository extends MongoRepository<Actor, String>, ActorRepositoryCustom
The custom interface definition looks like this:
public interface ActorRepositoryCustom
So my error was naming the implementation of ActorRepositoryCustom with ActorRepositoryCustomImpl, expecting Springdata would pick up the implementation as its postfix is the default one Impl. The thing is, Springdata looks for ActorRepositoryImpl by default, even though what you are implementing is ActorRepositoryCustom. The solution is using the optional attribute repository-impl-postfix and set it to CustomImpl.

Resources