Project

General

Profile

« Previous | Next » 

Revision 51874

[maven-release-plugin] copy for tag cnr-service-common-2.1.7

View differences:

modules/cnr-service-common/tags/cnr-service-common-2.1.7/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-service-common/trunk/", "deploy_repository": "dnet45-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/dnet45-snapshots", "name": "cnr-service-common"}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/tools/DynamicServiceEnumeratorTest.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5
import static org.junit.Assert.assertTrue;
6
import static org.mockito.Matchers.anyString;
7
import static org.mockito.Mockito.when;
8

  
9
import java.util.ArrayList;
10
import java.util.List;
11

  
12
import org.junit.Before;
13
import org.junit.Test;
14
import org.junit.runner.RunWith;
15
import org.mockito.Mock;
16
import org.mockito.junit.MockitoJUnitRunner;
17

  
18
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
19
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
20
import eu.dnetlib.enabling.tools.registration.ServiceNameResolver;
21
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder;
22

  
23
/**
24
 * Test the dynamic service enumerator.
25
 *
26
 * @author marko
27
 *
28
 */
29
@RunWith(MockitoJUnitRunner.class)
30
public class DynamicServiceEnumeratorTest {
31

  
32
	/**
33
	 * Dummy service interface.
34
	 *
35
	 * @author marko
36
	 *
37
	 */
38
	interface TestService {
39
	}
40

  
41
	/**
42
	 * instance under test.
43
	 */
44
	private transient DynamicServiceEnumerator<TestService> enumerator;
45

  
46
	/**
47
	 * lookup service locator mock
48
	 */
49
	@Mock
50
	private transient ISLookUpService lookUpService;
51

  
52
	/**
53
	 * lookup mock locator.
54
	 */
55
	private transient ServiceLocator<ISLookUpService> lookUpLocator;
56

  
57
	/**
58
	 * service name resolver mock.
59
	 */
60
	@Mock
61
	private transient ServiceNameResolver nameResolver;
62

  
63
	/**
64
	 * epr builder.
65
	 */
66
	StandaloneCxfEndpointReferenceBuilder eprBuilder;
67

  
68
	/**
69
	 * common preparation.
70
	 */
71
	@Before
72
	public void setUp()  {
73
		lookUpLocator = new StaticServiceLocator<ISLookUpService>(lookUpService);
74
		eprBuilder = new StandaloneCxfEndpointReferenceBuilder();
75

  
76
		enumerator = new DynamicServiceEnumerator<TestService>(TestService.class);
77
		enumerator.setLookUpLocator(lookUpLocator);
78
		enumerator.setServiceNameResolver(nameResolver);
79
		enumerator.setEprBuilder(eprBuilder);
80

  
81
		when(nameResolver.getName(TestService.class)).thenReturn("TestService");
82
	}
83

  
84
	/**
85
	 * test get services.
86
	 *
87
	 * @throws ISLookUpException mock exception
88
	 */
89
	@Test
90
	public void testGetServices() throws ISLookUpException {
91
		List<String> services = new ArrayList<String>();
92
		services.add("<service><id>123</id><url>http://test.com</url></service>");
93

  
94
		when(lookUpService.quickSearchProfile(anyString())).thenReturn(services);
95

  
96
		List<ServiceRunningInstance<TestService>> instances = enumerator.getServices();
97

  
98
		assertEquals("query size", 1, instances.size());
99
		assertEquals("service id", "123", instances.get(0).getServiceId());
100
		assertEquals("service url", "http://test.com", instances.get(0).getUrl());
101
		assertNotNull("service epr", instances.get(0).getEpr());
102
	}
103

  
104
	@Test
105
	public void testEmptyGetServices() throws ISLookUpException {
106
		List<String> services = new ArrayList<String>();
107
		when(lookUpService.quickSearchProfile(anyString())).thenReturn(services);
108

  
109
		List<ServiceRunningInstance<TestService>> instances = enumerator.getServices();
110
		assertTrue("empty", instances.isEmpty());
111
	}
112
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/tools/DynamicServiceLocatorTest.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import static org.junit.Assert.*; // NOPMD
4
import static org.mockito.Mockito.*; // NOPMD
5

  
6
import java.util.List;
7

  
8
import javax.xml.ws.wsaddressing.W3CEndpointReference;
9

  
10
import org.junit.Before;
11
import org.junit.Test;
12
import org.junit.runner.RunWith;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.test.context.ContextConfiguration;
15
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16

  
17
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
18
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
19
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
20

  
21
/**
22
 * Test dynamic service locator.
23
 *
24
 * @author marko
25
 *
26
 */
27
@RunWith(SpringJUnit4ClassRunner.class)
28
@ContextConfiguration
29
public class DynamicServiceLocatorTest {
30

  
31
	/**
32
	 * instance under test.
33
	 */
34
	@Autowired
35
	private transient DynamicServiceLocator<ResultSetService> serviceLocator;
36

  
37
	/**
38
	 * list of mock service profiles saved in files.
39
	 */
40

  
41
	@javax.annotation.Resource(name = "serviceProfiles")
42
	private transient List<String> serviceUris;
43

  
44
	/**
45
	 * service resolver mock.
46
	 */
47
	private transient ServiceResolver serviceResolver;
48

  
49
	/**
50
	 * setup.
51
	 *
52
	 * @throws ISLookUpException
53
	 *             mock
54
	 */
55
	@Before
56
	public void setUp() throws ISLookUpException {
57
//		final ISLookUpService lookupService = mock(ISLookUpService.class);
58
//		serviceLocator.setLookUpLocator(new StaticServiceLocator<ISLookUpService>(lookupService));
59

  
60
		serviceResolver = mock(ServiceResolver.class);
61
		serviceLocator.setServiceResolver(serviceResolver);
62

  
63
		final ISLookUpService lookupService = serviceLocator.getLookUpLocator().getService();
64
		when(lookupService.quickSearchProfile(anyString())).thenReturn(serviceUris);
65
	}
66

  
67
	/**
68
	 * test get service.
69
	 */
70
	@Test
71
	public void testGetService() {
72
		assertNull("dummy", serviceLocator.getService());
73

  
74
		verify(serviceResolver).getService(eq(ResultSetService.class), (W3CEndpointReference) anyObject());
75
	}
76

  
77
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/tools/registration/InterfaceServiceNameResolverCompatibilityTest.java
1
package eu.dnetlib.enabling.tools.registration;
2

  
3
import static org.junit.Assert.assertEquals;
4

  
5
import org.junit.Before;
6
import org.junit.Test;
7

  
8
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
9
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
10

  
11
public class InterfaceServiceNameResolverCompatibilityTest {
12

  
13
	private transient InterfaceServiceNameResolverCompatibility resolver;
14

  
15
	private interface IndexService {}
16

  
17
	private interface ISomethingService {}
18

  
19
	@Before
20
	public void setUp() throws Exception {
21
		resolver = new InterfaceServiceNameResolverCompatibility();
22
	}
23

  
24
	@Test
25
	public void testGetNameClassOfQ() {
26
		assertEquals("IndexService", resolver.getName(IndexService.class));
27
		assertEquals("SomethingService", resolver.getName(ISomethingService.class));
28
		assertEquals("ISRegistryService", resolver.getName(ISRegistryService.class));
29
		assertEquals("ResultSetService", resolver.getName(ResultSetService.class));
30
	}
31

  
32
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/locators/DefaultUniqueServiceLocatorTest.java
1
package eu.dnetlib.enabling.locators;
2

  
3
import java.util.Map;
4
import java.util.Set;
5

  
6
import com.google.common.collect.Lists;
7
import com.google.common.collect.Maps;
8
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
10
import eu.dnetlib.enabling.locators.comparators.PreferLocalRunningInstanceComparator;
11
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
12
import eu.dnetlib.enabling.tools.OpaqueResource;
13
import eu.dnetlib.enabling.tools.registration.ServiceNameResolver;
14
import eu.dnetlib.enabling.tools.registration.ServiceRegistrationManager;
15
import org.antlr.stringtemplate.StringTemplate;
16
import org.apache.commons.io.IOUtils;
17
import org.junit.Before;
18
import org.junit.Ignore;
19
import org.junit.Test;
20
import org.junit.runner.RunWith;
21
import org.mockito.Mock;
22
import org.mockito.junit.MockitoJUnitRunner;
23
import org.springframework.context.ApplicationContext;
24

  
25
import static org.junit.Assert.assertEquals;
26
import static org.junit.Assert.assertTrue;
27
import static org.mockito.Matchers.anyString;
28
import static org.mockito.Mockito.*;
29

  
30
@RunWith(MockitoJUnitRunner.class)
31
public class DefaultUniqueServiceLocatorTest {
32

  
33
	/**
34
	 * Class under test.
35
	 */
36
	private DefaultUniqueServiceLocator locator;
37

  
38
	@Mock
39
	private ISLookUpService lookupService;
40
	@Mock
41
	private ResultSetService resultsetService;
42
	@Mock
43
	private ApplicationContext appContext;
44
	@Mock
45
	private ServiceNameResolver serviceNameResolver;
46
	@Mock
47
	private ServiceRegistrationManager resultSetRegistrator;
48
	@Mock
49
	private OpaqueResource opaqueResource;
50

  
51
	private static final String SERVICE_NAME = "ResultsetService";
52

  
53
	private static final String XQUERY = "for $x in collection('/db/DRIVER/ServiceResources/" + SERVICE_NAME + "ResourceType') return $x";
54

  
55
	@Before
56
	public void setUp() throws Exception {
57
		locator = new DefaultUniqueServiceLocator();
58
		locator.setApplicationContext(appContext);
59
		locator.setDefaultComparator(new PreferLocalRunningInstanceComparator());
60
		locator.setServiceNameResolver(serviceNameResolver);
61
		locator.setIsLookupService(lookupService);
62

  
63
		final Map<String, ServiceRegistrationManager> registratorBeans = Maps.newHashMap();
64
		registratorBeans.put("resultSetRegistrator", resultSetRegistrator);
65
		final Map<String, ResultSetService> serviceBeans = Maps.newHashMap();
66
		serviceBeans.put("resultSetService", resultsetService);
67

  
68
		final StringTemplate st1 = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("serviceProfile.xml.st")));
69
		st1.setAttribute("name", SERVICE_NAME);
70
		st1.setAttribute("id", "1111");
71
		final StringTemplate st2 = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("serviceProfile.xml.st")));
72
		st2.setAttribute("name", SERVICE_NAME);
73
		st2.setAttribute("id", "2222");
74
		final StringTemplate st3 = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream("serviceProfile.xml.st")));
75
		st3.setAttribute("name", SERVICE_NAME);
76
		st3.setAttribute("id", "3333");
77

  
78
		when(serviceNameResolver.getName(ResultSetService.class)).thenReturn(SERVICE_NAME);
79
		when(lookupService.quickSearchProfile(XQUERY)).thenReturn(Lists.newArrayList(st1.toString(), st2.toString(), st3.toString()));
80
		when(lookupService.getResourceProfileByQuery(anyString())).thenReturn(st2.toString());
81
		//when(appContext.getBeansOfType(ServiceRegistrationManager.class)).thenReturn(registratorBeans);
82
		//when(appContext.getBeansOfType(ResultSetService.class)).thenReturn(serviceBeans);
83

  
84
		//when(resultSetRegistrator.getServiceProfile()).thenReturn(opaqueResource);
85
		//when(resultSetRegistrator.getService()).thenReturn(resultsetService);
86
		//when(opaqueResource.getResourceId()).thenReturn("2222");
87

  
88
	}
89

  
90
	@Test
91
	public void testGetServiceClassOfT_1() {
92
		assertEquals(lookupService, locator.getService(ISLookUpService.class));
93
	}
94

  
95
	@Test
96
	@Ignore
97
	public void testGetServiceClassOfT_2() throws ISLookUpException {
98
		assertEquals(resultsetService, locator.getService(ResultSetService.class, false));
99
		verify(lookupService, times(1)).quickSearchProfile(XQUERY);
100
	}
101

  
102
	@Test
103
	@Ignore
104
	public void testGetServiceClassOfTComparatorOfServiceRunningInstance() throws ISLookUpException {
105
		assertEquals(resultsetService, locator.getService(ResultSetService.class, new PreferLocalRunningInstanceComparator()));
106
		verify(lookupService, times(1)).quickSearchProfile(XQUERY);
107
	}
108

  
109
	@Test
110
	@Ignore
111
	public void testGetServiceClassOfTString() {
112
		assertEquals(resultsetService, locator.getService(ResultSetService.class, "rs-1234"));
113
	}
114

  
115
	@Test
116
	@Ignore
117
	public void testGetServiceClassOfTBoolean() throws ISLookUpException {
118
		assertEquals(resultsetService, locator.getService(ResultSetService.class, true));
119
		verify(lookupService, never()).quickSearchProfile(XQUERY);
120
	}
121

  
122
	@Test
123
	public void testGetServiceIdClassOfT() {
124
		assertEquals("1111", locator.getServiceId(ResultSetService.class));
125
	}
126

  
127
	@Test
128
	public void testGetServiceIdClassOfTComparatorOfServiceRunningInstance() {
129
		assertEquals("1111", locator.getServiceId(ResultSetService.class, new PreferLocalRunningInstanceComparator()));
130
	}
131

  
132
	@Test
133
	public void testGetServiceIdClassOfTString() {
134
		assertEquals("2222", locator.getServiceId(ResultSetService.class, "rs-1234"));
135
	}
136

  
137
	@Test
138
	@Ignore
139
	public void testGetAllServices() {
140
		final Set<ResultSetService> list = locator.getAllServices(ResultSetService.class);
141
		assertEquals(3, list.size());
142
		assertTrue(list.contains(resultsetService));
143
	}
144

  
145
	@Test
146
	public void testGetAllServiceIds() {
147
		final Set<String> list = locator.getAllServiceIds(ResultSetService.class);
148
		assertEquals(3, list.size());
149
		assertTrue(list.contains("1111"));
150
		assertTrue(list.contains("2222"));
151
		assertTrue(list.contains("3333"));
152
	}
153

  
154
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/locators/comparators/HandledDatastructuresComparatorTest.java
1
package eu.dnetlib.enabling.locators.comparators;
2

  
3
import static org.junit.Assert.*;
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.Mock;
10
import org.mockito.junit.MockitoJUnitRunner;
11

  
12
import eu.dnetlib.enabling.locators.ServiceRunningInstance;
13

  
14
@RunWith(MockitoJUnitRunner.class)
15
public class HandledDatastructuresComparatorTest {
16

  
17
	/**
18
	 * Class Under test.
19
	 */
20
	private HandledDatastructuresComparator comparator;
21
	
22
	@Mock
23
	private ServiceRunningInstance s1;
24
	@Mock
25
	private ServiceRunningInstance s2;
26
	@Mock
27
	private ServiceRunningInstance s3;
28
	
29
	@Before
30
	public void setUp() throws Exception {
31
		comparator = new HandledDatastructuresComparator();
32
		when(s1.getHandledDatastructures()).thenReturn(0);
33
		when(s2.getHandledDatastructures()).thenReturn(0);
34
		when(s3.getHandledDatastructures()).thenReturn(10);
35
	}
36

  
37
	@Test
38
	public void testCompare() {
39
		assertEquals(0, comparator.compare(s1, s2));
40
		assertEquals(-1, comparator.compare(s1, s3));
41
		assertEquals(1, comparator.compare(s3, s1));
42
	}
43

  
44
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/locators/comparators/PreferLocalRunningInstanceComparatorTest.java
1
package eu.dnetlib.enabling.locators.comparators;
2

  
3
import static org.junit.Assert.*;
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.Mock;
10

  
11
import eu.dnetlib.enabling.locators.ServiceRunningInstance;
12
import org.mockito.junit.MockitoJUnitRunner;
13

  
14
@RunWith(MockitoJUnitRunner.class)
15
public class PreferLocalRunningInstanceComparatorTest {
16

  
17
	/**
18
	 * Class Under test.
19
	 */
20
	private PreferLocalRunningInstanceComparator comparator;
21
	
22
	@Mock
23
	private ServiceRunningInstance s1;
24
	@Mock
25
	private ServiceRunningInstance s2;
26
	@Mock
27
	private ServiceRunningInstance s3;
28
	
29
	@Before
30
	public void setUp() throws Exception {
31
		comparator = new PreferLocalRunningInstanceComparator();
32
		when(s1.isLocal()).thenReturn(true);
33
		when(s2.isLocal()).thenReturn(false);
34
		when(s3.isLocal()).thenReturn(false);
35
	}
36

  
37
	@Test
38
	public void testCompare() {
39
		assertEquals(-1, comparator.compare(s1, s3));
40
		assertEquals(1, comparator.compare(s3, s1));
41
		assertEquals(0, comparator.compare(s2, s3));
42
	}
43

  
44
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/java/eu/dnetlib/enabling/locators/comparators/DiskSpaceComparatorTest.java
1
package eu.dnetlib.enabling.locators.comparators;
2

  
3
import static org.junit.Assert.*;
4

  
5
import org.junit.Before;
6
import org.junit.Test;
7
import org.junit.runner.RunWith;
8
import org.mockito.Mock;
9
import static org.mockito.Mockito.*;
10

  
11
import org.mockito.junit.MockitoJUnitRunner;
12

  
13
import eu.dnetlib.enabling.locators.ServiceRunningInstance;
14

  
15
@RunWith(MockitoJUnitRunner.class)
16
public class DiskSpaceComparatorTest {
17

  
18
	/**
19
	 * Class Under test.
20
	 */
21
	private DiskSpaceComparator comparator;
22
	
23
	@Mock
24
	private ServiceRunningInstance s1;
25
	@Mock
26
	private ServiceRunningInstance s2;
27
	@Mock
28
	private ServiceRunningInstance s3;
29
	
30
	@Before
31
	public void setUp() throws Exception {
32
		comparator = new DiskSpaceComparator();
33
		when(s1.getUsedDiskSpace()).thenReturn(0);
34
		when(s2.getUsedDiskSpace()).thenReturn(0);
35
		when(s3.getUsedDiskSpace()).thenReturn(10);
36
	}
37

  
38
	@Test
39
	public void testCompare() {
40
		assertEquals(0, comparator.compare(s1, s2));
41
		assertEquals(-1, comparator.compare(s1, s3));
42
		assertEquals(1, comparator.compare(s3, s1));
43
	}
44

  
45
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/resources/eu/dnetlib/enabling/tools/DynamicServiceLocatorTest-context.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:p="http://www.springframework.org/schema/p"
4
	xmlns:util="http://www.springframework.org/schema/util"
5
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
7

  
8
	<bean id="propertyConfigurer"
9
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
10
		<property name="properties">
11
			<props>
12
				<prop key="transport.soap.baseAddress">http://localhost:8090/app/services/
13
				</prop>
14
				<prop key="infrastructure.name">junitTest</prop>
15
				<prop key="transport.soap.force.local.address">true</prop>
16
			</props>
17
		</property>
18
	</bean>
19

  
20
	<import
21
		resource="classpath:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml" />
22

  
23
	<bean id="defaultServiceNameResolver"
24
		class="eu.dnetlib.enabling.tools.registration.InterfaceServiceNameResolver" />
25

  
26
	<bean id="serviceResolver" 
27
		class="eu.dnetlib.test.utils.MockBeanFactory" 
28
		p:clazz="eu.dnetlib.enabling.tools.ServiceResolver" />		
29

  
30
	<bean id="lookupLocator" class="eu.dnetlib.enabling.tools.StaticServiceLocator">
31
		<property name="service">
32
			<bean class="eu.dnetlib.test.utils.MockBeanFactory" p:clazz="eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService" />
33
		</property>
34
	</bean>
35
	
36
	<bean id="dynamicLocator" class="eu.dnetlib.enabling.tools.DynamicServiceLocator"
37
		p:clazz="eu.dnetlib.enabling.resultset.rmi.ResultSetService"
38
		p:lookUpLocator-ref="lookupLocator" />
39

  
40
	<util:list id="serviceProfiles">
41
		<value><![CDATA[<service><id>1234</id><url>http://localhost:1234/app/services/resultSet</url></service>]]>
42
		</value>
43
		<value><![CDATA[<service><id>1234</id><url>http://localhost:8090/otherContext/services/resultSet</url></service>]]>
44
		</value>
45
		<value><![CDATA[<service><id>1234</id><url>http://localhost:8090/app/services/resultSet</url></service>]]>
46
		</value>
47
		<value><![CDATA[<service><id>1234</id><url>http://192.168.1.12:8090/app/services/resultSet</url></service>]]>
48
		</value>
49
	</util:list>
50
</beans>
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/test/resources/eu/dnetlib/enabling/locators/serviceProfile.xml.st
1
<?xml version="1.0" encoding="UTF-8"?>
2
<RESOURCE_PROFILE>
3
    <HEADER>
4
        <RESOURCE_IDENTIFIER value="$id$"/>
5
        <RESOURCE_TYPE value="$name$ResourceType"/>
6
        <RESOURCE_KIND value="ServiceResources"/>
7
        <RESOURCE_URI value="http://localhost:8280/is/services/$name$?wsdl"/>
8
        <PARENT_ID value="" type="HNM"/>
9
        <DATE_OF_CREATION value="2014-11-04T19:34:56+01:00"/>
10
        <PROTOCOLS>
11
            <PROTOCOL name="SOAP" address="http://localhost:8280/is/services/$name$"/>
12
        </PROTOCOLS>
13
    </HEADER>
14
    <BODY>
15
        <CONFIGURATION>
16
            <TYPOLOGY/>
17
            <MAX_SIZE_OF_DATASTRUCTURE>0</MAX_SIZE_OF_DATASTRUCTURE>
18
            <AVAILABLE_DISKSPACE>0</AVAILABLE_DISKSPACE>
19
            <MAX_NUMBER_OF_DATASTRUCTURE>0</MAX_NUMBER_OF_DATASTRUCTURE>
20
            <SERVICE_PROPERTIES/>
21
        </CONFIGURATION>
22
        <STATUS>
23
            <HANDLED_DATASTRUCTURE>0</HANDLED_DATASTRUCTURE>
24
            <USED_DISKSPACE>0</USED_DISKSPACE>
25
            <LAST_UPDATE value="2000-01-01T00:00:00+00:00"/>
26
        </STATUS>
27
        <QOS>
28
            <AVAILABILITY/>
29
            <CAPACITY/>
30
            <RESPONSE_TIME>0</RESPONSE_TIME>
31
            <THROUGHPUT>0</THROUGHPUT>
32
        </QOS>
33
        <SECURITY_PARAMETERS/>
34
        <BLACKBOARD>
35
            <LAST_REQUEST />
36
            <LAST_RESPONSE />
37
        </BLACKBOARD>
38
    </BODY>
39
</RESOURCE_PROFILE>
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/DynamicServiceLocatorLocationScorer.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.net.MalformedURLException;
4
import java.net.URL;
5

  
6
/**
7
 * Implementors of this interface provide custom methods to assign scores to services based solely on their location.
8
 * @author marko
9
 *
10
 */
11
@Deprecated
12
public interface DynamicServiceLocatorLocationScorer {
13
	/**
14
	 * Compute the score assigned to a given service location (url).
15
	 * 
16
	 * @param url service url
17
	 * @return score (the higher the better)
18
	 * @throws MalformedURLException could happen
19
	 */
20
	int score(URL url) throws MalformedURLException;
21
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/DefaultServiceLocatorLocationScorer.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.net.MalformedURLException;
4
import java.net.URL;
5

  
6
import javax.annotation.Resource;
7

  
8
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder;
9

  
10
/**
11
 * Assign better scores for near services. Can be configured.
12
 * 
13
 * @author marko
14
 *
15
 */
16
@Deprecated
17
public class DefaultServiceLocatorLocationScorer implements DynamicServiceLocatorLocationScorer {
18

  
19
	/**
20
	 * default score assigned when the other service has the same host.
21
	 */
22
	private static final int LOCAL_HOST_SCORE = 5;
23

  
24
	/**
25
	 * default score assigned when the other service has the same host and port (same container).
26
	 */
27
	private static final int LOCAL_PORT_SCORE = 10;
28

  
29
	/**
30
	 * default score assigned when the other service has the same host and port (same container and context).
31
	 */
32
	private static final int LOCAL_SRV_SCORE = 15;
33
	
34
	
35
	/**
36
	 * score assigned when the other service has the same host.
37
	 */
38
	private int localHostScore = LOCAL_HOST_SCORE;
39
	
40
	/**
41
	 * score assigned when the other service has the same host and port (same container).
42
	 */
43
	private int localPortScore = LOCAL_PORT_SCORE;
44
	
45
	/**
46
	 * score assigned when the other service has the same host and port (same container and context).
47
	 */
48
	private int localSrvScore = LOCAL_SRV_SCORE; 
49

  
50
	/**
51
	 * build epr.
52
	 */
53
	@Resource
54
	private StandaloneCxfEndpointReferenceBuilder eprBuilder;
55
	
56
	/** 
57
	 * {@inheritDoc}
58
	 * @throws MalformedURLException 
59
	 * @see eu.dnetlib.enabling.tools.DynamicServiceLocatorLocationScorer#score(java.net.URL)
60
	 */
61
	@Override
62
	public int score(final URL url) throws MalformedURLException {
63
		final URL localBase = new URL(eprBuilder.getBaseAddress());
64
		if (url.toString().startsWith(localBase.toString()))
65
			return localSrvScore;
66

  
67
		if (localBase.getHost().equals(url.getHost())) {
68
			if (localBase.getPort() == url.getPort())
69
				return localPortScore;
70
			return localHostScore;
71
		}
72
		return 0;
73
	}
74

  
75
	public StandaloneCxfEndpointReferenceBuilder getEprBuilder() {
76
		return eprBuilder;
77
	}
78

  
79
	public void setEprBuilder(final StandaloneCxfEndpointReferenceBuilder eprBuilder) {
80
		this.eprBuilder = eprBuilder;
81
	}
82

  
83
	public int getLocalHostScore() {
84
		return localHostScore;
85
	}
86

  
87
	public void setLocalHostScore(final int localHostScore) {
88
		this.localHostScore = localHostScore;
89
	}
90

  
91
	public int getLocalPortScore() {
92
		return localPortScore;
93
	}
94

  
95
	public void setLocalPortScore(final int localPortScore) {
96
		this.localPortScore = localPortScore;
97
	}
98

  
99
	public int getLocalSrvScore() {
100
		return localSrvScore;
101
	}
102

  
103
	public void setLocalSrvScore(final int localSrvScore) {
104
		this.localSrvScore = localSrvScore;
105
	}
106

  
107
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/NullHNMLocator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * simplest HNM locator: doesn't find any.
5
 * 
6
 * @author marko
7
 * 
8
 */
9
public class NullHNMLocator implements HNMLocator {
10

  
11
	/**
12
	 * {@inheritDoc}
13
	 * 
14
	 * @see eu.dnetlib.enabling.tools.HNMLocator#getHNMForUrl(java.lang.String)
15
	 */
16
	@Override
17
	public String getHNMForUrl(final String url) {
18
		return "";
19
	}
20

  
21
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/ServiceEnumerator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.util.List;
4

  
5
/**
6
 * A service enumerator returns a bunch of service descriptions. The logic depends on the service enumerator.
7
 *
8
 * @author marko
9
 *
10
 */
11
@Deprecated
12
public interface ServiceEnumerator<T> {
13
	/**
14
	 * Obtain a list of services.
15
	 *
16
	 * @return a list of service running instance descriptions
17
	 */
18
	List<ServiceRunningInstance<T>> getServices();
19
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/OpaqueResource.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.util.Date;
4

  
5
import org.w3c.dom.Document;
6

  
7
/**
8
 * Some services, in particular the enabling layer, needs to manipulate all types of resources without knowing the exact
9
 * structure of their content, but only some well defined properties defined here.
10
 * 
11
 * <p>
12
 * Different wrappers can be provided for different kind of resources. For example resources returned from the xmldb
13
 * layer can be cheaply mapped to an OpaqueResource, without going to full xml->bean conversion.
14
 * </p>
15
 * 
16
 * @author marko
17
 * 
18
 */
19
public interface OpaqueResource {
20
	/**
21
	 * Resource type.
22
	 * 
23
	 * @return resource type string
24
	 */
25
	String getResourceType();
26

  
27
	/**
28
	 * Resource kind.
29
	 * 
30
	 * @return resource kind string
31
	 */
32
	String getResourceKind();
33

  
34
	/**
35
	 * Resource identifier.
36
	 * 
37
	 * @return resource identifier string
38
	 */
39
	String getResourceId();
40
	
41
	/**
42
	 * Resource URI.
43
	 * 
44
	 * @return resource uri string
45
	 */
46
	String getResourceUri();
47
	
48
	/**
49
	 * get modification time stamp.
50
	 * 
51
	 * @return time stamp
52
	 */
53
	Date getModificationDate();
54

  
55
	/**
56
	 * Implementors may need to serialize the resource to a xml string representation.
57
	 * 
58
	 * @return xml serialization
59
	 */
60
	String asString();
61

  
62
	/**
63
	 * Implementors may store the DOM in the first place. Otherwise they should
64
	 * return a parsed w3c DOM instance.
65
	 * 
66
	 * @return DOM document
67
	 */
68
	Document asDom();
69

  
70
	/**
71
	 * change the resource identifier.
72
	 * 
73
	 * @param identifier new identifier
74
	 */
75
	void setResourceId(String identifier);
76

  
77
	/**
78
	 * change the resource kind.
79
	 * 
80
	 * @param kind new kind
81
	 */
82
	void setResourceKind(String kind);
83
	
84
	/**
85
	 * change the resource uri.
86
	 * 
87
	 * @param uri new uri
88
	 */
89
	void setResourceUri(String uri);
90
	
91
	/**
92
	 * set modification timestamp.
93
	 * 
94
	 * @param timeStamp modification time stamp
95
	 */
96
	void setModificationDate(Date timeStamp);
97

  
98
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/DOMOpaqueResource.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.io.StringWriter;
4
import java.util.Date;
5

  
6
import javax.xml.transform.Transformer;
7
import javax.xml.transform.TransformerConfigurationException;
8
import javax.xml.transform.TransformerException;
9
import javax.xml.transform.TransformerFactory;
10
import javax.xml.transform.TransformerFactoryConfigurationError;
11
import javax.xml.transform.dom.DOMSource;
12
import javax.xml.transform.stream.StreamResult;
13
import javax.xml.xpath.XPath;
14
import javax.xml.xpath.XPathConstants;
15
import javax.xml.xpath.XPathExpressionException;
16
import javax.xml.xpath.XPathFactory;
17

  
18
import org.apache.commons.logging.Log;
19
import org.apache.commons.logging.LogFactory;
20
import org.w3c.dom.Document;
21
import org.w3c.dom.Element;
22

  
23
import eu.dnetlib.miscutils.datetime.DateUtils;
24

  
25
/**
26
 * OpaqueResource holding a plain old DOM document.
27
 *
28
 * @author marko
29
 *
30
 */
31
public class DOMOpaqueResource implements OpaqueResource {
32
	/**
33
	 * xpath expression error message.
34
	 */
35
	private static final String XPATH_ERROR = "cannot compile xpath expression";
36

  
37
	/**
38
	 * value attribute.
39
	 */
40
	private static final String VALUE_ATTR = "value";
41

  
42
	/**
43
	 * logger.
44
	 */
45
	private static final Log log = LogFactory.getLog(DOMOpaqueResource.class); // NOPMD by marko on 11/24/08 5:02 PM
46

  
47
	/**
48
	 * resource identifier.
49
	 */
50
	private String resourceId;
51

  
52
	/**
53
	 * resource type.
54
	 */
55
	private String resourceType;
56

  
57
	/**
58
	 * resource kind.
59
	 */
60
	private String resourceKind;
61

  
62
	/**
63
	 * resource uri.
64
	 */
65
	private String resourceUri;
66

  
67
	/**
68
	 * modification time stamp.
69
	 */
70
	private Date modificationDate;
71

  
72
	/**
73
	 * original document DOM.
74
	 */
75
	private Document dom;
76

  
77
	/**
78
	 * xslt transformer instance.
79
	 */
80
	private Transformer transformer;
81

  
82
	/**
83
	 * construct a DOMOpaqueInstance from a W3C DOM document.
84
	 *
85
	 * @param dom
86
	 *            DOM document
87
	 * @throws XPathExpressionException
88
	 *             happens
89
	 */
90
	public DOMOpaqueResource(final Document dom) throws XPathExpressionException {
91
		this.dom = dom;
92

  
93
		try {
94
			transformer = TransformerFactory.newInstance().newTransformer();
95
		} catch (TransformerConfigurationException e) {
96
			throw new IllegalStateException("transformer configuration", e);
97
		} catch (TransformerFactoryConfigurationError e) {
98
			throw new IllegalStateException("transformer configuration", e);
99
		}
100

  
101
		final XPath xpath = XPathFactory.newInstance().newXPath();
102

  
103
		this.resourceId = xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_IDENTIFIER/@value", dom);
104
		this.resourceType = xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_TYPE/@value", dom);
105
		this.resourceKind = xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_KIND/@value", dom);
106
		this.resourceUri = xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_URI/@value", dom);
107

  
108
		String modificationDateSource = xpath.evaluate("/RESOURCE_PROFILE/HEADER/DATE_OF_CREATION/@value", dom);
109

  
110
		try {
111
			this.modificationDate = new DateUtils().parse(modificationDateSource);
112
		} catch (IllegalStateException e) {
113
			log.debug("invalid date '" + modificationDateSource + "'", e);
114
		}
115
	}
116

  
117
	/**
118
	 * {@inheritDoc}
119
	 *
120
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#asDom()
121
	 */
122
	@Override
123
	public Document asDom() {
124
		return getDom();
125
	}
126

  
127
	/**
128
	 * {@inheritDoc}
129
	 *
130
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#asString()
131
	 */
132
	@Override
133
	public String asString() {
134
		final StringWriter writer = new StringWriter();
135

  
136
		try {
137
			transformer.transform(new DOMSource(getDom()), new StreamResult(writer));
138
		} catch (TransformerException e) {
139
			log.fatal("cannot serialize document", e);
140
			return null;
141
		}
142
		return writer.toString();
143
	}
144

  
145
	public Document getDom() {
146
		return dom;
147
	}
148

  
149
	public void setDom(final Document dom) {
150
		this.dom = dom;
151
	}
152

  
153
	@Override
154
	public String getResourceId() {
155
		return resourceId;
156
	}
157

  
158
	@Override
159
	public String getResourceType() {
160
		return resourceType;
161
	}
162

  
163
	public void setResourceType(final String resourceType) {
164
		this.resourceType = resourceType;
165
	}
166

  
167
	@Override
168
	public String getResourceKind() {
169
		return resourceKind;
170
	}
171

  
172
	/**
173
	 * {@inheritDoc}
174
	 *
175
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#setResourceKind(java.lang.String)
176
	 */
177
	@Override
178
	public void setResourceKind(final String resourceKind) {
179
		try {
180
			final XPath xpath = XPathFactory.newInstance().newXPath();
181
			final Element kindEl = (Element) xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_KIND", asDom(), XPathConstants.NODE);
182
			kindEl.setAttribute(VALUE_ATTR, resourceKind);
183
			this.resourceKind = resourceKind;
184
		} catch (XPathExpressionException e) {
185
			throw new IllegalStateException(XPATH_ERROR, e);
186
		}
187

  
188
	}
189

  
190
	/**
191
	 * {@inheritDoc}
192
	 *
193
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#setResourceId(java.lang.String)
194
	 */
195
	@Override
196
	public void setResourceId(final String identifier) {
197
		try {
198
			final XPath xpath = XPathFactory.newInstance().newXPath();
199
			final Element idEl = (Element) xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_IDENTIFIER", asDom(), XPathConstants.NODE);
200
			idEl.setAttribute(VALUE_ATTR, identifier);
201
			resourceId = identifier;
202
		} catch (XPathExpressionException e) {
203
			throw new IllegalStateException(XPATH_ERROR, e);
204
		}
205
	}
206

  
207
	@Override
208
	public Date getModificationDate() {
209
		return modificationDate;
210
	}
211

  
212
	/**
213
	 * {@inheritDoc}
214
	 *
215
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#setModificationDate(java.util.Date)
216
	 */
217
	@Override
218
	public void setModificationDate(final Date modificationDate) {
219
		try {
220
			final XPath xpath = XPathFactory.newInstance().newXPath();
221
			final Element idEl = (Element) xpath.evaluate("/RESOURCE_PROFILE/HEADER/DATE_OF_CREATION", asDom(), XPathConstants.NODE);
222
			if (idEl == null) {
223
				log.warn("resource with type " + getResourceType() + " has no date of creation element");
224
				return;
225
			}
226
			idEl.setAttribute(VALUE_ATTR, new DateUtils(modificationDate).getDateAsISO8601String());
227
			this.modificationDate = modificationDate;
228
		} catch (XPathExpressionException e) {
229
			throw new IllegalStateException(XPATH_ERROR, e);
230
		}
231

  
232
	}
233

  
234
	@Override
235
	public String getResourceUri() {
236
		return resourceUri;
237
	}
238

  
239
	/**
240
	 * {@inheritDoc}
241
	 *
242
	 * @see eu.dnetlib.enabling.tools.OpaqueResource#setResourceUri(java.lang.String)
243
	 */
244
	@Override
245
	public void setResourceUri(final String resourceUri) {
246
		try {
247
			final XPath xpath = XPathFactory.newInstance().newXPath();
248
			final Element uriEl = (Element) xpath.evaluate("/RESOURCE_PROFILE/HEADER/RESOURCE_URI", asDom(), XPathConstants.NODE);
249
			uriEl.setAttribute(VALUE_ATTR, resourceUri);
250
			this.resourceUri = resourceUri;
251
		} catch (XPathExpressionException e) {
252
			throw new IllegalStateException(XPATH_ERROR, e);
253
		}
254
	}
255

  
256
	public Transformer getTransformer() {
257
		return transformer;
258
	}
259

  
260
	public void setTransformer(final Transformer transformer) {
261
		this.transformer = transformer;
262
	}
263

  
264
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/HNMLocator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * finds an HNM profile for a giver service url.
5
 * 
6
 * @author marko
7
 * 
8
 */
9
public interface HNMLocator {
10

  
11
	/**
12
	 * finds an HNM profile for a giver service url.
13
	 * 
14
	 * @param url
15
	 *            service address
16
	 * @return hnm id
17
	 */
18
	String getHNMForUrl(String url);
19
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/DynamicServiceEnumerator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

  
10
import javax.annotation.Resource;
11
import javax.xml.parsers.DocumentBuilder;
12
import javax.xml.parsers.DocumentBuilderFactory;
13
import javax.xml.parsers.ParserConfigurationException;
14
import javax.xml.ws.wsaddressing.W3CEndpointReference;
15
import javax.xml.xpath.XPath;
16
import javax.xml.xpath.XPathConstants;
17
import javax.xml.xpath.XPathExpressionException;
18
import javax.xml.xpath.XPathFactory;
19

  
20
import org.apache.commons.logging.Log;
21
import org.apache.commons.logging.LogFactory;
22
import org.springframework.beans.factory.annotation.Required;
23
import org.w3c.dom.Document;
24
import org.w3c.dom.Element;
25
import org.w3c.dom.NodeList;
26
import org.xml.sax.InputSource;
27
import org.xml.sax.SAXException;
28

  
29
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
30
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
31
import eu.dnetlib.enabling.tools.registration.ServiceNameResolver;
32
import eu.dnetlib.miscutils.collections.EnsureCollection;
33
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder;
34

  
35
/**
36
 * Enumerates all services of a given type.
37
 *
38
 * @author marko
39
 *
40
 * @param <T>
41
 *            service class
42
 */
43
@Deprecated
44
public class DynamicServiceEnumerator<T> implements ServiceEnumerator<T> {
45

  
46
	/**
47
	 * logger.
48
	 */
49
	private static final Log log = LogFactory.getLog(DynamicServiceEnumerator.class); // NOPMD by marko on 11/24/08 5:02 PM
50

  
51
	/**
52
	 * service class
53
	 */
54
	private Class<T> clazz;
55

  
56
	/**
57
	 * lookup locator.
58
	 */
59
	private ServiceLocator<ISLookUpService> lookUpLocator;
60

  
61
	/**
62
	 * service name resolver.
63
	 */
64
	@Resource
65
	private ServiceNameResolver serviceNameResolver; // NOPMD
66

  
67
	/**
68
	 * build epr.
69
	 */
70
	@Resource
71
	private StandaloneCxfEndpointReferenceBuilder eprBuilder;
72

  
73
	/**
74
	 * default constructor, useful for spring based instantiation.
75
	 */
76
	public DynamicServiceEnumerator() {
77
		// default
78
	}
79

  
80
	/**
81
	 * Build a dynamic service enumerator for a given class
82
	 *
83
	 * @param clazz
84
	 *            class
85
	 */
86
	public DynamicServiceEnumerator(final Class<T> clazz) {
87
		super();
88
		this.clazz = clazz;
89
	}
90

  
91
	/**
92
	 * {@inheritDoc}
93
	 *
94
	 * @see eu.dnetlib.enabling.tools.ServiceEnumerator#getServices()
95
	 */
96
	@Override
97
	public List<ServiceRunningInstance<T>> getServices() {
98
		final String serviceName = serviceNameResolver.getName(clazz);
99
		log.debug("searching for service: " + serviceName);
100

  
101
		final String xquery = "for $x in collection('/db/DRIVER/ServiceResources')//RESOURCE_PROFILE[.//RESOURCE_TYPE/@value/string() = '"
102
				+ serviceName
103
				+ "ResourceType'] return <service><id>{$x//RESOURCE_IDENTIFIER/@value/string()}</id><url>{$x//PROTOCOL[@name = 'SOAP']/@address/string()}</url><properties>{$x//SERVICE_PROPERTIES/PROPERTY}</properties></service>";
104
		log.debug(xquery);
105

  
106
		final XPathFactory factory = XPathFactory.newInstance();
107
		final XPath xpath = factory.newXPath();
108

  
109
		final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
110

  
111
		try {
112
			final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
113

  
114
			final List<String> services = lookUpLocator.getService().quickSearchProfile(xquery);
115
			final List<ServiceRunningInstance<T>> instances = new ArrayList<ServiceRunningInstance<T>>();
116

  
117
			for (final String source : EnsureCollection.list(services)) {
118
				final Document doc = docBuilder.parse(new InputSource(new StringReader(source)));
119
				final String url = xpath.evaluate("//url", doc);
120
				final String serviceId = xpath.evaluate("//id", doc);
121

  
122
				final NodeList propElements = (NodeList) xpath.evaluate("//PROPERTY", doc, XPathConstants.NODESET);
123
				Map<String, String> props = new HashMap<String, String>();
124

  
125
				for (int i = 0; i < propElements.getLength(); i++) {
126
					Element propElement = (Element) propElements.item(i);
127
					props.put(propElement.getAttribute("key"), propElement.getAttribute("value"));
128
				}
129

  
130
				final W3CEndpointReference epr = eprBuilder.getEndpointReference(url, null, null, url + "?wsdl", null, null);
131

  
132
				instances.add(new ServiceRunningInstance<T>(epr, serviceId, url, props));
133
			}
134

  
135
			return instances;
136
		} catch (final ISLookUpException e) {
137
			throw new IllegalStateException("cannot locate service " + serviceName, e);
138
		} catch (final XPathExpressionException e) {
139
			throw new IllegalStateException("cannot locate service " + serviceName, e);
140
		} catch (final SAXException e) {
141
			throw new IllegalStateException("cannot locate service " + serviceName, e);
142
		} catch (final IOException e) {
143
			throw new IllegalStateException("cannot locate service " + serviceName, e);
144
		} catch (final ParserConfigurationException e) {
145
			throw new IllegalStateException("cannot locate service " + serviceName, e);
146
		}
147
	}
148

  
149
	public Class<T> getClazz() {
150
		return clazz;
151
	}
152

  
153
	@Required
154
	public void setClazz(final Class<T> clazz) {
155
		this.clazz = clazz;
156
	}
157

  
158
	public ServiceLocator<ISLookUpService> getLookUpLocator() {
159
		return lookUpLocator;
160
	}
161

  
162
	public void setLookUpLocator(final ServiceLocator<ISLookUpService> lookUpLocator) {
163
		this.lookUpLocator = lookUpLocator;
164
	}
165

  
166
	public ServiceNameResolver getServiceNameResolver() {
167
		return serviceNameResolver;
168
	}
169

  
170
	public void setServiceNameResolver(final ServiceNameResolver serviceNameResolver) {
171
		this.serviceNameResolver = serviceNameResolver;
172
	}
173

  
174
	public StandaloneCxfEndpointReferenceBuilder getEprBuilder() {
175
		return eprBuilder;
176
	}
177

  
178
	public void setEprBuilder(StandaloneCxfEndpointReferenceBuilder eprBuilder) {
179
		this.eprBuilder = eprBuilder;
180
	}
181

  
182
}
modules/cnr-service-common/tags/cnr-service-common-2.1.7/src/main/java/eu/dnetlib/enabling/tools/AbstractServiceLocator.java
1
package eu.dnetlib.enabling.tools;
2

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

  
7
import javax.annotation.Resource;
8
import javax.xml.parsers.DocumentBuilder;
9
import javax.xml.parsers.DocumentBuilderFactory;
10
import javax.xml.ws.wsaddressing.W3CEndpointReference;
11
import javax.xml.xpath.XPath;
12
import javax.xml.xpath.XPathConstants;
13
import javax.xml.xpath.XPathFactory;
14

  
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogFactory;
17
import org.w3c.dom.Document;
18
import org.w3c.dom.Element;
19
import org.w3c.dom.NodeList;
20
import org.xml.sax.InputSource;
21

  
22
import com.google.common.collect.Maps;
23

  
24
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
25
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
26
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder;
27

  
28
@Deprecated
29
public abstract class AbstractServiceLocator<T> implements ServiceLocator<T> {
30

  
31
	/**
32
	 * lookup locator.
33
	 */
34
	@Resource(name="lookupLocator")
35
	private ServiceLocator<ISLookUpService> lookUpLocator;	
36
	
37
	/**
38
	 * build epr.
39
	 */
40
	@Resource
41
	private StandaloneCxfEndpointReferenceBuilder eprBuilder;
42
	
43
	/**
44
	 * service resolver. used to create proxies for discovered services.
45
	 */
46
	@Resource(name="serviceResolver")
47
	private ServiceResolver serviceResolver;
48
	
49
	/**
50
	 * logger.
51
	 */
52
	private static final Log log = LogFactory.getLog(AbstractServiceLocator.class); // NOPMD by marko on 11/24/08 5:02 PM
53

  
54
	
55
	@Override
56
	public T getService(final String profileId, final Class<T> clazz) {
57
		final String profile = executeQuery(profileId, null);
58
		
59
		try {
60
			final XPathFactory factory = XPathFactory.newInstance();
61
			final XPath xpath = factory.newXPath();
62
	
63
			final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
64
			final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
65
			
66
			final Document doc = docBuilder.parse(new InputSource(new StringReader(profile)));
67
			final String url = xpath.evaluate("//url", doc);
68
			final String serviceId = xpath.evaluate("//id", doc);
69
	
70
			final NodeList propElements = (NodeList) xpath.evaluate("//PROPERTY", doc, XPathConstants.NODESET);
71
			final Map<String, String> props = Maps.newHashMap();
72
	
73
			for (int i = 0; i < propElements.getLength(); i++) {
74
				Element propElement = (Element) propElements.item(i);
75
				props.put(propElement.getAttribute("key"), propElement.getAttribute("value"));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff