Project

General

Profile

« Previous | Next » 

Revision 45107

codebase used to migrate to java8 the production system

View differences:

modules/cnr-service-utils/trunk/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-service-utils/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-service-utils"}
modules/cnr-service-utils/trunk/src/test/java/eu/dnetlib/soap/cxf/StandaloneCxfEndpointReferenceBuilderTest.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.mockito.Mockito.when;
5

  
6
import org.junit.Before;
7
import org.junit.Test;
8
import org.junit.runner.RunWith;
9
import org.mockito.runners.MockitoJUnit44Runner;
10

  
11
/**
12
 * test StandaloneCxfEndpointReferenceBuilderTest.
13
 * 
14
 * @author marko
15
 * 
16
 */
17
@RunWith(MockitoJUnit44Runner.class)
18
public class StandaloneCxfEndpointReferenceBuilderTest extends CxfEndpointReferenceBuilderTest {
19

  
20
	/**
21
	 * some constant url prefix.
22
	 */
23
	private static final String HTTP_TEST_COM = "http://test.com";
24

  
25
	/**
26
	 * class under test.
27
	 */
28
	private transient StandaloneCxfEndpointReferenceBuilder builder;
29

  
30
	/**
31
	 * {@inheritDoc}
32
	 * 
33
	 * @see eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilderTest#setUp()
34
	 */
35
	@Override
36
	@Before
37
	public void setUp() {
38
		super.setUp();
39
		builder = new StandaloneCxfEndpointReferenceBuilder();
40
	}
41

  
42
	/**
43
	 * test computeAddress.
44
	 */
45
	@Test
46
	public void testGetAddress() {
47
		assertEquals("no base, http", "http://localhost/something", builder.getAddress(getEndpoint()));
48

  
49
		when(getEndpointInfo().getAddress()).thenReturn("/localPath");
50
		assertEquals("no base, no http", "/localPath", builder.getAddress(getEndpoint()));
51

  
52
		builder.setBaseAddress("http://somebase");
53
		assertEquals("base, no http", "http://somebase/localPath", builder.getAddress(getEndpoint()));
54
	}
55

  
56
	/**
57
	 * make code coverage happy.
58
	 */
59
	@Test
60
	public void testGetBaseAddress() {
61
		builder.setBaseAddress(HTTP_TEST_COM);
62
		assertEquals("testing setter", HTTP_TEST_COM, builder.getBaseAddress());
63
	}
64

  
65
	/**
66
	 * make code coverage happy.
67
	 */
68
	@Test
69
	public void testSetBaseAddress() {
70
		builder.setBaseAddress(HTTP_TEST_COM);
71
		assertEquals("testing setter", HTTP_TEST_COM, builder.getBaseAddress());
72
	}
73

  
74
}
modules/cnr-service-utils/trunk/src/test/java/eu/dnetlib/soap/cxf/CxfEndpointReferenceBuilderTest.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import static org.junit.Assert.assertTrue;
4
import static org.mockito.Mockito.when;
5

  
6
import java.util.HashMap;
7

  
8
import javax.xml.namespace.QName;
9
import javax.xml.ws.EndpointReference;
10

  
11
import org.apache.cxf.endpoint.Endpoint;
12
import org.apache.cxf.service.Service;
13
import org.apache.cxf.service.model.EndpointInfo;
14
import org.junit.Before;
15
import org.junit.Test;
16
import org.junit.runner.RunWith;
17
import org.mockito.Mock;
18
import org.mockito.runners.MockitoJUnit44Runner;
19

  
20
/**
21
 * test the CxfEndpointReferenceBuilder.
22
 *
23
 * @author marko
24
 *
25
 */
26
@RunWith(MockitoJUnit44Runner.class)
27
public class CxfEndpointReferenceBuilderTest {
28

  
29
	/**
30
	 * service mock.
31
	 */
32
	@Mock
33
	private Service service;
34

  
35
	/**
36
	 * endpoint info mock.
37
	 */
38
	@Mock
39
	private EndpointInfo endpointInfo;
40

  
41
	/**
42
	 * endpoint mock.
43
	 */
44
	@Mock
45
	private Endpoint endpoint;
46

  
47
	/**
48
	 * object under test.
49
	 */
50
	private CxfEndpointReferenceBuilder builder;
51

  
52
	/**
53
	 * initialize object under test and prepare a commmon endpoint mock.
54
	 */
55
	@Before
56
	public void setUp() {
57
		builder = new CxfEndpointReferenceBuilder();
58
		when(service.getName()).thenReturn(new QName("http://my.test", "TestService"));
59

  
60
		when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
61
		when(endpoint.getService()).thenReturn(service);
62
		when(endpointInfo.getAddress()).thenReturn("http://localhost/something");
63
		when(endpointInfo.getName()).thenReturn(new QName("http://my.test", "TestServiceEndpoint"));
64
	}
65

  
66
	/**
67
	 * test.
68
	 */
69
	@Test
70
	public void testGetEndpointReference() {
71

  
72
		final EndpointReference epr = builder.getEndpointReference(endpoint);
73
		assertTrue("check serialization", epr.toString().contains("TestServiceEndpoint"));
74
		assertTrue("check serialization", epr.toString().contains("http://localhost/something"));
75
		assertTrue("check serialization", epr.toString().contains("http://my.test"));
76

  
77
	}
78

  
79
	/**
80
	 * test method.
81
	 */
82
	@Test
83
	public void testGetEndpointReferenceMetadata() {
84
		final HashMap<String, Object> defaultMetadata = new HashMap<String, Object>();
85
		defaultMetadata.put("{http://someuri}somename", "somevalue");
86
		builder.setDefaultMetadata(defaultMetadata);
87

  
88
		final EndpointReference epr = builder.getEndpointReference(endpoint);
89
		
90
		assertTrue("check serialization", epr.toString().contains("somename:somename xmlns=\"http://someuri\""));
91
		assertTrue("check serialization", epr.toString().contains("xmlns:somename=\"http://someuri\""));		
92
		assertTrue("check serialization", epr.toString().contains("somevalue"));
93
	}
94

  
95
	protected Service getService() {
96
		return service;
97
	}
98

  
99
	protected void setService(final Service service) {
100
		this.service = service;
101
	}
102

  
103
	protected EndpointInfo getEndpointInfo() {
104
		return endpointInfo;
105
	}
106

  
107
	protected void setEndpointInfo(final EndpointInfo endpointInfo) {
108
		this.endpointInfo = endpointInfo;
109
	}
110

  
111
	protected Endpoint getEndpoint() {
112
		return endpoint;
113
	}
114

  
115
	protected void setEndpoint(final Endpoint endpoint) {
116
		this.endpoint = endpoint;
117
	}
118

  
119
	protected CxfEndpointReferenceBuilder getBuilder() {
120
		return builder;
121
	}
122

  
123
	protected void setBuilder(final CxfEndpointReferenceBuilder builder) {
124
		this.builder = builder;
125
	}
126
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/LocalServiceResolverImpl.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.io.StringReader;
4
import java.util.Map;
5

  
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7
import javax.xml.xpath.XPathExpressionException;
8
import javax.xml.xpath.XPathFactory;
9

  
10
import org.apache.commons.logging.Log;
11
import org.apache.commons.logging.LogFactory;
12
import org.springframework.context.ApplicationContext;
13
import org.springframework.context.ApplicationContextAware;
14
import org.xml.sax.InputSource;
15

  
16
/**
17
 * This service resolver parses the EPR and returns a local reference to a service instance if the EPR refers to the
18
 * local node.
19
 * 
20
 * @author marko
21
 * 
22
 */
23
public class LocalServiceResolverImpl extends AbstractServiceResolverImpl implements ServiceResolver, ApplicationContextAware {
24
	private static final Log log = LogFactory.getLog(LocalServiceResolverImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
25

  
26
	private String baseAddress;
27

  
28
	private ApplicationContext applicationContext;
29

  
30
	/**
31
	 * {@inheritDoc}
32
	 * 
33
	 * @see eu.dnetlib.enabling.tools.ServiceResolver#getService(java.lang.Class,
34
	 *      javax.xml.ws.wsaddressing.W3CEndpointReference)
35
	 */
36
	@Override
37
	public <T> T getService(final Class<T> clazz, final W3CEndpointReference epr) {
38

  
39
		// backward compat
40
		if (baseAddress == null) {
41
			log.warn("please set baseAddress in " + this);
42
			return null;
43
		}
44

  
45
		try {
46
			// TODO: measure performance impact of this. I wrote it this way just to be sure of thread safety
47
			String address = XPathFactory.newInstance().newXPath().evaluate("/*[local-name() ='EndpointReference']/*[local-name() = 'Address']",
48
					new InputSource(new StringReader(epr.toString())));
49
			if (log.isDebugEnabled())
50
				log.debug("epr address " + address);
51
			
52
			if (address.startsWith(baseAddress))
53
				return resolveLocalService(clazz, epr);
54
		} catch (XPathExpressionException e) {
55
			log.warn("cannot parse epr", e);
56
		}
57

  
58
		return null;
59
	}
60

  
61
	private <T> T resolveLocalService(final Class<T> clazz, W3CEndpointReference epr) {
62
		log.info("resolving local service " + clazz);
63

  
64
		Map<String, T> services = (Map<String, T>) applicationContext.getBeansOfType(clazz, false, false);
65

  
66
		log.info("found services: " + services);
67
		if(services.size() > 0)
68
			for(T service : services.values())
69
				return service;
70

  
71
		return null;
72
	}
73

  
74
	public String getBaseAddress() {
75
		return baseAddress;
76
	}
77

  
78
	public void setBaseAddress(String baseAddress) {
79
		this.baseAddress = baseAddress;
80
	}
81

  
82
	public ApplicationContext getApplicationContext() {
83
		return applicationContext;
84
	}
85

  
86
	@Override
87
	public void setApplicationContext(ApplicationContext applicationContext) {
88
		this.applicationContext = applicationContext;
89
	}
90

  
91
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/UniqueIdentifierGenerator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * genrate unique identifiers.
5
 * 
6
 * @author marko
7
 *
8
 */
9
public interface UniqueIdentifierGenerator {
10

  
11
	/**
12
	 * generate a new unique identifier.
13
	 * 
14
	 * @return string identifier
15
	 */
16
	String generateIdentifier();
17
	
18
	/**
19
	 * helps identify valid identifiers.
20
	 * 
21
	 * @return string regex
22
	 */
23
	String getRegEx();
24

  
25
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/JaxwsServiceResolverImpl.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import javax.xml.ws.WebServiceFeature;
4
import javax.xml.ws.wsaddressing.W3CEndpointReference;
5

  
6
/**
7
 * This service resolver asks jaxws to obtain a proxy to a remote service.
8
 *   
9
 * @author marko
10
 *
11
 */
12
public class JaxwsServiceResolverImpl extends AbstractServiceResolverImpl implements ServiceResolver {
13

  
14
	/** 
15
	 * {@inheritDoc}
16
	 * @see eu.dnetlib.enabling.tools.ServiceResolver#getService(java.lang.Class, javax.xml.ws.wsaddressing.W3CEndpointReference)
17
	 */
18
	@Override
19
	public <T> T getService(final Class<T> clazz, final W3CEndpointReference epr) {
20
		synchronized(this) {
21
			return epr.getPort(clazz, new WebServiceFeature[] {});
22
		}
23
	}
24

  
25
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/ServiceResolver.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import javax.xml.ws.wsaddressing.W3CEndpointReference;
4

  
5
/**
6
 * Instances of this type resolve EPR references to service endpoints.
7
 * 
8
 * @author marko
9
 * 
10
 */
11
public interface ServiceResolver {
12
	/**
13
	 * return a service client given an EPR instance.
14
	 * 
15
	 * @param <T>
16
	 *            the service type
17
	 * @param clazz
18
	 *            needed for type inference of type parameter <T>
19
	 * @param epr
20
	 *            EPR
21
	 * @return a service client reference
22
	 */
23
	<T> T getService(Class<T> clazz, W3CEndpointReference epr);
24

  
25
	/**
26
	 * Extract the resource identifier embedded in the EPR.
27
	 * 
28
	 * @param epr end point reference
29
	 * @return resource identifier
30
	 */
31
	String getResourceIdentifier(W3CEndpointReference epr);
32
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/UniqueIdentifierGeneratorImpl.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.util.UUID;
4

  
5
/**
6
 * generates unique UUID identifiers.
7
 * 
8
 * @author marko
9
 * 
10
 */
11
public class UniqueIdentifierGeneratorImpl implements UniqueIdentifierGenerator {
12

  
13
	/**
14
	 * helps identify valid identifiers.
15
	 */
16
	public static final String UUID_REGEX = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
17
	
18
	/**
19
	 * prefixes all identifiers with this string.
20
	 */
21
	private String prefix = "";
22

  
23
	/**
24
	 * create a new instance with an empty prefix.
25
	 */
26
	public UniqueIdentifierGeneratorImpl() {
27
		//
28
	}
29

  
30
	/**
31
	 * construct a new instance with a given prefix.
32
	 * 
33
	 * @param prefix prefix
34
	 */
35
	public UniqueIdentifierGeneratorImpl(final String prefix) {
36
		this.prefix = prefix;
37
	}
38

  
39
	public String getPrefix() {
40
		return prefix;
41
	}
42

  
43
	public void setPrefix(final String prefix) {
44
		this.prefix = prefix;
45
	}
46

  
47
	/**
48
	 * {@inheritDoc}
49
	 * 
50
	 * @see eu.dnetlib.enabling.tools.UniqueIdentifierGenerator#generateIdentifier()
51
	 */
52
	@Override
53
	public String generateIdentifier() {
54
		return prefix + createUUID();
55
	}
56

  
57
	/**
58
	 * the real job of creating the uuid is here.
59
	 * 
60
	 * @return new uuid
61
	 */
62
	private String createUUID() {
63
		return UUID.randomUUID().toString();
64
	}
65

  
66
	/** 
67
	 * {@inheritDoc}
68
	 * @see eu.dnetlib.enabling.tools.UniqueIdentifierGenerator#getRegEx()
69
	 */
70
	@Override
71
	public String getRegEx() {
72
		return UUID_REGEX;
73
	}
74
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/AbstractServiceResolverImpl.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import javax.xml.transform.dom.DOMResult;
4
import javax.xml.ws.wsaddressing.W3CEndpointReference;
5
import javax.xml.xpath.XPathExpressionException;
6
import javax.xml.xpath.XPathFactory;
7

  
8
/**
9
 * implement common functionality of ServiceResolvers.
10
 * 
11
 * @author marko
12
 *
13
 */
14
public abstract class AbstractServiceResolverImpl implements ServiceResolver {
15
	
16
	/** 
17
	 * {@inheritDoc}
18
	 * @see eu.dnetlib.enabling.tools.ServiceResolver#getResourceIdentifier(javax.xml.ws.wsaddressing.W3CEndpointReference)
19
	 */
20
	@Override
21
	public String getResourceIdentifier(final W3CEndpointReference epr) {
22
		final DOMResult dom = new DOMResult();
23
		epr.writeTo(dom);
24

  
25
		try {
26
			return XPathFactory.newInstance().newXPath().evaluate("//*[local-name() = 'ResourceIdentifier']", dom.getNode());
27
		} catch (XPathExpressionException e) {
28
			throw new IllegalStateException("cannot construct xpath expression", e);
29
		} 
30
	}
31

  
32
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/ResourceIdentifierResolver.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * Resource identifiers may carry, implicitly or explicity, some informations about the location of the resource in the
5
 * hierarchical xmldb namespace.
6
 * 
7
 * Implementors of this interface may take different approachs to the problem.
8
 * 
9
 * @author marko
10
 * 
11
 */
12
public interface ResourceIdentifierResolver {
13
	/**
14
	 * get the xmldb filename associated to this resource identifier, usually extracted from the identifier itself.
15
	 * 
16
	 * @param resId resource identifier
17
	 * @return xmldb file name
18
	 */
19
	String getFileName(String resId);
20

  
21
	/**
22
	 * get the xmldb collection name associated to this resource identifier.
23
	 * Implementors may decide to encode it in the identifier itself or use a secondary associative memory.
24
	 * to quickly transform identifiers.
25
	 * 
26
	 * @param resId resource identifier
27
	 * @return xmldb collection name
28
	 */
29
	String getCollectionName(String resId);
30
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/enabling/tools/ResourceLoaderHelper.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import org.springframework.context.ResourceLoaderAware;
4
import org.springframework.core.io.ResourceLoader;
5
import org.springframework.core.io.support.ResourcePatternResolver;
6
import org.springframework.core.io.support.ResourcePatternUtils;
7

  
8
/**
9
 * Some beans aren't directly instantiated (like quartz jobs for instance), so they cannot receive the resource loader
10
 * by implementing the ResourceLoaderAware interface.
11
 * 
12
 * This class is a temporary solution to this problem until we find a way to obtain a bean reference to the
13
 * application context (the actual resource loader) itself and inject it directly. It could be done by turning this
14
 * class into a bean factory and expose the resource loader through it.   
15
 * 
16
 * @author marko
17
 *
18
 */
19
public class ResourceLoaderHelper implements ResourceLoaderAware {
20

  
21
	/**
22
	 * injected resource loader.
23
	 */
24
	private ResourceLoader resourceLoader;
25

  
26
	/**
27
	 * obtain a resource pattern resolver for a given resource loader.
28
	 * 
29
	 * @return pattern resolver
30
	 */
31
	public ResourcePatternResolver getResourcePatternResolver() {
32
		return ResourcePatternUtils.getResourcePatternResolver(getResourceLoader());
33
	}
34
	
35
	public ResourceLoader getResourceLoader() {
36
		return resourceLoader;
37
	}
38

  
39
	@Override
40
	public void setResourceLoader(final ResourceLoader resourceLoader) {
41
		this.resourceLoader = resourceLoader;
42
	}
43
	
44
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/cxf/StandaloneCxfEndpointReferenceBuilder.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import java.net.URI;
4
import java.net.URISyntaxException;
5

  
6
import javax.annotation.PostConstruct;
7

  
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.apache.cxf.endpoint.Endpoint;
11
import org.springframework.beans.factory.annotation.Required;
12

  
13
/**
14
 * CxfEndpointReferenceBuilder is not able to create correct endpoint addresses outside a http request context. This means that service
15
 * initialization code cannot obtain the service address and thus cannot register himself.
16
 * 
17
 * This subclass allows putting a local address (ip/dns + port) to be used when the runtime servlet context is not available.
18
 * 
19
 * TODO: automated tomcat port detection, trough org.apache.catalina.ServerFactory.getServer().getServices() TODO: automated jetty port
20
 * detection
21
 * 
22
 * 
23
 * @author marko
24
 * 
25
 */
26
public class StandaloneCxfEndpointReferenceBuilder extends CxfEndpointReferenceBuilder {
27

  
28
	private static final Log log = LogFactory.getLog(StandaloneCxfEndpointReferenceBuilder.class); // NOPMD by marko on 11/24/08 5:02 PM
29

  
30
	/**
31
	 * base url where all services are exported.
32
	 */
33
	private String baseAddress;
34

  
35
	private String absoluteBase;
36

  
37
	private boolean forceLocalAddress = false;
38

  
39
	public String getBaseAddress() {
40
		return baseAddress;
41
	}
42

  
43
	public void setBaseAddress(final String baseAddress) {
44
		this.baseAddress = baseAddress;
45
	}
46

  
47
	@PostConstruct
48
	public void init() throws URISyntaxException {
49
		URI base = new URI(baseAddress);
50
		log.info("base address: " + baseAddress);
51

  
52
		this.absoluteBase = (new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), null, null, null)).toString().trim();
53
		log.info("absolute base address: " + absoluteBase);
54
	}
55

  
56
	/**
57
	 * {@inheritDoc}
58
	 * 
59
	 * @see eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder#getAddress(org.apache.cxf.endpoint.Endpoint)
60
	 */
61
	@Override
62
	public String getAddress(final Endpoint endpoint) {
63
		final String address = super.getAddress(endpoint);
64

  
65
		if (forceLocalAddress) {
66
			try {
67
				URI uri = new URI(address);
68
				if (!address.startsWith("http://")) {
69
					String res = baseAddress + uri.getPath();
70
					if (log.isDebugEnabled()) {
71
						log.debug("fixing address to: " + res);
72
					}
73
					return res;
74
				}
75
				String res = absoluteBase + uri.getPath();
76
				if (log.isDebugEnabled()) {
77
					log.debug("forcing address to: " + res);
78
				}
79
				return res;
80
			} catch (URISyntaxException e) {
81
				throw new IllegalArgumentException(e);
82
			}
83
		}
84

  
85
		if (!address.startsWith("http://") && (baseAddress != null)) { return baseAddress + address; }
86
		return address;
87
	}
88

  
89
	public boolean isForceLocalAddress() {
90
		return forceLocalAddress;
91
	}
92

  
93
	@Required
94
	public void setForceLocalAddress(final boolean forceLocalAddress) {
95
		this.forceLocalAddress = forceLocalAddress;
96
	}
97
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/cxf/JaxwsEndpointReferenceBuilder.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import java.util.Map;
4

  
5
import javax.xml.namespace.QName;
6
import javax.xml.ws.Endpoint;
7
import javax.xml.ws.wsaddressing.W3CEndpointReference;
8

  
9
import org.apache.cxf.jaxws.EndpointImpl;
10
import org.springframework.beans.factory.annotation.Required;
11

  
12
import eu.dnetlib.soap.AbstractEndpointReferenceBuilder;
13

  
14
/**
15
 * This EndpointReferenceBuilder implementation takes a jaxws endpoint and extracts the cxf endpoint from it.
16
 *
17
 * jaxws endpoints are the most readily available endpoint objects since they constructed from jaxws:endpoint spring
18
 * beans, as shown in the CXF documentation.
19
 *
20
 * Since this implementation forwards the job to CxfEndpointReferenceBuilder, the 'builder' property has to be set:
21
 *
22
 * <pre>
23
 * &lt;bean name=&quot;jaxwsEndpointReferenceBuilder&quot; class=&quot;eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder&quot;
24
 *   p:builder-ref=&quot;cxfEndpointReferenceBuilder&quot; /&gt;
25
 * </pre>
26
 *
27
 * @author marko
28
 * @see CxfEndpointReferenceBuilder
29
 *
30
 */
31
public class JaxwsEndpointReferenceBuilder extends AbstractEndpointReferenceBuilder<Endpoint> {
32

  
33
	/**
34
	 * required reference to the cxf endpoint builder.
35
	 */
36
	private CxfEndpointReferenceBuilder builder = null;
37

  
38
	/**
39
	 * simply unpacks the cxf endpoint from the jaxws endpoint and forwards it to CxfEndpointReferenceBuilder.
40
	 *
41
	 * {@inheritDoc}
42
	 *
43
	 * @see eu.dnetlib.soap.EndpointReferenceBuilder#getEndpointReference(java.lang.Object, java.util.Map)
44
	 */
45
	@Override
46
	public W3CEndpointReference getEndpointReference(final Endpoint endpoint, final String referenceParam, final Map<QName, Object> attrs) {
47
		return builder.getEndpointReference(((EndpointImpl) endpoint).getServer().getEndpoint(), referenceParam, attrs);
48
	}
49

  
50
	public CxfEndpointReferenceBuilder getBuilder() {
51
		return builder;
52
	}
53

  
54
	@Required
55
	public void setBuilder(final CxfEndpointReferenceBuilder builder) {
56
		this.builder = builder;
57
	}
58

  
59
	@Override
60
	public String getAddress(Endpoint endpoint) {
61
		return builder.getAddress(((EndpointImpl) endpoint).getServer().getEndpoint());
62
	}
63

  
64
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/cxf/CxfEndpointReferenceBuilder.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Map.Entry;
6

  
7
import javax.xml.namespace.QName;
8
import javax.xml.parsers.DocumentBuilderFactory;
9
import javax.xml.parsers.ParserConfigurationException;
10
import javax.xml.ws.wsaddressing.W3CEndpointReference;
11
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
12

  
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15
import org.apache.cxf.endpoint.Endpoint;
16
import org.apache.oro.text.perl.Perl5Util;
17
import org.w3c.dom.Document;
18
import org.w3c.dom.Element;
19

  
20
import eu.dnetlib.soap.AbstractEndpointReferenceBuilder;
21

  
22
/**
23
 * The cxf endpoint is an internal cross-toolkit implementation of the messaging endpoint.
24
 *
25
 * <p>
26
 * End users will normally access jaxws endpoints, since jaxws is the mostly used cxf frontend. However, generic code,
27
 * like interceptors, will handle cxf endpoints, so sometimes you may need to construct endpoint references from them.
28
 * </p>
29
 *
30
 * <pre>
31
 * &lt;ns3:Address&gt;http://localhost:8090/app/services/isStore&lt;/ns3:Address&gt;
32
 * &lt;ns3:ReferenceParameters/&gt;
33
 * &lt;ns3:Metadata&gt;
34
 *   &lt;wsaw:InterfaceName&gt;ns1:ISStoreService&lt;/wsaw:InterfaceName&gt;
35
 *   &lt;wsaw:ServiceName EndpointName=&quot;ISStoreServicePort&quot;&gt;ns2:ISStoreServiceService&lt;/wsaw:ServiceName&gt;
36
 *   &lt;infrastructure:infrastructure&gt;development&lt;/infrastructure:infrastructure&gt;
37
 * &lt;/ns3:Metadata&gt;
38
 * </pre>
39
 *
40
 * Users can easily define default system or service wide custom metadata to endpoint references by setting a
41
 * defaultMetadata property:
42
 *
43
 * <pre>
44
 * &lt;bean name=&quot;cxfEndpointReferenceBuilder&quot; class=&quot;eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilder&quot;&gt;
45
 *  &lt;property name=&quot;defaultMetadata&quot;&gt;
46
 *   &lt;map&gt;
47
 *    &lt;entry key=&quot;{http://dnetlib.eu/endpointReference}infrastructure&quot; value=&quot;${infrastructure.name}&quot; /&gt;
48
 *   &lt;/map&gt;
49
 *  &lt;/property&gt;
50
 * &lt;/bean&gt;
51
 * </pre>
52
 *
53
 *
54
 * @author marko
55
 *
56
 */
57
public class CxfEndpointReferenceBuilder extends AbstractEndpointReferenceBuilder<Endpoint> {
58
	/**
59
	 * logger.
60
	 */
61
	private static final Log log = LogFactory.getLog(CxfEndpointReferenceBuilder.class); // NOPMD by marko on 11/24/08 4:55
62

  
63
	/**
64
	 * users can put some default metadata elements into all EPRs.
65
	 */
66
	private Map<String, Object> defaultMetadata;
67

  
68
	/**
69
	 * regexp utility.
70
	 */
71
	private final transient Perl5Util matcher = new Perl5Util();
72

  
73
	/**
74
	 * namespace of the ResourceIdentifier reference parameter.
75
	 */
76
	private String riNamespace = "http://www.driver.org";
77

  
78
	/**
79
	 * element name of the ResourceIdentifier reference parameter.
80
	 */
81
	private String riElementName = "ResourceIdentifier";
82

  
83
	/**
84
	 * {@inheritDoc}
85
	 *
86
	 * TODO: refactor.
87
	 *
88
	 * @see eu.dnetlib.soap.EndpointReferenceBuilder#getEndpointReference(java.lang.Object, java.util.Map)
89
	 */
90

  
91
	@Override
92
	public W3CEndpointReference getEndpointReference(final Endpoint endpoint, final String referenceParam, final Map<QName, Object> attributes) {
93
		final String address = getAddress(endpoint);
94
		return getEndpointReference(address, endpoint.getService().getName(), endpoint.getEndpointInfo().getName(), null, referenceParam,
95
				attributes);
96
	}
97

  
98
	/**
99
	 * low level method which allows the construction of a endpoint reference knowing all basic data as the address, service name etc.
100
	 *
101
	 * @param address
102
	 * @param serviceName
103
	 * @param endpointName
104
	 * @param wsdl
105
	 * @param referenceParam
106
	 * @param attributes
107
	 * @return
108
	 */
109
	public W3CEndpointReference getEndpointReference(
110
			final String address,
111
			final QName serviceName,
112
			final QName endpointName,
113
			final String wsdl,
114
			final String referenceParam,
115
			final Map<QName, Object> attributes) {
116
		Map<QName, Object> attrs = attributes;
117

  
118
		final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
119
		builder.address(address);
120
		if(serviceName != null)
121
			builder.serviceName(serviceName);
122
		if(endpointName != null)
123
			builder.endpointName(endpointName);
124
		builder.wsdlDocumentLocation(wsdl);
125

  
126
		if (defaultMetadata != null) {
127
			if (attrs == null)
128
				attrs = new HashMap<QName, Object>();
129
			for (Entry<String, Object> entry : defaultMetadata.entrySet())
130
				attrs.put(splitQNameString(entry.getKey()), entry.getValue());
131
		}
132

  
133
		try {
134
			final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); // NOPMD
135
			if (referenceParam != null) {
136
				final Element referenceElement = doc.createElementNS(getRiNamespace(), getRiElementName());
137
				referenceElement.setTextContent(referenceParam);
138
				builder.referenceParameter(referenceElement);
139
			}
140

  
141
			if (attrs != null && !attrs.isEmpty()) {
142
				for (Entry<QName, Object> entry : attrs.entrySet()) {
143
					final QName qname = entry.getKey();
144
					final Element element = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
145
					element.setTextContent((String) entry.getValue());
146
					builder.metadata(element);
147
				}
148
			}
149
		} catch (ParserConfigurationException e) {
150
			log.fatal("cannot extend EPR", e);
151
			throw new IllegalStateException("cannot extend EPR", e);
152
		}
153

  
154
		return builder.build();
155
	}
156

  
157
	/**
158
	 * compute an endpoint address.
159
	 *
160
	 * @param endpoint
161
	 *            endpoint
162
	 * @return url as string
163
	 */
164
	@Override
165
	public String getAddress(final Endpoint endpoint) {
166
		return endpoint.getEndpointInfo().getAddress();
167
	}
168

  
169
	/**
170
	 * helper method for converting "{namespace}elementName" strings to QNames.
171
	 *
172
	 * @param key
173
	 *            "{namespace}elementName" string
174
	 * @return qname
175
	 */
176
	private QName splitQNameString(final String key) {
177
		matcher.match("m/{(.*)}(.*)/", key);
178

  
179
		return new QName(matcher.group(1), matcher.group(2));
180
	}
181

  
182
	public Map<String, Object> getDefaultMetadata() {
183
		return defaultMetadata;
184
	}
185

  
186
	public void setDefaultMetadata(final Map<String, Object> defaultMetadata) {
187
		this.defaultMetadata = defaultMetadata;
188
	}
189

  
190
	public String getRiNamespace() {
191
		return riNamespace;
192
	}
193

  
194
	public void setRiNamespace(final String riNamespace) {
195
		this.riNamespace = riNamespace;
196
	}
197

  
198
	public String getRiElementName() {
199
		return riElementName;
200
	}
201

  
202
	public void setRiElementName(final String riElementName) {
203
		this.riElementName = riElementName;
204
	}
205

  
206
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/EndpointReferenceBuilder.java
1
package eu.dnetlib.soap;
2

  
3
import java.util.Map;
4

  
5
import javax.xml.namespace.QName;
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7

  
8
/**
9
 * This is a generalization of org.apache.cxf.jaxws.EndpointReferenceBuilder and org.apache.cxf.jaxws.EndpointImpl
10
 *
11
 * <p>
12
 * javax.xml.ws.WebServiceContext org.apache.cxf.jaxws.EndpointReferenceBuilder doesn't expose the API for adding
13
 * additional metadata while org.apache.cxf.jaxws.EndpointImpl doesn't take the correct endpoint address from the
14
 * EndpointInfo object. org.apache.cxf.endpoint.Endpoint return a CXF proprietary endpoint reference and not the
15
 * javax/w3c standard definition.
16
 * </p>
17
 *
18
 * <p>
19
 * This interface is intended to provide an abstract way to construct an endpoint reference for a given service,
20
 * depending on the type of endpoint interface you have at hand (CXF abstract endpoint or jaxws endpoint)
21
 * </p>
22
 *
23
 * <p>
24
 * Normally the type parameter T will be bound to your endpoint type.
25
 * </p>
26
 *
27
 * <p>
28
 * In CXF jaxws applications you can easly get a WebServiceContext instance which returns an EndpointReference, however
29
 * the API is cumbersome because it requires instantiating w3c DOM Element instances for each reference parameter, and
30
 * it doesn't allow setting custom metadata elements.
31
 * </p>
32
 *
33
 * <p>
34
 * Implementors of this API will extract as many useful informations from the runtime besides the plain soap endpoint
35
 * address.
36
 * </p>
37
 *
38
 * @author marko
39
 * @param <T>
40
 *            all endpoint builders are parameterized to specific endpoint type which on the used framework (not on the
41
 *            service)
42
 *
43
 */
44
public interface EndpointReferenceBuilder<T> {
45
	/**
46
	 * get an endpoint reference with default metadata attached.
47
	 *
48
	 * @param endpoint
49
	 *            the endpoint
50
	 * @return an endpoint reference
51
	 */
52
	W3CEndpointReference getEndpointReference(T endpoint);
53

  
54
	/**
55
	 * get an endpoint reference with custom metadata attached.
56
	 *
57
	 * @param endpoint
58
	 *            the endpoint
59
	 * @param attrs
60
	 *            metadata attribute map
61
	 * @return an endpoint reference
62
	 */
63
	W3CEndpointReference getEndpointReference(T endpoint, Map<QName, Object> attrs);
64

  
65
	/**
66
	 * get an endpoint reference with a WSA reference parameter.
67
	 *
68
	 * @param endpoint
69
	 *            the endpoint
70
	 * @param referenceParam
71
	 *            reference parameters
72
	 * @return an endpoint reference
73
	 */
74
	W3CEndpointReference getEndpointReference(T endpoint, String referenceParam);
75

  
76
	/**
77
	 * get an endpoint reference with custom metadata attached and WSA reference parameter.
78
	 *
79
	 * @param endpoint
80
	 *            endpoint
81
	 * @param referenceParam
82
	 *            reference parameters
83
	 * @param attrs
84
	 *            metadata attribute map
85
	 * @return an endpoint reference
86
	 */
87
	W3CEndpointReference getEndpointReference(T endpoint, String referenceParam, Map<QName, Object> attrs);
88

  
89
	/**
90
	 * Sometimes we need only the address.
91
	 *
92
	 * @param endpoint endpoint
93
	 * @return address
94
	 */
95
	String getAddress(T endpoint);
96
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/AbstractEndpointReferenceBuilder.java
1
package eu.dnetlib.soap;
2

  
3
import java.util.Map;
4

  
5
import javax.xml.namespace.QName;
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7

  
8
/**
9
 *
10
 * default implementation short methods.
11
 *
12
 * @author marko
13
 *
14
 * @param <T>
15
 */
16
public abstract class AbstractEndpointReferenceBuilder<T> implements EndpointReferenceBuilder<T> {
17

  
18
	/**
19
	 * {@inheritDoc}
20
	 *
21
	 * @see eu.dnetlib.soap.EndpointReferenceBuilder#getEndpointReference(java.lang.Object)
22
	 */
23
	@Override
24
	public W3CEndpointReference getEndpointReference(final T endpoint) {
25
		return getEndpointReference(endpoint, (Map<QName, Object>)null);
26
	}
27

  
28
	/**
29
	 * {@inheritDoc}
30
	 * @see eu.dnetlib.soap.EndpointReferenceBuilder#getEndpointReference(java.lang.Object, java.lang.String)
31
	 */
32
	@Override
33
	public W3CEndpointReference getEndpointReference(final T endpoint, final String referenceParam) {
34
		return getEndpointReference(endpoint, referenceParam, null);
35
	}
36

  
37
	/**
38
	 * {@inheritDoc}
39
	 * @see eu.dnetlib.soap.EndpointReferenceBuilder#getEndpointReference(java.lang.Object, java.util.Map)
40
	 */
41
	@Override
42
	public W3CEndpointReference getEndpointReference(final T endpoint, final Map<QName, Object> attrs) {
43
		return getEndpointReference(endpoint, null, attrs);
44
	}
45

  
46
}
modules/cnr-service-utils/trunk/src/main/java/eu/dnetlib/soap/StaticEndpointReferenceBuilder.java
1
package eu.dnetlib.soap;
2

  
3
import java.util.Map;
4

  
5
import javax.xml.namespace.QName;
6
import javax.xml.ws.wsaddressing.W3CEndpointReference;
7
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
8

  
9
/**
10
 * This endpoint reference builder builds always the same epr, with a fixed address, for any incoming endpoint (even
11
 * null endpoints). Useful when registering service profiles for external services like the old perl Aggregator.
12
 *
13
 * @author marko
14
 *
15
 * @param <T>
16
 *            endpoint type
17
 */
18
public class StaticEndpointReferenceBuilder<T> implements EndpointReferenceBuilder<T> {
19

  
20
	/**
21
	 * service address.
22
	 */
23
	private String address;
24

  
25
	@Override
26
	public String getAddress(final T endpoint) {
27
		return address;
28
	}
29

  
30
	@Override
31
	public W3CEndpointReference getEndpointReference(final T endpoint) {
32
		final W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
33
		builder.address(address);
34
		return builder.build();
35
	}
36

  
37
	@Override
38
	public W3CEndpointReference getEndpointReference(final T endpoint, final Map<QName, Object> attrs) {
39
		return getEndpointReference(endpoint);
40
	}
41

  
42
	@Override
43
	public W3CEndpointReference getEndpointReference(final T endpoint, final String referenceParam) {
44
		return getEndpointReference(endpoint);
45
	}
46

  
47
	@Override
48
	public W3CEndpointReference getEndpointReference(final T endpoint, final String referenceParam, final Map<QName, Object> attrs) {
49
		return getEndpointReference(endpoint);
50
	}
51

  
52
	public String getAddress() {
53
		return address;
54
	}
55

  
56
	public void setAddress(final String address) {
57
		this.address = address;
58
	}
59

  
60
}
modules/cnr-service-utils/trunk/src/main/resources/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.properties
1
transport.soap.force.local.address=false
modules/cnr-service-utils/trunk/src/main/resources/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
4
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
5
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
6

  
7
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8
                                    http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
9
                                    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
10
                                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
11
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
12

  
13
	<bean id="jaxwsEndpointReferenceBuilder" class="eu.dnetlib.soap.cxf.JaxwsEndpointReferenceBuilder"
14
		p:builder-ref="cxfEndpointReferenceBuilder" />
15

  
16
	<bean id="cxfEndpointReferenceBuilder"
17
		class="eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder"
18
		p:baseAddress="${transport.soap.baseAddress}"
19
		p:forceLocalAddress="${transport.soap.force.local.address}">
20
		<property name="defaultMetadata">
21
			<map>
22
				<entry key="{http://dnetlib.eu/endpointReference}infrastructure"
23
					value="${infrastructure.name}" />
24
			</map>
25
		</property>
26
	</bean>
27

  
28
</beans>
modules/cnr-service-utils/trunk/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>cnr-service-utils</artifactId>
12
	<packaging>jar</packaging>
13
	<version>1.0.2-SNAPSHOT</version>
14
	<scm>
15
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-service-utils/trunk</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>apache</groupId>
20
			<artifactId>oro</artifactId>
21
			<version>2.0.8</version>
22
		</dependency>
23
		<dependency>
24
			<groupId>org.apache.cxf</groupId>
25
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
26
			<version>${cxf.version}</version>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.springframework</groupId>
30
			<artifactId>spring-context</artifactId>
31
			<version>${spring.version}</version>
32
		</dependency>
33

  
34
		<dependency>
35
			<groupId>org.mockito</groupId>
36
			<artifactId>mockito-core</artifactId>
37
			<version>1.6</version>
38
			<scope>test</scope>
39
		</dependency>
40
		<dependency>
41
			<groupId>junit</groupId>
42
			<artifactId>junit</artifactId>
43
			<version>${junit.version}</version>
44
			<scope>test</scope>
45
		</dependency>
46

  
47
	</dependencies>
48
</project>
modules/cnr-service-utils/tags/cnr-service-utils-1.0.0/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-service-utils/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-service-utils"}
modules/cnr-service-utils/tags/cnr-service-utils-1.0.0/src/test/java/eu/dnetlib/soap/cxf/StandaloneCxfEndpointReferenceBuilderTest.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.mockito.Mockito.when;
5

  
6
import org.junit.Before;
7
import org.junit.Test;
8
import org.junit.runner.RunWith;
9
import org.mockito.runners.MockitoJUnit44Runner;
10

  
11
/**
12
 * test StandaloneCxfEndpointReferenceBuilderTest.
13
 * 
14
 * @author marko
15
 * 
16
 */
17
@RunWith(MockitoJUnit44Runner.class)
18
public class StandaloneCxfEndpointReferenceBuilderTest extends CxfEndpointReferenceBuilderTest {
19

  
20
	/**
21
	 * some constant url prefix.
22
	 */
23
	private static final String HTTP_TEST_COM = "http://test.com";
24

  
25
	/**
26
	 * class under test.
27
	 */
28
	private transient StandaloneCxfEndpointReferenceBuilder builder;
29

  
30
	/**
31
	 * {@inheritDoc}
32
	 * 
33
	 * @see eu.dnetlib.soap.cxf.CxfEndpointReferenceBuilderTest#setUp()
34
	 */
35
	@Override
36
	@Before
37
	public void setUp() {
38
		super.setUp();
39
		builder = new StandaloneCxfEndpointReferenceBuilder();
40
	}
41

  
42
	/**
43
	 * test computeAddress.
44
	 */
45
	@Test
46
	public void testGetAddress() {
47
		assertEquals("no base, http", "http://localhost/something", builder.getAddress(getEndpoint()));
48

  
49
		when(getEndpointInfo().getAddress()).thenReturn("/localPath");
50
		assertEquals("no base, no http", "/localPath", builder.getAddress(getEndpoint()));
51

  
52
		builder.setBaseAddress("http://somebase");
53
		assertEquals("base, no http", "http://somebase/localPath", builder.getAddress(getEndpoint()));
54
	}
55

  
56
	/**
57
	 * make code coverage happy.
58
	 */
59
	@Test
60
	public void testGetBaseAddress() {
61
		builder.setBaseAddress(HTTP_TEST_COM);
62
		assertEquals("testing setter", HTTP_TEST_COM, builder.getBaseAddress());
63
	}
64

  
65
	/**
66
	 * make code coverage happy.
67
	 */
68
	@Test
69
	public void testSetBaseAddress() {
70
		builder.setBaseAddress(HTTP_TEST_COM);
71
		assertEquals("testing setter", HTTP_TEST_COM, builder.getBaseAddress());
72
	}
73

  
74
}
modules/cnr-service-utils/tags/cnr-service-utils-1.0.0/src/test/java/eu/dnetlib/soap/cxf/CxfEndpointReferenceBuilderTest.java
1
package eu.dnetlib.soap.cxf;
2

  
3
import static org.junit.Assert.assertTrue;
4
import static org.mockito.Mockito.when;
5

  
6
import java.util.HashMap;
7

  
8
import javax.xml.namespace.QName;
9
import javax.xml.ws.EndpointReference;
10

  
11
import org.apache.cxf.endpoint.Endpoint;
12
import org.apache.cxf.service.Service;
13
import org.apache.cxf.service.model.EndpointInfo;
14
import org.junit.Before;
15
import org.junit.Test;
16
import org.junit.runner.RunWith;
17
import org.mockito.Mock;
18
import org.mockito.runners.MockitoJUnit44Runner;
19

  
20
/**
21
 * test the CxfEndpointReferenceBuilder.
22
 *
23
 * @author marko
24
 *
25
 */
26
@RunWith(MockitoJUnit44Runner.class)
27
public class CxfEndpointReferenceBuilderTest {
28

  
29
	/**
30
	 * service mock.
31
	 */
32
	@Mock
33
	private Service service;
34

  
35
	/**
36
	 * endpoint info mock.
37
	 */
38
	@Mock
39
	private EndpointInfo endpointInfo;
40

  
41
	/**
42
	 * endpoint mock.
43
	 */
44
	@Mock
45
	private Endpoint endpoint;
46

  
47
	/**
48
	 * object under test.
49
	 */
50
	private CxfEndpointReferenceBuilder builder;
51

  
52
	/**
53
	 * initialize object under test and prepare a commmon endpoint mock.
54
	 */
55
	@Before
56
	public void setUp() {
57
		builder = new CxfEndpointReferenceBuilder();
58
		when(service.getName()).thenReturn(new QName("http://my.test", "TestService"));
59

  
60
		when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
61
		when(endpoint.getService()).thenReturn(service);
62
		when(endpointInfo.getAddress()).thenReturn("http://localhost/something");
63
		when(endpointInfo.getName()).thenReturn(new QName("http://my.test", "TestServiceEndpoint"));
64
	}
65

  
66
	/**
67
	 * test.
68
	 */
69
	@Test
70
	public void testGetEndpointReference() {
71

  
72
		final EndpointReference epr = builder.getEndpointReference(endpoint);
73
		assertTrue("check serialization", epr.toString().contains("TestServiceEndpoint"));
74
		assertTrue("check serialization", epr.toString().contains("http://localhost/something"));
75
		assertTrue("check serialization", epr.toString().contains("http://my.test"));
76

  
77
	}
78

  
79
	/**
80
	 * test method.
81
	 */
82
	@Test
83
	public void testGetEndpointReferenceMetadata() {
84
		final HashMap<String, Object> defaultMetadata = new HashMap<String, Object>();
85
		defaultMetadata.put("{http://someuri}somename", "somevalue");
86
		builder.setDefaultMetadata(defaultMetadata);
87

  
88
		final EndpointReference epr = builder.getEndpointReference(endpoint);
89
		
90
		assertTrue("check serialization", epr.toString().contains("somename:somename xmlns=\"http://someuri\""));
91
		assertTrue("check serialization", epr.toString().contains("xmlns:somename=\"http://someuri\""));		
92
		assertTrue("check serialization", epr.toString().contains("somevalue"));
93
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff