27

Unit testing a filter in Grails 2

sty
No Comments |  Posted by |  Category:Forum
I’m in the process of writing a filter for a Grails 2 application and would like to write a unit test for it. The documentation outlines a way to test the execution of a controller wrapped by the filters configured. I understand how this would work for a simple controller and a controller that depends on a service that is mocked. However, I’m not sure how to setup any dependencies the filter itself has. The filter I’m using calls a service. How do I inject that service? Below is the code for my filter and it’s unit test. Any ideas anyone has are appreciated. Thanks in advance!

Filter:

Code:

package grails.feature.toggle.filters
import grails.plugin.featuretoggle.FeatureToggleService;
import grails.plugin.featuretoggle.annotations.FeatureToggle;

class FeatureToggleFilters {

        FeatureToggleService featureToggleService

        def filters = {
                allControllers(controller:'*', action:'*') {
                        before = {
                                def artefact = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)

                                def curController = applicationContext.getBean(artefact.clazz.name)

                                def annotation = curController.class.getAnnotation(FeatureToggle)

                                if(annotation != null && !featureToggleService.isFeatureEnabled(annotation.feature())) {
                                        render(status: annotation.responseStatus())
                                        return
                                }
                        }
                }
        }
}


Test:

Code:

package grails.feature.toggle

import grails.feature.toggle.filters.FeatureToggleFilters
import grails.plugin.featuretoggle.FeatureToggleService
import grails.test.mixin.Mock
import grails.test.mixin.TestFor

@TestFor(SampleController)
@Mock(FeatureToggleFilters)
class SampleControllerTests {

        def featureService

        void testFeatureIsDisabled() {
                def featureService = mockFor(FeatureToggleService)
                featureService.demand.isFeatureEnabled {String feature -> return false}
               
                withFilters(action: 'index') {
                        controller.index()
                }

                assert response.status == 404
        }
}


more...
27

Naming Convention based Soap Fault elements

sty
No Comments |  Posted by |  Category:Forum
Hello All,

Using Spring WS 2.0.1 I’m trying to define the soap faults a given operation can return within the wsdl. I’m using the dynamically generated wsdl functionality of Spring WS and I found that I can associate fault elements to operations by following the naming convention [operationName]Fault. This works beautifully and the generated wsdl correctly lists my Fault element with the operation:

Code:

<wsdl:operation name="SomeOperation">
<wsdl:input message="tns:SomeOperationRequest" name="SomeOperationRequest">
    </wsdl:input>
<wsdl:output message="tns:SomeOperationResponse" name="SomeOperationResponse">
    </wsdl:output>
<wsdl:fault message="tns:SomeOperationFault" name="SomeOperationFault">
    </wsdl:fault>
</wsdl:operation>


I’ve created a custom version of SoapFaultMappingExceptionResolver in order to customize the generated soap fault but for some reason, the SoapFault argument that gets passed into the customizeFault method doesn’t have it’s detail attribute populated with an instance of the Fault that was described in the WSDL. From all the research I’ve done so far, it seem that you’re 100% on you own to create the FaultDetail object that is described in the wsdl. If you don’t have a one to one mapping between the exception thrown and the declared fault, there’s not an *easy* way within the body of that method to figure out which fault detail element should be created. You *do* get access to the endpoint itself so I’m sure you could somehow use that to figure out which operation was called but that seems like a bad approach. Is there something that I’m missing or is this a bit of a gap in Spring WSs handling of SoapFaults? I’ve scoured through a bunch of posts regarding Spring WS and SoapFaults but I’m yet to find anything addressing this scenerio. Any insight would be greatly appreciated.
Thanks in advance

Seamus

more...
27

Stopping jobs "via the database"

sty
No Comments |  Posted by |  Category:Forum
The docs mention in section ’2.4 Meta Data Access Improvements’ that

Quote:

"It is also worth noting that Jobs can now be stopped via the database…"


Having noted that – I’d be interested to know what it means. :) I mean understand – not assume. :)

However, this is what I assume. That one should update the database (via the JobRepository) using the JobOperator interface. I see JobOperator has a handy looking stop(executionId) method.

I know it sounds obvious but just double checking that I’ve noted this correctly. :p

TIA,
David.

more...
27

Support for Generics

sty
No Comments |  Posted by |  Category:Forum
Is there any particular reason why
Code:

org.springframework.amqp.support.converter.MessageConvertor

is not

Code:

org.springframework.amqp.support.converter.MessageConverter<T>

with correspondingly changing the method signatures?

It will be great if the next fix version changes this.

more...
27

Webservice breaks when removing ‘parent’ element and adding ‘scm’ element within pom

sty
No Comments |  Posted by |  Category:Forum
Our webservice works correctly when the pom.xml uses the ‘parent’ element, and does not use the ‘scm’ element.
Our webservice breaks when the pom.xml uses the ‘scm’ element, and doesn’t use the ‘parent’ element.

For this test, we use a static wsdl
- we start up the webservice using ‘dynamic-wsdl’ element within ‘spring-ws-servlet.xml’, then copy the resulting wsdl into the static wsdl file, and then, switch to using the ‘static-wsdl’ element within ‘spring-ws-servlet.wsdl’.

The result is that when using ‘parent’ element and not ‘scm’ element within pom.xml, SoapUI is able to work with the given wsdl.

If using the ‘scm’ element and not ‘parent’ element, SoapUI fails with the following message:

Servlet.service() for servlet [spring-ws] in context with path [/QcimService] threw exception [Request processing failed; nested exception is javax.xml.transform.TransformerException: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.] with root cause
org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

The WSDL file differs in the xmlns inclusion order.
The working version has:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:sch="http://xmlns.qualcomm.com/it/isso/qcim/schemas/1.0.0"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://xmlns.qualcomm.com/it/isso/qcim/definitions/1.0.0"
targetNamespace="http://xmlns.qualcomm.com/it/isso/qcim/definitions/1.0.0">

The non-working version has:

<wsdl:definitions xmlns:sch="http://xmlns.qualcomm.com/it/isso/qcim/schemas/1.0.0"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://xmlns.qualcomm.com/it/isso/qcim/definitions/1.0.0"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://xmlns.qualcomm.com/it/isso/qcim/definitions/1.0.0">

Changing the order on the non-working version to conform to working version does not because this causes the schema validation to fail.

Finally, between the two projects, there is the inclusion of the following Jar files in the non-working version:

activation-1.1.jar
icu4j-2.6.1.jar
jdom-1.0.jar
mail-1.4.3.jar
saaj-api-1.3.jar
spring-test-3.0.6.RELEASE.jar
xalan-2.6.0.jar
xercesImpl-2.6.2.jar
xml-apis-1.3.02.jar
xmlParserAPIs-2.6.2.jar
xom-1.0.jar

Since ‘parent’ element is deprecated, please help resolve this issue of removing ‘parent’ element from pom.xml causing webservice errors.

Within poms.zip, I have added the pom.xml file with pom-working.xml is the working version and pom-broken.xml is the version leading to a broken webservice.

Attached Files
  • File Type: zip
    poms.zip‎
    (8.7 KB)
more...
27

design question

sty
No Comments |  Posted by |  Category:Forum
I am wondering if I have some redundancies in the way I have set up my project. I have created a working jar for my application, easier to run a test locally for me. It is completely self contained with its own spring configuration, i.e. I can run as a java application. (I have several modules like this.)

I have also created a spring mvc app that I will use to run/monitor this application in tomcat. The jar is a dependency of the mvc app and has its own controller.

Would this be considered a bad practice? Everything works but it occurred to me the other day this may not be the best way to do things.

I hope that I am explaining this properly.

Basically my war has a spring config but my jar also has a spring config.

Any and all thoughts would be greatly appreciated.

Thanks,
Bobby

more...
27

PropertyOverrideConfigurer and LIST properties

sty
No Comments |  Posted by |  Category:Forum
I fell in love with the PropertyOverrideConfigurer. Using the following configuration it lets me have a context file that is identical between DEV, TEST and PROD servers while keeping server-specific values in a properties file for each server. I can even have all of the properties file present in my DEV box (and version control) and only the DEV one is used since the last PropertyOverrideConfigurer is the one that gets used.

In the context:

Code:

<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
    <property name="locations"              value="classpath*:myAppPROD.properties" />
    <property name="ignoreResourceNotFound" value="true" />
</bean>
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer" >
    <property name="locations"              value="classpath*:myAppDEV.properties" />
    <property name="ignoreResourceNotFound" value="true" />
</bean>

<bean id="myBeanId" class="mypackage.MyClass">
    <property name="appSpecificProperty"    value="1234" />
    <property name="serverSpecificProperty" value="" />
</bean>


In myAppDEV.properties:

Code:

myBeanId.serverSpecificProperty=devhostname56.domain.com

It works great. But… I am stumped about how to setup properties that have a list of strings as its values. For example, if I were to hard-code it in the context such a property could be defined as:

Code:

<bean id="myListBean" class="mypackage.MyOtherClass>
    <property name="myListProperty">
      <list>
        <value>myString1</value>
        <value>myString2</value>
        <value>myString3</value>
      <list>
    </property>
</bean>


I typically use list properties like the one above for email address lists that are different between DEV and PROD. And here comes the question:

Without changing MyOtherClass, is there a way to define the list values in myAppDEV.properties and specify <property name="myListProperty"> in a way that is compatible with the PropertyOverrideConfigurer?

more...
27

New simple SpringWS 2.0: SOAP-ENV:Server No adapter for endpoint

sty
No Comments |  Posted by |  Category:Forum
Hi,
I’m learning SpringWS 2.0. I set up a simple End Point as an exercise to see how things flow. I got the SOAP Fault on the server side.
What did I miss? 1M Thanks.

@Endpoint
public class BankingSIB {
private static final String NAMESPACE_URI = "http://ci.test/";
private static final String GETBALANCE = "getBalance";

@PayloadRoot(localPart = GETBALANCE, namespace = NAMESPACE_URI)
@ResponsePayload
@Namespace(prefix = "ci", uri=NAMESPACE_URI)
public Double getBalance(@XPathParam("/ci:getBalance/arg0") Long acctno, @XPathParam("/ci:getBalance/arg1") Long secno) throws SocialSecurityException, AccountNumberException {
}
}

SOAP request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ci="http://ci.test/">
<soapenv:Header/>
<soapenv:Body>
<ci:getBalance>
<!–Optional:–>
<!–type: long–>
<arg0>10</arg0>
<!–Optional:–>
<!–type: long–>
<arg1>10</arg1>
</ci:getBalance>
</soapenv:Body>
</soapenv:Envelope>

SOAP response

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">No adapter for endpoint [public java.lang.Double test.ci.BankingSIB.getBalance(java.lang.Long,java. lang.Long) throws test.exception.SocialSecurityException,test.except ion.AccountNumberException]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
more...
27

Server doesn’t proceed after INFO – Initializing Spring root WebApplicationContext

sty
No Comments |  Posted by |  Category:Forum
Hi,

I am trying to deploy an application in JBOSS 5.1 server but it doesn’t proceed after this info message
"Initializing Spring root WebApplicationContext"

The application is a web app for Spring(3.0.5) Webservices using CXF 2.4.2

please provide some pointers.

Thanks.

more...
27

util:map throwing BeanDefinitionParser error

sty
No Comments |  Posted by |  Category:Forum
Hi all,
i want to implement double hashing in my code
for example.
In the first map Countrycode is the key
key Value
UK Ukdomains
DE Germandomains

and then
in the second map city code is the Key

id of this bean will be Ukdomains
Key Value
Lon somevalue
Man somevalue

this is wat i tried

Code:

<property name="splitDomains"
            <util:map id="DE" map-class="java.util.HashMap">
                        <entry key="FRA" value="COLT-AM-DE001" />
                        <entry key="BHX" value="COLT-AM-DE002" />
          </util:map>
        </property>


but im getting BeanDefinition Parder error on map

Any help is much appreciated.

Thanks

more...