Your testcase exposed a couple issues. :-) I've marked them at:
https://issues.apache.org/jira/browse/NEETHI-12 Fundamentally, the issue is that your document isn't a policy. It's a collection of policies. Neethi doesn't really support that, it's up to you to wire the collection of policies together. In your case, you would need something like: Element d = getResourceAsDOM(file); Node nd = d.getFirstChild(); Policy first = null; while (nd != null) { if (nd instanceof Element) { Policy p = policyEngine.getPolicy(nd); if (p.getId() != null) { policyEngine.getPolicyRegistry() .register("#" + p.getId(), p); } if (first == null) { first = p; } } nd = nd.getNextSibling(); } first.normalize(true); I've updated the trunk code (to be released as 3.0.1 soon) to check if the incoming namespace of the root element is really a valid policy namespace or not. With 3.0.1, your code SHOULD throw an IllegalArguementException. Dan On Monday, July 04, 2011 6:29:15 PM JAYA KARTHIK wrote: > Hi, > > Am a new Apache Neethi user.I downloaded the latest Apache Neethi 3.0.0 > binaries. On using <PolicyReference ..> I get the following exception when > it tries to resolve the corresponding policy. > > Exception in thread "main" java.lang.RuntimeException: #PolicyID can't be > resolved at > org.apache.neethi.AbstractPolicyOperator.normalizeOperator(AbstractPolicyOp > erator.java:130) at > org.apache.neethi.AbstractPolicyOperator.normalizeOperator(AbstractPolicyOp > erator.java:143) at > org.apache.neethi.AbstractPolicyOperator.normalizeOperator(AbstractPolicyOp > erator.java:140) at > org.apache.neethi.AbstractPolicyOperator.normalize(AbstractPolicyOperator.j > ava:87) at org.apache.neethi.Policy.normalize(Policy.java:95) > at org.apache.neethi.Policy$PolicyIterator.<init>(Policy.java:245) > at org.apache.neethi.Policy.getAlternatives(Policy.java:235) > at TestNeethi.test(TestNeethi.java:26) > at TestNeethi.main(TestNeethi.java:18) > > Following is the test source code: > > public class TestNeethi{ > public static void main(String args[])throws Exception{ > new TestNeethi().test(args[0]); > } > public void test(String file) throws Exception{ > Assertion ast=null; > PolicyBuilder builder = new PolicyBuilder(); > builder.setPolicyRegistry(new PolicyRegistryImpl()); > Policy policy=builder.getPolicy(getResourceAsDOM(file)); > Iterator it = policy.getAlternatives(); > while(it.hasNext()){ > List k =(ArrayList)it.next(); > for(int g=0;g<k.size();g++){ > ast = (org.apache.neethi.Assertion)k.get(g); > System.out.println(ast.toString()); > } > } > } > public Element getResourceAsDOM(String name) > throws ParserConfigurationException, SAXException, IOException { > InputStream in = new FileInputStream(name); > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > dbf.setValidating(false); > dbf.setIgnoringComments(false); > dbf.setIgnoringElementContentWhitespace(true); > dbf.setNamespaceAware(true); > DocumentBuilder db = null; > db = dbf.newDocumentBuilder(); > return db.parse(in).getDocumentElement(); > } > } > > Policy file used: > > <Policies xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" > xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecuri > ty-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing"> > <wsp:Policy Name="OuterPolicy" > > <wsp:All> > <wsp:PolicyReference URI="#PolicyID"/> > </wsp:All> > </wsp:Policy> > <wsp:Policy Name="TestPolicy" wsu:Id="PolicyID" > > <wsp:All> > <wsaws:UsingAddressing > xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/> </wsp:All> > </wsp:Policy> > </Policies> > > Not sure if am missing something.Could you please help me in resolving this? > > Thanks&Regards > J.JayaKarthik. -- Daniel Kulp [email protected] http://dankulp.com/blog Talend - http://www.talend.com --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
