From 485441f2635effb8655d7d00d7f6896bfab996cb Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 9 Jan 2012 02:06:27 +0000 Subject: Policy archetype (work in progress) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1229004 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-2.x/trunk/maven/archetypes/policy/pom.xml | 67 ++++++++++++ .../META-INF/maven/archetype-metadata.xml | 70 +++++++++++++ .../archetype-resources/META-INF/MANIFEST.MF | 28 +++++ .../src/main/resources/archetype-resources/pom.xml | 45 ++++++++ .../src/main/java/__policyName__Policy.java | 68 +++++++++++++ .../src/main/java/__policyName__PolicyBuilder.java | 87 ++++++++++++++++ .../main/java/__policyName__PolicyProcessor.java | 113 +++++++++++++++++++++ ...__policyName__ImplementationPolicyProvider.java | 59 +++++++++++ .../provider.__policyName__PolicyInterceptor.java | 79 ++++++++++++++ ...ovider.__policyName__PolicyProviderFactory.java | 71 +++++++++++++ ...ider.__policyName__ReferencePolicyProvider.java | 55 ++++++++++ ...ovider.__policyName__ServicePolicyProvider.java | 52 ++++++++++ ...ache.tuscany.sca.assembly.builder.PolicyBuilder | 17 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 20 ++++ ....apache.tuscany.sca.definitions.xml.Definitions | 17 ++++ ...ache.tuscany.sca.provider.PolicyProviderFactory | 20 ++++ .../src/main/resources/definitions.xml | 41 ++++++++ .../src/test/java/PolicyReadTestCase.java | 97 ++++++++++++++++++ .../sca/policy/logging/jdk/mock_policies.xml | 26 +++++ .../resources/projects/basic/archetype.properties | 22 ++++ .../src/test/resources/projects/basic/goal.txt | 0 21 files changed, 1054 insertions(+) create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/pom.xml create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/META-INF/MANIFEST.MF create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/pom.xml create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__Policy.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyBuilder.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyProcessor.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ImplementationPolicyProvider.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyInterceptor.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyProviderFactory.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ReferencePolicyProvider.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ServicePolicyProvider.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/definitions.xml create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/java/PolicyReadTestCase.java create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/resources/org/apache/tuscany/sca/policy/logging/jdk/mock_policies.xml create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/archetype.properties create mode 100644 sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/goal.txt (limited to 'sca-java-2.x/trunk/maven') diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/pom.xml b/sca-java-2.x/trunk/maven/archetypes/policy/pom.xml new file mode 100644 index 0000000000..4fc6d796b1 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../../pom.xml + + + tuscany-policy-archetype + maven-archetype + Create a Tuscany policy extension project + Create a Tuscany policy extension project + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + true + + + + + + + + apache.releases.https + Apache Release Distribution Repository + https://repository.apache.org/service/local/staging/deploy/maven2 + + + false + apache.snapshots.https + Apache Development Snapshot Repository + https://repository.apache.org/content/repositories/snapshots + + + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/META-INF/maven/archetype-metadata.xml b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000..1d260f241b --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + src/main/java + + **/*.java + + + + src/main/resources + + **/*.* + + + **/definitions.xml + + + + src/main/resources + + **/definitions.xml + + + + src/test/java + + **/*.java + + + + src/test/resources + + **/*.* + + + + META-INF + + MANIFEST.MF + + + + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a41ac55cb6 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Private-Package: org.apache.tuscany.sca.policy.logging;version="2.0.0",o + rg.apache.tuscany.sca.policy.logging.jdk;version="2.0.0" +SCA-Version: 1.1 +Bundle-Name: Apache Tuscany ${policyName} Policy Model +Bundle-Vendor: The Apache Software Foundation +Bundle-Version: 2.0.0 +Bundle-ManifestVersion: 2 +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-Description: Apache Tuscany ${policyName} Policy Model +Import-Package: javax.xml.namespace, + javax.xml.stream, + org.apache.tuscany.sca.assembly;version="2.0.0", + org.apache.tuscany.sca.assembly.builder;version="2.0.0", + org.apache.tuscany.sca.contribution.processor;version="2.0.0", + org.apache.tuscany.sca.contribution.resolver;version="2.0.0", + org.apache.tuscany.sca.core;version="2.0.0", + org.apache.tuscany.sca.definitions;version="2.0.0", + org.apache.tuscany.sca.interfacedef;version="2.0.0", + org.apache.tuscany.sca.invocation;version="2.0.0", + org.apache.tuscany.sca.monitor;version="2.0.0", + org.apache.tuscany.sca.policy;version="2.0.0", + org.apache.tuscany.sca.provider;version="2.0.0", + org.apache.tuscany.sca.runtime;version="2.0.0", + org.oasisopen.sca.annotation +Bundle-SymbolicName: ${package}.${policyName} +Bundle-DocURL: http://www.apache.org/ + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/pom.xml b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..d436d21970 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + ${artifactId} + ${groupId} + Apache Tuscany SCA Extension Policy Logging Model + + + + + org.apache.tuscany.sca + tuscany-core-runtime-pom + pom + provided + 2.0-SNAPSHOT + + + + + ${version} + + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__Policy.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__Policy.java new file mode 100644 index 0000000000..921475c7b8 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__Policy.java @@ -0,0 +1,68 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}Policy { + static final String SCA11_NS = Base.SCA11_NS; + static final String SCA11_TUSCANY_NS = Base.SCA11_TUSCANY_NS; + + static final QName POLICY_QNAME = new QName(SCA11_TUSCANY_NS, "${policyName}"); + + private String configProperty; + + public String getConfigProperty() { + return configProperty; + } + + public void setConfigProperty(String configProperty) { + this.configProperty = configProperty; + } + + public QName getSchemaName() { + return POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public String toString() { + return "${policyName}Policy [configProperty=" + configProperty + + "]"; + } +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyBuilder.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyBuilder.java new file mode 100644 index 0000000000..146b04c7ec --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyBuilder.java @@ -0,0 +1,87 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package ${package}; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * + */ +public class ${policyName}PolicyBuilder implements PolicyBuilder<${policyName}Policy> { + + public boolean build(Endpoint endpoint, BuilderContext context) { + List<${policyName}Policy> polices = getPolicies(endpoint); + System.out.println(endpoint + ": " + polices); + return true; + } + + public boolean build(EndpointReference endpointReference, BuilderContext context) { + List<${policyName}Policy> polices = getPolicies(endpointReference); + System.out.println(endpointReference + ": " + polices); + return true; + } + + public boolean build(Component component, Implementation implementation, BuilderContext context) { + List<${policyName}Policy> polices = getPolicies(implementation); + System.out.println(implementation + ": " + polices); + return true; + } + + public QName getPolicyType() { + return ${policyName}Policy.POLICY_QNAME; + } + + public List getSupportedBindings() { + return null; + } + + private List<${policyName}Policy> getPolicies(PolicySubject subject) { + List<${policyName}Policy> polices = new ArrayList<${policyName}Policy>(); + for (PolicySet ps : subject.getPolicySets()) { + for (PolicyExpression exp : ps.getPolicies()) { + if (getPolicyType().equals(exp.getName())) { + polices.add((${policyName}Policy)exp.getPolicy()); + } + } + } + return polices; + } + + public boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) { + return true; + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyProcessor.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyProcessor.java new file mode 100644 index 0000000000..ba9169b39c --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__PolicyProcessor.java @@ -0,0 +1,113 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}PolicyProcessor implements StAXArtifactProcessor<${policyName}Policy> { + + public QName getArtifactType() { + return ${policyName}Policy.POLICY_QNAME; + } + + public ${policyName}PolicyProcessor(FactoryExtensionPoint modelFactories) { + } + + + public ${policyName}Policy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + ${policyName}Policy policy = new ${policyName}Policy(); + int event = reader.getEventType(); + QName name = null; + + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(${policyName}Policy.POLICY_QNAME) ) { + String config = reader.getAttributeValue(null, "name"); + policy.setConfigurationProperty(config); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( ${policyName}Policy.POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(${policyName}Policy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + POLICY_QNAME.getLocalPart(), + POLICY_QNAME.getNamespaceURI()); + writer.writeNamespace("tuscany", ${policyName}Policy.SCA11_TUSCANY_NS); + + if (policy.getConfigurationProperty() != null) { + writer.writeAttribute("name", policy.getConfigurationProperty()); + } + + writer.writeEndElement(); + } + + public Class<${policyName}Policy> getModelType() { + return ${policyName}Policy.class; + } + + public void resolve(${policyName}Policy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ImplementationPolicyProvider.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ImplementationPolicyProvider.java new file mode 100644 index 0000000000..258c623f69 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ImplementationPolicyProvider.java @@ -0,0 +1,59 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package ${package}; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +import com.shutterfly.middleware.tuscany.sca.policy.authorization.AuthorizationPolicy; +import com.shutterfly.middleware.tuscany.sca.policy.authorization.provider.PolicySet; +import com.shutterfly.middleware.tuscany.sca.policy.util.PolicyHelper; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ImplementationPolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private RuntimeComponent component; + + public ${policyName}ImplementationPolicyProvider(RuntimeComponent component) { + super(${policyName}Policy.class, component.getImplementation()); + this.component = component; + } + + /** + * @see ${groupId}.provider.PolicyProvider${symbol_pound}createInterceptor(${groupId}.interfacedef.Operation) + */ + public PhasedInterceptor createInterceptor(Operation operation) { + List policySets = PolicyHelper.findPolicySets(component, ${policyName}Policy.POLICY_QNAME); + + + return policySets.isEmpty() ? null : new ${policyName}PolicyInterceptor(subject, getContext(), operation, + policySets, Phase.IMPLEMENTATION_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyInterceptor.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyInterceptor.java new file mode 100644 index 0000000000..7ec95aee4f --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyInterceptor.java @@ -0,0 +1,79 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import java.util.List; +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}${policyName}Policy + * + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}PolicyInterceptor implements PhasedInterceptor { + private Invoker next; + private Operation operation; + + public ${policyName}PolicyInterceptor(String context, Operation operation, String phase) { + + super(); + this.operation = operation; + this.context = context; + this.phase = phase; + } + + public Message invoke(Message msg) { + + // DO SOMETHING HERE + System.out.println("Inside policy interceptor invoke method"); + + return getNext.invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public String getPhase() { + return phase; + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyProviderFactory.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyProviderFactory.java new file mode 100644 index 0000000000..796381fd7d --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__PolicyProviderFactory.java @@ -0,0 +1,71 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package ${package}; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}PolicyProviderFactory implements PolicyProviderFactory<${policyName}Policy> { + private ExtensionPointRegistry registry; + + public ${policyName}PolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createImplementationPolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return new ${policyName}ImplementationPolicyProvider(component); + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createReferencePolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.runtime.RuntimeComponentReference, ${groupId}.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new ${policyName}ReferencePolicyProvider(endpointReference); + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createServicePolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.runtime.RuntimeComponentService, ${groupId}.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new ${policyName}ServicePolicyProvider(endpoint); + } + + /** + * @see ${groupId}.provider.ProviderFactory${symbol_pound}getModelType() + */ + public Class<${policyName}Policy> getModelType() { + return ${policyName}Policy.class; + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ReferencePolicyProvider.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ReferencePolicyProvider.java new file mode 100644 index 0000000000..bb93a756ce --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ReferencePolicyProvider.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package ${package}; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +import com.shutterfly.middleware.tuscany.sca.policy.authorization.provider.AuthorizationPolicyInterceptor; +import com.shutterfly.middleware.tuscany.sca.policy.authorization.provider.PolicySet; +import com.shutterfly.middleware.tuscany.sca.policy.metrics.PerformanceMetricsPolicy; +import com.shutterfly.middleware.tuscany.sca.policy.util.PolicyHelper; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ReferencePolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private EndpointReference endpointReference; + + public ${policyName}ReferencePolicyProvider(EndpointReference endpointReference) { + super(${policyName}Policy.class, endpointReference); + this.endpointReference = endpointReference; + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List policySets = PolicyHelper.findPolicySets(endpointReference, ${policyName}Policy.POLICY_QNAME); + + return (policySets.isEmpty()) ? null : new ${policyName}PolicyInterceptor(getContext(), operation, Phase.REFERENCE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ServicePolicyProvider.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ServicePolicyProvider.java new file mode 100644 index 0000000000..2f019ab606 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/provider.__policyName__ServicePolicyProvider.java @@ -0,0 +1,52 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package ${package}; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +import com.shutterfly.middleware.tuscany.sca.policy.authorization.provider.RuntimeComponent; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ServicePolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private RuntimeComponent component; + + public ${policyName}ServicePolicyProvider(Endpoint endpoint) { + super(${policyName}Policy.class, endpoint); + this.component = component; + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List policySets = PolicyHelper.findPolicySets(component, ${policyName}Policy.POLICY_QNAME); + + return policySets.isEmpty() ? null : new ${policyName}PolicyInterceptor(subject, getContext(), operation, policySets, Phase.SERVICE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder new file mode 100644 index 0000000000..42b3ff5556 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicyBuilder;qname=http://tuscany.apache.org/xmlns/sca/1.1#jdkLogger diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..fce12e6e55 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +${package}.${policyName}PolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#jdkLogger,model=${package}.${policyName}Policy + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions new file mode 100644 index 0000000000..a3cc52cd3c --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +org/apache/tuscany/sca/policy/logging/definitions.xml diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..3bbbc3108c --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the policy extension +org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicyProviderFactory;model=org.apache.tuscany.sca.policy.logging.jdk.JDKLoggingPolicy + diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/definitions.xml b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/definitions.xml new file mode 100644 index 0000000000..4e24d0e93b --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/resources/definitions.xml @@ -0,0 +1,41 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + All messages to and from this implementation must be logged + + + + + + + All messages to and from this implementation must be logged + + + + \ No newline at end of file diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/java/PolicyReadTestCase.java b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/java/PolicyReadTestCase.java new file mode 100644 index 0000000000..618dec57ce --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/java/PolicyReadTestCase.java @@ -0,0 +1,97 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + + +import java.io.InputStream; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URL; +import java.util.logging.Level; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import ${groupId}.contribution.processor.ProcessorContext; + +/** + * Test the reading of ws config params policy. + * + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class PolicyReadTestCase extends TestCase { + private ProcessorContext context = new ProcessorContext(); + + @Override + public void setUp() throws Exception { + } + + @Override + public void tearDown() throws Exception { + } + + public void testPolicyReading() throws Exception { + JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null); + + URL url = getClass().getResource("mock_policies.xml"); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + InputStream urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + + + JDKLoggingPolicy policy = processor.read(reader, context); + assertEquals(policy.getLoggerName(), "test.logger"); + assertEquals(policy.getLogLevel(), Level.INFO ); + assertEquals(policy.getResourceBundleName(), "Trace_Messages.properties"); + } + + public void testPolicyWriting() throws Exception { + JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null); + + JDKLoggingPolicy policy = new JDKLoggingPolicy(); + policy.setLoggerName("test.logger"); + policy.setLogLevel(Level.INFO); + policy.setResourceBundleName("Trace_Messages.properties"); + + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + StringWriter sw = new StringWriter(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw); + processor.write(policy, writer, context); + writer.close(); + + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + StringReader sr = new StringReader(sw.toString()); + XMLStreamReader reader = inputFactory.createXMLStreamReader(sr); + + policy = processor.read(reader, context); + assertEquals(policy.getLoggerName(), "test.logger"); + assertEquals(policy.getLogLevel(), Level.INFO ); + assertEquals(policy.getResourceBundleName(), "Trace_Messages.properties"); + + } + +} diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/resources/org/apache/tuscany/sca/policy/logging/jdk/mock_policies.xml b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/resources/org/apache/tuscany/sca/policy/logging/jdk/mock_policies.xml new file mode 100644 index 0000000000..4fcfffb115 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/main/resources/archetype-resources/src/test/resources/org/apache/tuscany/sca/policy/logging/jdk/mock_policies.xml @@ -0,0 +1,26 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + INFO + Trace_Messages.properties + \ No newline at end of file diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/archetype.properties b/sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000000..6e140b54b7 --- /dev/null +++ b/sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +#Sat Sep 04 08:10:22 BST 2010 +version=0.1-SNAPSHOT +groupId=archetype.it +package=archetype.it.basic +artifactId=basic +policyName=Basic diff --git a/sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/goal.txt b/sca-java-2.x/trunk/maven/archetypes/policy/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3