Author: chris.laprun(a)jboss.com
Date: 2007-05-02 01:43:03 -0400 (Wed, 02 May 2007)
New Revision: 7169
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/BehaviorBackedServiceFactory.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/EndpointConfigurationInfoTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
Log:
- Added isRefreshNeeded method for clients to know if a refresh is needed due to changes
in URLs.
- Added test case.
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/BehaviorBackedServiceFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/BehaviorBackedServiceFactory.java 2007-05-02
05:40:38 UTC (rev 7168)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/BehaviorBackedServiceFactory.java 2007-05-02
05:43:03 UTC (rev 7169)
@@ -109,22 +109,22 @@
public void setServiceDescriptionURL(String serviceDescriptionURL)
{
- throw new NotYetImplemented();
+ // do nothing
}
public void setMarkupURL(String markupURL)
{
- throw new NotYetImplemented();
+ // do nothing
}
public void setRegistrationURL(String registrationURL)
{
- throw new NotYetImplemented();
+ // do nothing
}
public void setPortletManagementURL(String portletManagementURL)
{
- throw new NotYetImplemented();
+ // do nothing
}
public void create() throws Exception
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/EndpointConfigurationInfoTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/EndpointConfigurationInfoTestCase.java 2007-05-02
05:40:38 UTC (rev 7168)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/EndpointConfigurationInfoTestCase.java 2007-05-02
05:43:03 UTC (rev 7169)
@@ -23,6 +23,7 @@
package org.jboss.portal.test.wsrp.other;
import junit.framework.TestCase;
+import org.jboss.portal.test.wsrp.framework.support.BehaviorBackedServiceFactory;
import org.jboss.portal.wsrp.consumer.EndpointConfigurationInfo;
import org.jboss.portal.wsrp.services.PerEndpointSOAPInvokerServiceFactory;
import org.jboss.portal.wsrp.services.RemoteSOAPInvokerServiceFactory;
@@ -90,4 +91,27 @@
// it should be possible to set the WSDL to null for Hibernate
info.setWsdlDefinitionURL(null);
}
+
+ public void testIsRefreshNeeded() throws Exception
+ {
+ assertTrue(info.isRefreshNeeded());
+ assertFalse(info.isAvailable());
+
+ info.setServiceFactory(new BehaviorBackedServiceFactory());
+ String bea = "http://wsrp.bea.com:7001/producer/producer?WSDL";
+ info.setWsdlDefinitionURL(bea);
+ assertFalse(info.isRefreshNeeded());
+ assertTrue(info.isAvailable());
+
+ // change the service factory to a fake one to be able to simulate access to
endpoint
+ info.setServiceFactory(new BehaviorBackedServiceFactory());
+ info.setServiceDescriptionURL(url);
+ assertTrue(info.isRefreshNeeded());
+
+ info.getRegistrationService();
+ assertTrue(info.isRefreshNeeded());
+
+ info.getServiceDescriptionService();
+ assertFalse(info.isRefreshNeeded());
+ }
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2007-05-02
05:40:38 UTC (rev 7168)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2007-05-02
05:43:03 UTC (rev 7169)
@@ -33,6 +33,8 @@
import org.jboss.portal.wsrp.services.RemoteSOAPInvokerServiceFactory;
import org.jboss.portal.wsrp.services.ServiceFactory;
+import java.util.BitSet;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -61,6 +63,12 @@
// Used to ensure that even invalid values can be persisted to DB so that it can be
accessed from the GUI
public final static String UNSET = "MUST BE SET";
+ // maintain the dirty status of each URL
+ private BitSet clean = new BitSet();
+ private final static int SD = 0;
+ private final static int M = 1;
+ private final static int PM = 2;
+ private final static int R = 3;
public EndpointConfigurationInfo()
{
@@ -146,7 +154,8 @@
{
serviceFactory.setServiceDescriptionURL(serviceDescriptionURL);
}
- this.serviceDescriptionURL = serviceDescriptionURL;
+ this.serviceDescriptionURL = modifyIfNeeded(this.serviceDescriptionURL,
serviceDescriptionURL, SD);
+
}
public void setMarkupURL(String markupURL)
@@ -155,7 +164,7 @@
{
serviceFactory.setMarkupURL(markupURL);
}
- this.markupURL = markupURL;
+ this.markupURL = modifyIfNeeded(this.markupURL, markupURL, M);
}
public void setRegistrationURL(String registrationURL)
@@ -164,7 +173,7 @@
{
serviceFactory.setRegistrationURL(registrationURL);
}
- this.registrationURL = registrationURL;
+ this.registrationURL = modifyIfNeeded(this.registrationURL, registrationURL, R);
}
public void setPortletManagementURL(String portletManagementURL)
@@ -173,7 +182,7 @@
{
serviceFactory.setPortletManagementURL(portletManagementURL);
}
- this.portletManagementURL = portletManagementURL;
+ this.portletManagementURL = modifyIfNeeded(this.portletManagementURL,
portletManagementURL, PM);
}
public void setWsdlDefinitionURL(String wsdlDefinitionURL) throws RuntimeException
@@ -187,17 +196,21 @@
{
serviceFactory = new RemoteSOAPInvokerServiceFactory();
}
- try
- {
-
((RemoteSOAPInvokerServiceFactory)serviceFactory).setWsdlDefinitionURL(wsdlDefinitionURL);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
+ internalSetWsdlURL();
}
}
+ private String modifyIfNeeded(String oldValue, String newValue, int whichURL)
+ {
+ if ((oldValue != null && !oldValue.equals(newValue)) || (oldValue == null
&& newValue != null))
+ {
+ oldValue = newValue;
+ clean.clear(whichURL);
+ }
+
+ return oldValue;
+ }
+
private void initServiceFactoryIfNeeded() throws RuntimeException
{
if (serviceFactory == null)
@@ -205,14 +218,7 @@
if (usesWSDL())
{
serviceFactory = new RemoteSOAPInvokerServiceFactory();
- try
- {
-
((RemoteSOAPInvokerServiceFactory)serviceFactory).setWsdlDefinitionURL(wsdlDefinitionURL);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
+ internalSetWsdlURL();
}
else
{
@@ -233,6 +239,19 @@
}
+ private void internalSetWsdlURL()
+ {
+ try
+ {
+
((RemoteSOAPInvokerServiceFactory)serviceFactory).setWsdlDefinitionURL(wsdlDefinitionURL);
+ clean.set(0, 4); // if setting the WSDL URL worked, consider everything clean
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public void start() throws Exception
{
getServiceFactory().start();
@@ -249,7 +268,12 @@
return serviceFactory;
}
- void setServiceFactory(ServiceFactory serviceFactory)
+ /**
+ * Only public for tests...
+ *
+ * @param serviceFactory
+ */
+ public void setServiceFactory(ServiceFactory serviceFactory)
{
ParameterValidation.throwIllegalArgExceptionIfNull(serviceFactory,
"ServiceFactory");
@@ -266,22 +290,22 @@
}
- WSRP_v1_ServiceDescription_PortType getServiceDescriptionService() throws
InvokerUnavailableException
+ public WSRP_v1_ServiceDescription_PortType getServiceDescriptionService() throws
InvokerUnavailableException
{
return (WSRP_v1_ServiceDescription_PortType)getService(SERVICE_DESCRIPTION,
WSRP_v1_ServiceDescription_PortType.class);
}
- WSRP_v1_Markup_PortType getMarkupService() throws InvokerUnavailableException
+ public WSRP_v1_Markup_PortType getMarkupService() throws InvokerUnavailableException
{
return (WSRP_v1_Markup_PortType)getService(MARKUP, WSRP_v1_Markup_PortType.class);
}
- WSRP_v1_PortletManagement_PortType getPortletManagementService() throws
InvokerUnavailableException
+ public WSRP_v1_PortletManagement_PortType getPortletManagementService() throws
InvokerUnavailableException
{
return (WSRP_v1_PortletManagement_PortType)getService(PORTLET_MANAGEMENT,
WSRP_v1_PortletManagement_PortType.class);
}
- WSRP_v1_Registration_PortType getRegistrationService() throws
InvokerUnavailableException
+ public WSRP_v1_Registration_PortType getRegistrationService() throws
InvokerUnavailableException
{
return (WSRP_v1_Registration_PortType)getService(REGISTRATION,
WSRP_v1_Registration_PortType.class);
}
@@ -290,7 +314,9 @@
{
try
{
- return getServiceFactory().getService(clazz);
+ Object service = getServiceFactory().getService(clazz);
+ clean.set(getIndexFor(clazz));
+ return service;
}
catch (Exception e)
{
@@ -299,6 +325,23 @@
}
}
+ private int getIndexFor(Class clazz)
+ {
+ if (clazz == WSRP_v1_ServiceDescription_PortType.class)
+ {
+ return SD;
+ }
+ if (clazz == WSRP_v1_Markup_PortType.class)
+ {
+ return M;
+ }
+ if (clazz == WSRP_v1_PortletManagement_PortType.class)
+ {
+ return PM;
+ }
+ return R;
+ }
+
public boolean isAvailable()
{
try
@@ -310,4 +353,14 @@
return false;
}
}
+
+ public boolean isRefreshNeeded()
+ {
+ return areURLsDirty() || !isAvailable();
+ }
+
+ private boolean areURLsDirty()
+ {
+ return clean.cardinality() < 4;
+ }
}