web.xml property override by Weblogic deployment plan - deployment

Trying to override my web.xml file's
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
I tried using the following deployment plan which seems like it should work ... but it does not seem to. I need to either remove the login-config or change it to client-cert.
<variable-definition>
<variable>
<name>authMethod</name>
<value>CLIENT-CERT</value>
</variable>
</variable-definition>
......
<module-descriptor external="false">
<root-element>web-app</root-element>
<uri>WEB-INF/web.xml</uri>
<variable-assignment>
<name>authMethod</name>
<xpath>/web-app/login-config/auth-method</xpath>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>

I ran into a similar issue and found that by default Weblogic's Plan Generator generates plan.xml with the following:
<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://xmlns.oracle.com/weblogic/deployment-plan"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan
http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"
global-variables="false">
Changing the global-variables="false" to global-variables="true" fixed the problem for me.

try modifying your xpath to the following:
<xpath>/web-app/login-config/auth-method/[param-name="authMethod"]/param-value</xpath>

Related

WildFly 9 Failed to parse service xml

jboss-service.xml:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean name="com.xxx.yyy:service=SomeClass"
code="com.xxx.yyy.SomeClassBean" xmbean-dd="META-INF/config-mbeans.xml" />
</server>
I have jboss-service.xml above and I'm getting this error:
Caused by: java.lang.IllegalStateException: Current state START_ELEMENT is not among the statesCHARACTERS, COMMENT, CDATA, SPACE, ENTITY_REFERENCE, DTD valid for getText()
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.getText(Unknown Source)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.getText(XMLExtendedStreamReaderImpl.java:275)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.unexpectedContent(JBossServiceXmlDescriptorParser.java:638)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.parseMBean(JBossServiceXmlDescriptorParser.java:221)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.readElement(JBossServiceXmlDescriptorParser.java:192)
at org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser.readElement(JBossServiceXmlDescriptorParser.java:48)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110)
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69)
at org.jboss.as.service.ServiceDeploymentParsingProcessor.deploy(ServiceDeploymentParsingProcessor.java:96)
... 6 more
Any idea how to fix this? Tried other suggestions, but nothing seems to work.
According to the section 9.6.2 of the JBossAS docs, you need to define your mbean like this:
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean code="..." name="...">
</mbean>
</server>
EDIT
After looking at the source code of JBossServiceXmlDescriptorParser.java:221, one understands that the element xmbean-dd is no longer expected on Wildfly 9. Only NAMEand CODE are expected.
Remove that element from your mbean tag and it will work.

#RepositoryRestResource doesnt export anything

I am trying to get RepositoryRestResource working but somehow it doesnt export anything.
Take this class:
#RepositoryRestResource(collectionResourceRel = "store", path = "store")
public interface StoreRepository extends PagingAndSortingRepository<Store, Long> {
}
I expected to have a rest endpoint at http://localhost:8080/mycontext/stores or at http://localhost:8080/mycontext/store/1 or even get a service overview at http://localhost:8080/mycontext like described in the docs.
I can use this repository as "normal" from a controller with #Resource annotation and use it via the controller but i somehow dont get it to expose the REST endpoints.
Is there anything i need to do other than that? I added <jpa:repositories base-package="de.netstorsys.repositories" /> to the spring context because someone had it into his example code but with no difference.
Since the registration of the web endpoints is somehow spring magic, i dont know how to debug this further. Most of the Tutorials around that topic are for Spring Boot but i have a xml based standard spring application.
Thanks for any input.
I guess you might be missing file
src/main/resources/META-INF/spring-data-rest/repositories-export.xml
where we specify:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<jpa:repositories base-package="<packageWhereRepoClassExists>"/>
</beans>
Please refer below sample spring-data-rest project, that is not based on spring-boot. It uses xml configuration:
https://github.com/charybr/spring-data-rest-acl
I have one working example and blog that uses RepositoryRestResource and EntityLinks. Please check if this helps you. On the blog you will find GitHub link too.
http://sv-technical.blogspot.com/2015/11/spring-boot-and-repositoryrestresource.html

Override NativeQuery at Runtime

I am using OpenJPA with SqlServer in my project and I have a need to use native SqlServer syntax for a particular query. For this, I have been using the NativeQuery annotation with great results.
However, the issue comes when I need to run a unit test with Derby as my database. As it turns out, Derby does not support the exact syntax of my NativeQuery. My thought is to swap out the NativeQuery with a "Derbified" version to run the test. However, I have not been able to find a way to do this.
Is there any way to override or redefine a NativeQuery for an entity at runtime?
I would use persistence.xml to define two peristence-unit elements (one for SqlServer and another for Derby) with dedicated orm.xml containing named-native-query.
persistence.xml
<persistence version="2.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_2_0.xsd">
<persistence-unit name="sqlserver-pu">
<mapping-file>META-INF/orm-sqlserver.xml</mapping-file>
...
</persistence-unit>
<persistence-unit name="derby-pu">
<mapping-file>META-INF/orm-derby.xml</mapping-file>
...
</persistence-unit>
</persistence>
orm-sqlserver.xml
<entity-mappings version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<named-native-query name="findFirst" result-class="com.tyler.example.order">
<query>SELECT TOP 1 * FROM Order</query>
</named-native-query>
</entity-mappings>
orm-derby.xml
<entity-mappings version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<named-native-query name="findFirst" result-class="com.tyler.example.order">
<query>SELECT * FROM Order FETCH FIRST ROW ONLY</query>
</named-native-query>
</entity-mappings>
With such an approach you have improved interoperability of your code as entities (portable across databases) are decoupled from queries (vendor specific). All you need is to select a proper persistence unit at runtime and execute a given query (they must have the same name).
Another approach that comes into my mind is to define a named native query twice for each entity using #NamedNativeQuery annotation with different name and query attributes, but at runtime you would then probably need some "ifology" to determine a proper one.

How to add the description of job in spring batch admin user interface?

Is there any way to add the description of job at the user interface of spring batch admin?
Although, I tried to added the description of the job, spring batch admin cannot support it.
I would like to know that whether spring batch admin does not support it or not.
I know i'm late to the party but I figured it out and it works flawlessly for me. All you have to do is :
Add a messages.properties file in your classpath (under
src/main/resources).
Add yourJobName.description=Your description goes here in that file.
Override manager-context.xml for SBA by creating a file on path src/main/resources/META-INF/spring/batch/servlet/override/manager-context.xml
The content of the above created file should be :
`
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Override messageSource bean in order to provide custom text content -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
</beans>
`
That's it. Your custom description shows up in SBA. Hope this helps someone who's looking for it.
There isn't the ability out of the box to display the job's description. That is only contained in the XML and the data seen in the UI comes from the JobRepository. You'd have to extend the UI to add that functionality.

How do specify clientId and subscriptionName for EJB3 message driven bean durable subscription without hard coding the values?

I have a server running JBoss4.2.1 containing a JMS Topic. I also have multiple terminals, each running their own JBoss with an EJB3 message driven bean that need to subscribe to the topic using durable subscriptions. Since each subscription needs to specify a unique clientId and subscriptionName I can't hard code the values in the ActivationConfigProperty annotations and I can't specify the values in the deployment descriptor files.
So, the question is how do I specify these values? Do I do it in JBoss configuration files?
Please provide a complete sample configuration if possible.
Thanks.
This can be done by using a combination of entries in the ejb-jar.xml configuration file and supplying the values as parameters to the JBoss startup command.
META-INF/ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
version="3.0"
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/ejb-jar_3_0.xsd">
<enterprise-beans>
<message-driven>
<ejb-name>MyMsgDrivenBeanMDB</ejb-name>
<ejb-class>com.mdb.MyMsgDrivenBeanMDB</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>clientId</activation-config-property-name>
<activation-config-property-value>${client.id}</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>subscriptionName</activation-config-property-name>
<activation-config-property-value>${subscription.name}</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>reconnectInterval</activation-config-property-name>
<activation-config-property-value>60</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
By specifying the values using the ${variable} notation in the ejb-jar.xml file they can then be picked up from the JBoss start command as server options.
-Dclient.id=client-01 -Dsubscription.name=subscription-01