Author: palin
Date: 2007-04-27 08:03:58 -0400 (Fri, 27 Apr 2007)
New Revision: 2942
Added:
branches/JBWS-856/jbossws-tests/src/resources/common/wsdl11/PolicyAttachmentFragment.wsdl
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/common/wsdl11/WSDL11TestCase.java
Log:
Partial commit:
- Modified WSDL11TestCase to test policy attachments in wsdl fragment
- Work in progress on JAXWSWebServiceMetaDataBuilder to support @Policy
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-04-27
11:11:32 UTC (rev 2941)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-04-27
12:03:58 UTC (rev 2942)
@@ -34,6 +34,7 @@
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
+import org.jboss.ws.annotation.Policy;
import org.jboss.ws.core.server.UnifiedDeploymentInfo;
import org.jboss.ws.core.utils.IOUtils;
import org.jboss.ws.metadata.builder.MetaDataBuilder;
@@ -53,6 +54,7 @@
import org.jboss.ws.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;
import org.jboss.ws.tools.ToolsUtils;
import org.jboss.ws.tools.jaxws.JAXBWSDLGenerator;
+import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
import org.jboss.ws.tools.wsdl.WSDLGenerator;
import org.jboss.ws.tools.wsdl.WSDLWriter;
import org.jboss.ws.tools.wsdl.WSDLWriterResolver;
@@ -80,6 +82,7 @@
private ServerEndpointMetaData sepMetaData;
private ServiceMetaData serviceMetaData;
private URL wsdlLocation;
+ private URL policyLocation;
}
public void setGenerateWsdl(boolean generateWsdl)
@@ -130,7 +133,7 @@
// The server must always generate WSDL
if (generateWsdl || !toolMode)
- processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData);
+ processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData, result.policyLocation);
// No need to process endpoint items if we are in tool mode
if (toolMode)
@@ -168,6 +171,10 @@
log.warn("@SOAPMessageHandlers is deprecated as of JAX-WS 2.0 with no
replacement.");
MetaDataBuilder.replaceAddressLocation(sepMetaData);
+
+ //POL-2
+ //TODO!!!
+
processEndpointMetaDataExtensions(sepMetaData, wsdlDefinitions);
// init service endpoint id
@@ -326,79 +333,128 @@
result.wsdlLocation = udi.getMetaDataFileURL(wsdlLocation);
result.serviceMetaData.addEndpoint(result.sepMetaData);
wsMetaData.addService(result.serviceMetaData);
+
+ //Check for policy attachment file
+ Policy anPolicy = sepClass.getAnnotation(Policy.class);
+ if (anPolicy!=null)
+ {
+ String policyLocation = anPolicy.wsdlFragmentLocation();
+ if (policyLocation==null || policyLocation.length()==0)
+ throw new WSException("Missing wsdlFragmentLocation for @Policy on
" + sepClass.getName());
+ result.policyLocation = udi.getMetaDataFileURL(policyLocation);
+ }
return result;
}
- private void processOrGenerateWSDL(Class wsClass, ServiceMetaData serviceMetaData, URL
wsdlLocation, EndpointMetaData epMetaData)
+ private void processOrGenerateWSDL(Class wsClass, ServiceMetaData serviceMetaData, URL
wsdlLocation, EndpointMetaData epMetaData, URL policyLocation)
{
- if (wsdlLocation != null)
+ try
{
- serviceMetaData.setWsdlLocation(wsdlLocation);
+ WSDLGenerator generator = new JAXBWSDLGenerator(jaxbCtx);
+ WSDLDefinitionsFactory factory = WSDLDefinitionsFactory.newInstance();
+ if (wsdlLocation != null)
+ {
+ //we can no longer use the user provided wsdl without parsing it right now,
+ //since we need to look for policies, eventually choose the supported
+ //policy alternatives and generate the final wsdl
+ //serviceMetaData.setWsdlLocation(wsdlLocation);
+
+ WSDLDefinitions wsdlDefinitions = factory.parse(wsdlLocation);
+ if (policyLocation == null)
+ {
+ //process wsdl fragment with additional policies
+ WSDLDefinitions policyDefinitions = factory.parse(policyLocation);
+ }
+
+ //POL-1
+ //TODO!!!
+
+ //generate the wsdl4j model again for the actual UMDM containing policy data
+ WSDLDefinitions actualWsdlDefinitions = generator.generate(serviceMetaData);
+ writeWsdl(serviceMetaData,actualWsdlDefinitions,epMetaData);
+ }
+ else
+ {
+ WSDLDefinitions wsdlDefinitions = generator.generate(serviceMetaData);
+ //we write the generated wsdl right now only if we have no additional
policies
+ //otherwise we first parse them since they may change the actual wsdl to
be written
+ if (policyLocation == null)
+ {
+ writeWsdl(serviceMetaData,wsdlDefinitions,epMetaData);
+ }
+ else
+ {
+ WSDLDefinitions policyDefinitions = factory.parse(policyLocation);
+
+ //POL-1
+ //TODO!!!
+
+ //generate the wsdl4j model again for the actual UMDM containing policy
data
+ WSDLDefinitions actualWsdlDefinitions =
generator.generate(serviceMetaData);
+ writeWsdl(serviceMetaData,actualWsdlDefinitions,epMetaData);
+ }
+ }
}
- else
+ catch (RuntimeException rte)
{
- try
- {
- // The RI uses upper case, and the TCK expects it, so we just mimic this even
though we don't really have to
- String wsdlName =
ToolsUtils.firstLetterUpperCase(serviceMetaData.getServiceName().getLocalPart());
+ throw rte;
+ }
+ catch (IOException e)
+ {
+ throw new WSException("Cannot write generated wsdl", e);
+ }
+ }
+
+
+ public void writeWsdl(ServiceMetaData serviceMetaData, WSDLDefinitions
wsdlDefinitions, EndpointMetaData epMetaData)
+ {
+ // The RI uses upper case, and the TCK expects it, so we just mimic this even
though we don't really have to
+ String wsdlName =
ToolsUtils.firstLetterUpperCase(serviceMetaData.getServiceName().getLocalPart());
+ // Ensure that types are only in the interface qname
+
wsdlDefinitions.getWsdlTypes().setNamespace(epMetaData.getPortTypeName().getNamespaceURI());
- WSDLGenerator generator = new JAXBWSDLGenerator(jaxbCtx);
- WSDLDefinitions wsdlDefinitions = generator.generate(serviceMetaData);
+ final File dir, wsdlFile;
- // Ensure that types are only in the interface qname
-
wsdlDefinitions.getWsdlTypes().setNamespace(epMetaData.getPortTypeName().getNamespaceURI());
+ if (wsdlDirectory != null)
+ {
+ dir = wsdlDirectory;
+ wsdlFile = new File(dir, wsdlName + ".wsdl");
+ }
+ else
+ {
+ dir = IOUtils.createTempDirectory();
+ wsdlFile = File.createTempFile(wsdlName, ".wsdl", dir);
+ wsdlFile.deleteOnExit();
+ }
- final File dir, wsdlFile;
-
+ message(wsdlFile.getName());
+ Writer writer = IOUtils.getCharsetFileWriter(wsdlFile,
Constants.DEFAULT_XML_CHARSET);
+ new WSDLWriter(wsdlDefinitions).write(writer, Constants.DEFAULT_XML_CHARSET, new
WSDLWriterResolver() {
+ public WSDLWriterResolver resolve(String suggestedFile) throws IOException
+ {
+ File file;
if (wsdlDirectory != null)
{
- dir = wsdlDirectory;
- wsdlFile = new File(dir, wsdlName + ".wsdl");
+ file = new File(dir, suggestedFile + ".wsdl");
}
else
{
- dir = IOUtils.createTempDirectory();
- wsdlFile = File.createTempFile(wsdlName, ".wsdl", dir);
- wsdlFile.deleteOnExit();
+ file = File.createTempFile(suggestedFile, ".wsdl", dir);
+ file.deleteOnExit();
}
+ actualFile = file.getName();
+ message(actualFile);
+ charset = Constants.DEFAULT_XML_CHARSET;
+ writer = IOUtils.getCharsetFileWriter(file, Constants.DEFAULT_XML_CHARSET);
+ return this;
+ }
+ });
+ writer.close();
- message(wsdlFile.getName());
- Writer writer = IOUtils.getCharsetFileWriter(wsdlFile,
Constants.DEFAULT_XML_CHARSET);
- new WSDLWriter(wsdlDefinitions).write(writer, Constants.DEFAULT_XML_CHARSET,
new WSDLWriterResolver() {
- public WSDLWriterResolver resolve(String suggestedFile) throws
IOException
- {
- File file;
- if (wsdlDirectory != null)
- {
- file = new File(dir, suggestedFile + ".wsdl");
- }
- else
- {
- file = File.createTempFile(suggestedFile, ".wsdl", dir);
- file.deleteOnExit();
- }
- actualFile = file.getName();
- message(actualFile);
- charset = Constants.DEFAULT_XML_CHARSET;
- writer = IOUtils.getCharsetFileWriter(file,
Constants.DEFAULT_XML_CHARSET);
- return this;
- }
- });
- writer.close();
-
- serviceMetaData.setWsdlLocation(wsdlFile.toURL());
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (IOException e)
- {
- throw new WSException("Cannot write generated wsdl", e);
- }
- }
+ serviceMetaData.setWsdlLocation(wsdlFile.toURL());
}
+
private void message(String msg)
{
Modified:
branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/common/wsdl11/WSDL11TestCase.java
===================================================================
---
branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/common/wsdl11/WSDL11TestCase.java 2007-04-27
11:11:32 UTC (rev 2941)
+++
branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/common/wsdl11/WSDL11TestCase.java 2007-04-27
12:03:58 UTC (rev 2942)
@@ -192,7 +192,14 @@
{
File wsdlFile = new
File("resources/common/wsdl11/PolicyAttachment.wsdl");
assertTrue(wsdlFile.exists());
-
+ testPolicyAttachment(wsdlFile);
+ wsdlFile = new
File("resources/common/wsdl11/PolicyAttachmentFragment.wsdl");
+ assertTrue(wsdlFile.exists());
+ testPolicyAttachment(wsdlFile);
+ }
+
+ private void testPolicyAttachment(File wsdlFile) throws Exception
+ {
WSDLDefinitionsFactory factory = WSDLDefinitionsFactory.newInstance();
WSDLDefinitions wsdlDefinitions = factory.parse(wsdlFile.toURL());
assertNotNull(wsdlDefinitions);
@@ -213,6 +220,13 @@
public void testServicePolicyRef() throws Exception
{
File wsdlFile = new
File("resources/common/wsdl11/PolicyAttachment.wsdl");
+ testServicePolicyRef(wsdlFile);
+ wsdlFile = new
File("resources/common/wsdl11/PolicyAttachmentFragment.wsdl");
+ testServicePolicyRef(wsdlFile);
+ }
+
+ public void testServicePolicyRef(File wsdlFile) throws Exception
+ {
WSDLDefinitionsFactory factory = WSDLDefinitionsFactory.newInstance();
WSDLDefinitions wsdlDefinitions = factory.parse(wsdlFile.toURL());
WSDLService wsdlService = wsdlDefinitions.getServices()[0];
@@ -226,6 +240,13 @@
public void testEndpointPolicyRef() throws Exception
{
File wsdlFile = new
File("resources/common/wsdl11/PolicyAttachment.wsdl");
+ testEndpointPolicyRef(wsdlFile);
+ wsdlFile = new
File("resources/common/wsdl11/PolicyAttachmentFragment.wsdl");
+ testEndpointPolicyRef(wsdlFile);
+ }
+
+ public void testEndpointPolicyRef(File wsdlFile) throws Exception
+ {
WSDLDefinitionsFactory factory = WSDLDefinitionsFactory.newInstance();
WSDLDefinitions wsdlDefinitions = factory.parse(wsdlFile.toURL());
WSDLService wsdlService = wsdlDefinitions.getServices()[0];
@@ -250,7 +271,6 @@
assertPolicyRef(extBinding.get(1),"X509EndpointPolicy");
}
-
private void assertPolicyRef(WSDLExtensibilityElement extEl, String policyURI)
{
Element el = extEl.getElement();
Added:
branches/JBWS-856/jbossws-tests/src/resources/common/wsdl11/PolicyAttachmentFragment.wsdl
===================================================================
---
branches/JBWS-856/jbossws-tests/src/resources/common/wsdl11/PolicyAttachmentFragment.wsdl
(rev 0)
+++
branches/JBWS-856/jbossws-tests/src/resources/common/wsdl11/PolicyAttachmentFragment.wsdl 2007-04-27
12:03:58 UTC (rev 2942)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<definitions name="TestService"
targetNamespace="http://org.jboss.ws/jaxrpc"
+ xmlns:tns="http://org.jboss.ws/jaxrpc"
+
xmlns="http://schemas.xmlsoap.org/wsdl/"
+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+
xmlns:fab="http://www.fabrikam123.example.com/stock"
+
xmlns:rmp="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
+
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
+
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-w...
>
+ <wsp:Policy wsu:Id="RmPolicy" >
+ <rmp:RMAssertion>
+ <rmp:InactivityTimeout Milliseconds="600000" />
+ <rmp:BaseRetransmissionInterval Milliseconds="3000" />
+ <rmp:ExponentialBackoff />
+ <rmp:AcknowledgementInterval Milliseconds="200" />
+ </rmp:RMAssertion>
+ </wsp:Policy>
+ <wsp:Policy wsu:Id="uselessServicePolicy" >
+ <fab:useless>nothing</fab:useless>
+ </wsp:Policy>
+ <wsp:Policy wsu:Id="uselessPortPolicy" >
+ <fab:useless>nothing again</fab:useless>
+ </wsp:Policy>
+ <wsp:Policy wsu:Id="X509EndpointPolicy" >
+ <sp:AsymmetricBinding>
+ <wsp:Policy>
+ <!-- Details omitted for readability -->
+ <sp:IncludeTimestamp />
+ <sp:OnlySignEntireHeadersAndBody />
+ </wsp:Policy>
+ </sp:AsymmetricBinding>
+ </wsp:Policy>
+ <wsp:Policy wsu:Id="SecureMessagePolicy" >
+ <sp:SignedParts>
+ <sp:Body />
+ </sp:SignedParts>
+ <sp:EncryptedParts>
+ <sp:Body />
+ </sp:EncryptedParts>
+ </wsp:Policy>
+ <types>
+ </types>
+ <portType name="JaxRpcTestService"
wsp:PolicyURIs="#RmPolicy">
+ </portType>
+ <binding name="JaxRpcTestServiceBinding"
type="tns:JaxRpcTestService">
+ <soap:binding
transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
+ <wsp:PolicyReference URI="#RmPolicy" wsdl:required="true"
/>
+ <wsp:PolicyReference URI="#X509EndpointPolicy"
wsdl:required="true" />
+ </binding>
+ <service name="TestService">
+ <wsp:PolicyReference URI="#uselessServicePolicy"
wsdl:required="true" />
+ <port name="JaxRpcTestServicePort"
binding="tns:JaxRpcTestServiceBinding">
+ <wsp:PolicyReference URI="#uselessPortPolicy"
wsdl:required="true" />
+ <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
+ </port>
+ </service>
+</definitions>