ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » For Namespace declarations on a specific tag in a JCN

Post new topic  Reply to topic
 For Namespace declarations on a specific tag in a JCN « View previous topic :: View next topic » 
Author Message
JosephGramig
PostPosted: Fri Mar 18, 2016 8:41 am    Post subject: For Namespace declarations on a specific tag in a JCN Reply with quote

Grand Master

Joined: 09 Feb 2006
Posts: 1244
Location: Gold Coast of Florida, USA

In this ESQL Example 1, I see they are creating a namespace declaration on a specific tag.

I need to do this to meet an IRS ACA spec.

I need to add a bunch of namespace declarations on the Envelope tag long before they are used. The parser puts them where they are first referenced.

What is the equivalent in Java?

I'm trying to get something like:

<soapenv:Envelope xmlns:soapenv="http...."
xmlns:NS1="http...1"
xmlns:NS2="http...2"
xmlns:NS3="http...3"
xmlns:NS4="http...4"
...


where the first reference of NS1 (or the others) is several more tags deep.
Back to top
View user's profile Send private message AIM Address
Gralgrathor
PostPosted: Fri Mar 18, 2016 9:02 am    Post subject: Reply with quote

Master

Joined: 23 Jul 2009
Posts: 297

I think it would be something like this:

Code:
String ns1 = "http://name/space/1";

// provided soapEnvelope points to the envelope element
MbElement ns1Decl = soapEnvelope.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "ns1", ns1);


and don't forget:

Code:
someElement.setNamespace(ns1);


to put the actual elements in their proper namespace.
_________________
A measure of wheat for a penny, and three measures of barley for a penny; and see thou hurt not the oil and the wine.
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Fri Mar 18, 2016 9:08 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Gralgrathor wrote:
I think it would be something like this:

Code:
String ns1 = "http://name/space/1";

// provided soapEnvelope points to the envelope element
MbElement ns1Decl = soapEnvelope.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "ns1", ns1);


Yeah, I have some old code that is
Code:
         element.createElementAsFirstChild(MbXMLNSC.NAMESPACE_DECLARATION, "xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");


obviously, first or last child doesn't make a huge difference.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
timber
PostPosted: Fri Mar 18, 2016 9:11 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

If you're writing Java in a JavaCompute node then I strongly recommend that you use the JAXB option ( it's one of the options when you first configure the JCN).
Using JAXB, your Java code deals with Java objects that were generated from the XML Schema. Namespaces are automatically assigned where they are required. As a bonus, you get code assist ( ctrl-space ) to auto-complete the fields in your Java code.

All in all, it makes Java almost as nice to use as ESQL
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Mar 18, 2016 9:18 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

timber wrote:
If you're writing Java in a JavaCompute node then I strongly recommend that you use the JAXB option ( it's one of the options when you first configure the JCN).
Using JAXB, your Java code deals with Java objects that were generated from the XML Schema. Namespaces are automatically assigned where they are required. As a bonus, you get code assist ( ctrl-space ) to auto-complete the fields in your Java code.

All in all, it makes Java almost as nice to use as ESQL


JAXB may or may not allow for the necessary customization of the message tree to include weird and unnatural business requirements...
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
timber
PostPosted: Fri Mar 18, 2016 9:56 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

True - it can only read and write message trees that conform to an XML Schema, so it's not a universal solution. But still pretty useful for the cases where it works, in my opinion.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Mar 18, 2016 10:04 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Huh.

It looks like the five parameter version of createElementAsXChild has been removed from IIBv9 and 10.
http://www.ibm.com/support/knowledgecenter/api/content/nl/en-us/SSMKHH_9.0.0/com.ibm.etools.mft.plugin.doc/com/ibm/broker/plugin/MbElement.html

So you have to create the element, and then use setSpecificType.

Weird.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
JosephGramig
PostPosted: Tue Mar 22, 2016 5:16 am    Post subject: Reply with quote

Grand Master

Joined: 09 Feb 2006
Posts: 1244
Location: Gold Coast of Florida, USA

This is what did work:
Code:
private static String ACA_BH = "urn:us:gov:treasury:irs:msg:acabusinessheader";
...
MbElement outXMLNSC = outMessage.getRootElement().getLastChild();
MbElement outEnvelope = outXMLNSC.getFirstElementByPath("Envelope");
MbElement outBody = outEnvelope.getFirstElementByPath("Body");
MbElement outNS1attr = outBody.createElementBefore(MbElement.TYPE_NAME_VALUE, "xmlns:NS1", ACA_BH);
outNS1attr.setSpecificType(MbXMLNSC.NAMESPACE_DECLARATION);
Back to top
View user's profile Send private message AIM Address
fjb_saper
PostPosted: Tue Mar 22, 2016 5:32 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

JosephGramig wrote:
This is what did work:
Code:
private static String ACA_BH = "urn:us:gov:treasury:irs:msg:acabusinessheader";
...
MbElement outXMLNSC = outMessage.getRootElement().getLastChild();
MbElement outEnvelope = outXMLNSC.getFirstElementByPath("Envelope");
MbElement outBody = outEnvelope.getFirstElementByPath("Body");
MbElement outNS1attr = outBody.createElementBefore(MbElement.TYPE_NAME_VALUE, "xmlns:NS1", ACA_BH);
outNS1attr.setSpecificType(MbXMLNSC.NAMESPACE_DECLARATION);

That's what I remember too... Before Body or First Child of Envelope makes really no distinction... unless you have to have the namespace declarations in a specific order...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
JosephGramig
PostPosted: Tue Mar 22, 2016 9:06 am    Post subject: Reply with quote

Grand Master

Joined: 09 Feb 2006
Posts: 1244
Location: Gold Coast of Florida, USA

Yes, the IRS BatShitCrazy ACA folks need a specific order.
Back to top
View user's profile Send private message AIM Address
timber
PostPosted: Tue Mar 22, 2016 9:30 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

Namespace declarations can appear in any order you like. Can you give an example of a valid XML document that the IRS application rejects?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Mar 22, 2016 9:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

timber wrote:
Namespace declarations can appear in any order you like.

Assuming you're using a compliant XML parser to validate the document...
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
timber
PostPosted: Tue Mar 22, 2016 12:26 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

If the IRS is not using a compliant XML parser then somebody should get a rocket. It's still a possibility, and I knew that when I posted my question. But other possibilities also still exist becauseXML can be confusing and the receiving application can't speak up and defend itself.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » For Namespace declarations on a specific tag in a JCN
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.