Spring SOAP: Defining a package structure which does not use the URI namespace - soap

Given the following XSD used by Spring SOAP web services:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ccc.jjj.nnn/verify/"
targetNamespace="http://ccc.jjj.nnn/verify/" elementFormDefault="qualified">
...
</xs:schema>
the request and response classes used by the web services will reside in the following package structure:
- nnn
- jjj
- ccc
- verify
Is there a way to override this and specify a different package hierarchy?
It is not possible to change the XSD namespace itself, because this is already used in production, and changing it would impact the clients.
This was possible with WebSphere. In that technology, there was a mapping file which could include the following:
<package-mapping>
<package-type>com.jjj.ws</package-type>
<namespaceURI>http://ccc.jjj.nnn/verify<namespaceURI>
</package-mapping>
The classes exposed by the SOAP service would then reside in the following package structure:
- com
- jjj
- ws
Thanks

Related

mathml xsd schema to java classes using xjc MiOrMoOrMn <jaxb:property> error

Jaxb / xjc won't create java classes from xsd schema file (Eclipse and command line)
Using jre1.8.0_191 and JAXB both Eclipse and xjc command line (and switches) give errors when trying to convert imsqti_v2p1.xsd (learning object quizzes) to POJOs (plain old java objects). Most errors said "Property X is already defined. Use to resolve this conflict" and I was able to annotate imsqti_v2p1.xsd until (in both Eclipse and command line xjc) only one error remains:
parsing a schema...
[ERROR] Property "MiOrMoOrMn" is already defined. Use to
resolve this conflict. line 132 of
http://www.w3.org/Math/XMLSchema/mathml2/presentation/scripts.xsd
Now, imsqti_v2p1.xsd has many xmlns' - the one responsible for the error is
<xs:import namespace="http://www.w3.org/1998/Math/MathML"
schemaLocation="http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd"/>
This xsd is SHORT and has many local references, one of which causes the error
I did find this scripts.xsd - the compiler complained about line 132 and Property "MiOrMoOrMn" but scripts.xsd ends at line 130! Plus, when I load scripts.xsd into Eclipse editor it has a dozen errors - if they are caused by missing "neighbor" xsd's referenced by mathml2.xsd I'd probably have to find and download and run locally 27 local xsd's! So I'd hoped I could fix scripts.xsd and refer to it locally in a xmlns in the mathml2.xsd header, but now I'm not sure how to resolve this. Also, If you know of a better way to create these POJO's I'd be hearing about it - someone must know about this mathml xsd issue?!?
==================== imsqti_v2p1.xsd =============================
<xs:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.1"
xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:apip="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
targetNamespace="http://www.imsglobal.org/xsd/imsqti_v2p1" version="IMS
QTI 2.1" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.imsglobal.org/xsd/w3/2001/xml.xsd"/>
<xs:import namespace="http://www.w3.org/2001/XInclude"
schemaLocation="http://www.imsglobal.org/xsd/w3/2001/XInclude.xsd"/>
<xs:import namespace="http://www.w3.org/1998/Math/MathML"
schemaLocation="http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd"/>
<xs:import
namespace="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0"
schemaLocation="http://www.imsglobal.org/profile/apip/apipv1p0/
apipv1p0_qtiextv2p1_v1p0.xsd"/>
==================== mathml2.xsd ==================
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1998/Math/MathML"
targetNamespace="http://www.w3.org/1998/Math/MathML"
elementFormDefault="qualified">
<xs:include schemaLocation="common/math.xsd"/>
<xs:include schemaLocation="common/common-attribs.xsd"/>
<!-- Presentation -->
<xs:include schemaLocation="presentation/common-types.xsd"/>
<xs:include schemaLocation="presentation/common-attribs.xsd"/>
<xs:include schemaLocation="presentation/characters.xsd"/>
<xs:include schemaLocation="presentation/tokens.xsd"/>
<xs:include schemaLocation="presentation/scripts.xsd"/>
============= scripts.xsd ========================
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1998/Math/MathML"
targetNamespace="http://www.w3.org/1998/Math/MathML"
elementFormDefault="qualified">
================ compiler error message ==================
parsing a schema...
[ERROR] Property "MiOrMoOrMn" is already defined. Use <jaxb:property>
to resolve this conflict. line 132 of
http://www.w3.org/Math/XMLSchema/mathml2/presentation/scripts.xsd
[ERROR] The following location is relevant to the above error
line 138 of
http://www.w3.org/Math/XMLSchema/mathml2/presentation/scripts.xsd
Failed to parse a schema.
XMLSPY let's you download and try the full edition - I loaded up my .xsd and the product was able to chew through all the reference .xsd's and produce (many, many) java class files successfully ... so FYI ... In the meantime, I have been able to get JAXB to work using much smaller input .xds's. I got these (different part of project) by producing output XML from a tool, then using one of the online XML to XSD web sites to produce the .xsd which JAXB was able to process. I guess this is the only way 'round the MiOrMoOrMn problem.

Apache camel endpoint handling

I have an applicationContext xml file that imports multiple resources (camel context files).
<import resource="AddRequest.xml" >
<import resource="AdviseRequest.xml" >
I am caching the definitions of this xml before hand using new FileSystemXmlApplicationContext().
Say AddRequest.xml uses some method to connect to some host, while AdviseRequest.xml uses CXF endpoint to SOAP.
When I try to load the applicationContext xml, it tries to caches both files first before actually starting camelContext. At this stage, it is trying to check the CXF endpoint availabilty. Is there anyway to handle this, if the soap wsdl is actually down ?
The reason is, if there's some connection issues in the second xml, my first xml also fails, as it tries to cache both at a time.
Note: I cannot use two separate applicationContext files
I have used below code in the camel route.
<onException id="Request_onException1">
<exception>java.net.ConnectException</exception>
<handled>
<constant>true</constant>
</handled>
</onException>

Removing namespace from Soap Response Camel CXF

Below is my sample Soap Response for a service hosted in camel cxf
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:XpgIntegratedPaymentResponse xmlns:ns2="http://test:9090/wsx/services/WemXpgPaymentService"/>
</soap:Body>
</soap:Envelope>
Now I don't want to generate "ns2" namespace prefix in response.
Can anyone help?
if you want to drop the namespace of that element so that it is serialized as no-namespaced XpgIntegratedPaymentResponse, the common approach is to use CXF's transform feature.
see more info here:
http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-Changinginputandoutputelementnamesandnamespaces
in your particular case, you will need the following entry
<entry key="{http://test:9090/wsx/services/WemXpgPaymentService"}XpgIntegratedPaymentResponse"
value="XpgIntegratedPaymentResponse"/>
Are you using Camel 2.11+ ? You can control the namespaces mapping:
Taken from:
http://camel.apache.org/jaxb.html
When marshalling using JAXB or SOAP then the JAXB implementation will automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To control this mapping, Camel allows you to refer to a map which contains the desired mapping.
Notice this requires having JAXB-RI 2.1 or better (from SUN) on the classpath, as the mapping functionality is dependent on the implementation of JAXB, whether its supported.
For example in Spring XML we can define a Map with the mapping. In the mapping file below, we map SOAP to use soap as prefix. While our custom namespace "http://www.mycompany.com/foo/2" is not using any prefix.
<util:map id="myMap">
<entry key="http://www.w3.org/2003/05/soap-envelope" value="soap"/>
<!-- we dont want any prefix for our namespace -->
<entry key="http://www.mycompany.com/foo/2" value=""/>
</util:map>
To use this in JAXB or SOAP you refer to this map, using the namespacePrefixRef attribute as shown below. Then Camel will lookup in the Registry a java.util.Map with the id "myMap", which was what we defined above.
<marshal>
<soapjaxb version="1.2" contextPath="com.mycompany.foo" namespacePrefixRef="myMap"/>
</marshal>

#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

Correct way to make datasources/resources a deploy-time setting

I have a web-app that requires two settings:
A JDBC datasource
A string token
I desperately want to be able to deploy one .war to various different containers (jetty,tomcat,gf3 minimum) and configure these settings at application level within the container.
My code does this:
InitialContext ctx = new InitialContext();
Context envCtx = (javax.naming.Context) ctx.lookup("java:comp/env");
token = (String)envCtx.lookup("token");
ds = (DataSource)envCtx.lookup("jdbc/datasource")
Let's assume I've used the glassfish management interface to create two jdbc resources: jdbc/test-datasource and jdbc/live-datasource which connect to different copies of the same schema, on different servers, different credentials etc. Say I want to deploy this to glassfish with and point it at the test datasource, I might have this in my sun-web.xml:
...
<resource-ref>
<res-ref-name>jdbc/datasource</res-ref-name>
<jndi-name>jdbc/test-datasource</jndi-name>
</resource-ref>
...
but
sun-web.xml goes inside my war, right?
surely there must be a way to do this through the management interface
Am I even trying to do the right thing? Do other containers make this any easier? I'd be particularly interested in how jetty 7 handles this since I use it for development.
EDIT Tomcat has a reasonable way to do this:
Create $TOMCAT_HOME/conf/Catalina/localhost/webapp.xml with:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true">
<!-- String resource -->
<Environment name="token" value="value of token" type="java.lang.String" override="false" />
<!-- Linking to a global resource -->
<ResourceLink name="jdbc/datasource1" global="jdbc/test" type="javax.sql.DataSource" />
<!-- Derby -->
<Resource name="jdbc/datasource2"
type="javax.sql.DataSource"
auth="Container"
driverClassName="org.apache.derby.jdbc.EmbeddedDataSource"
url="jdbc:derby:test;create=true"
/>
<!-- H2 -->
<Resource name="jdbc/datasource3"
type="javax.sql.DataSource"
auth="Container"
driverClassName="org.h2.jdbcx.JdbcDataSource"
url="jdbc:h2:~/test"
username="sa"
password=""
/>
</Context>
Note that override="false" means the opposite. It means that this setting can't be overriden by web.xml.
I like this approach because the file is part of the container configuration not the war, but it's not part of the global configuration; it's webapp specific.
I guess I expect a bit more from glassfish since it is supposed to have a full web admin interface, but I would be happy enough with something equivalent to the above.
For GF v3, you may want to try leveraging the --deploymentplan option of the deploy subcommand of asadmin. It is discussed on the man page for the deploy subcommand.
We had just this issue when migrating from Tomcat to Glassfish 3. Here is what works for us.
In the Glassfish admin console, configure datasources (JDBC connection pools and resources) for DEV/TEST/PROD/etc.
Record your deployment time parameters (in our case database connect info) in properties file. For example:
# Database connection properties
dev=jdbc/dbdev
test=jdbc/dbtest
prod=jdbc/dbprod
Each web app can load the same database properties file.
Lookup the JDBC resource as follows.
import java.sql.Connection;
import javax.sql.DataSource;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* #param resourceName the resource name of the connection pool (eg jdbc/dbdev)
* #return Connection a pooled connection from the data source
* associated with resourceName
* #throws NamingException will be thrown if resource name is not found
*/
public Connection getDatabaseConnection(String resourceName)
throws NamingException, SQLException {
Context initContext = new InitialContext();
DataSource pooledDataSource = (DataSource) initContext.lookup(resourceName);
return pooledDataSource.getConnection();
}
Note that this is not the usual two step process involving a look up using the naming context "java:comp/env." I have no idea if this works in application containers other than GF3, but in GF3 there is no need to add resource descriptors to web.xml when using the above approach.
I'm not sure to really understand the question/problem.
As an Application Component Provider, you declare the resource(s) required by your application in a standard way (container agnostic) in the web.xml.
At deployment time, the Application Deployer and Administrator is supposed to follow the instructions provided by the Application Component Provider to resolve external dependencies (amongst other things) for example by creating a datasource at the application server level and mapping its real JNDI name to the resource name used by the application through the use of an application server specific deployment descriptor (e.g. the sun-web.xml for GlassFish). Obviously, this is a container specific step and thus not covered by the Java EE specification.
Now, if you want to change the database an application is using, you'll have to either:
change the mapping in the application server deployment descriptor - or -
modify the configuration of the existing datasource to make it points on another database.
Having an admin interface doesn't really change anything. If I missed something, don't hesitate to let me know. And just in case, maybe have a look at this previous answer.