Constantes en Spring description file


El fichero de spring:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd>

	<util:constant id="constant1" static-field="org.apache.ws.security.handler.WSHandlerConstants.ACTION"/>
	<bean id="constant2" class="java.lang.String">
		<constructor-arg value="#{T(org.apache.ws.security.handler.WSHandlerConstants).ACTION}" />
	</bean>
	<util:map id="mapProperties">
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).IS_BSP_COMPLIANT}" value="#{T(java.lang.Boolean).FALSE.toString()}"/>
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).ACTION}" value="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIGNATURE}"/>
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).USER}" value="myclientkey" />
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_PROP_FILE}" value="client_sign.properties" />
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_KEY_ID}" value="DirectReference"/>
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_ALGO}" value="#{T(org.apache.ws.security.WSConstants).RSA_SHA1}" />
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_DIGEST_ALGO}" value="#{T(org.apache.ws.security.WSConstants).SHA1}" />
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_C14N_ALGO}" value="#{T(org.apache.ws.security.WSConstants).C14N_OMIT_COMMENTS}" />
		<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIGNATURE_PARTS}" 
			value="#{'{}{' + T(org.apache.ws.security.WSConstants).URI_SOAP11_ENV + '}' + T(org.apache.ws.security.WSConstants).ELEM_BODY + ';'}" />
	</util:map>

La clase test:

package es.depontevedra.soap.interoperabilidad.identidad.paxase;

import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

import static org.testng.Assert.assertTrue;

@ContextConfiguration(locations = { "classpath:spring-properties.xml" })
public class Testing extends AbstractTestNGSpringContextTests {

	@Autowired
	private String constant1;
	
	@Autowired
	private String constant2;
	
	@Resource(name="mapProperties")
	private Map<String, String> mapProperties;
	
	@Test
	public void test(){
		System.out.println("Constante 1: " + constant1);
		System.out.println("Constante 2: " + constant2);
		for(Entry<String, String> entry: mapProperties.entrySet()){
			System.out.println("Clave: " + entry.getKey());
			System.out.println("Valor: " + entry.getValue());
		}
		
		assertTrue(true);
	}
	
}

el resultado:

Constante 1: action
Constante 2: action
Clave: isBSPCompliant
Valor: false
Clave: action
Valor: Signature
Clave: user
Valor: myclientkey
Clave: signaturePropFile
Valor: client_sign.properties
Clave: signatureKeyIdentifier
Valor: DirectReference
Clave: signatureAlgorithm
Valor: http://www.w3.org/2000/09/xmldsig#rsa-sha1
Clave: signatureDigestAlgorithm
Valor: http://www.w3.org/2000/09/xmldsig#sha1
Clave: signatureC14nAlgorithm
Valor: http://www.w3.org/TR/2001/REC-xml-c14n-20010315
Clave: signatureParts
Valor: {}{http://schemas.xmlsoap.org/soap/envelope/}Body;
PASSED: test

librerias que vas a necesitar, en el fichero pom de Maven:

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.ws.security</groupId>
			<artifactId>wss4j</artifactId>
			<version>1.6.13</version>
		</dependency>

		<!-- TEST -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<scope>test</scope>
		</dependency>
Anuncios
Constantes en Spring description file