Parameterized Tests: An Underused Technique
4 years ago
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
@Endpoint
public class MyExposedEndpoint {
@PayloadRoot(localPart="MyEndpointMethod", namespace="http://www.company.com/mynamespace")
public void processMyMethod(MyRequest myRequest) {
// Insert code to process the request here.
}
}
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.vendor.JAXBClass1</value>>
<value>com.vendor.JAXBClass2</value>
<value>com.vendor.JAXBClass3</value>
</list>
</property>
</bean>
<bean id="myServiceClient" class="com.company.project.ws.MyServiceClient">
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
the class MyServiceClient extends the spring WebServiceGatewaySupport class. This is an easy way to send requests and receive responses. Inside your class you can create the request object that you want sent using the JAXB ObjectFactory methods.
MyRequest myRequest = new ObjectFactory().createMyRequest();
Then you can set individual elements on that object, whatever they are. The request is sent by using a method from the Spring class. The SoapAction is not set automatically, so it needs to be set manually.
MyResponse myResponse = getWebServiceTemplate().marshallSendAndReceive(serviceUri, myRequest, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage message) {
((SoapMessage)message).setSoapAction("MySoapAction");}});
That's really all there is to it. As you can see the above method automatically marshalls the request to XML and unmarshalls the response to the JAXB Java object. Also it is good to surround that method call with a try catch so that if there is a problem on the other end, your software can react appropriately.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:my-project.properties</value>
</property>
</bean>
<bean id="jmsQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${my.project.testQueue}"/>
<property name="jndiTemplate" ref="jndiTemplate" />
</bean>
<si-ws:outbound-gateway id="WebServiceGateway"
request-channel="jmsChannel"
reply-channel="replyChannel"
uri="${my.project.uri}" />
if [ "${LOG4J_CONFIG_FILE}" != "" ] ; then
JAVA_PROPERTIES="${JAVA_PROPERTIES} -Dlog4j.configuration=file:${LOG4J_CONFIG_FILE}"
export JAVA_PROPERTIES
fi
LOG4J_CONFIG_FILE=”/u01/app/oracle/middleware/user_projects/domains/base_domain/log4j.xml”
Export LOG4J_CONFIG_FILE
if NOT "%LOG4J_CONFIG_FILE%"=="" (
set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE%
)
set LOG4J_CONFIG_FILE=”C:\Oracle\Middleware\user_projects\domains\base_domain\log4j.xml”
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!--====================================================================-->
<!-- Appenders -->
<!-- %d{dd-MMM-yy HH:mm:ss} %-5p [%c{1}] %m%n -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] - %m (%F:%M:%L)%n"/>
<!--param name="ConversionPattern" value="%d{ISO8601} %p [%c{1}] - %m (%F:%M:%L)%n"/-->
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/temp/logs/yourproject.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %t %-5p %c{2} - %m%n"/>
</layout>
</appender>
<!--====================================================================-->
<!-- Logging Levels -->
<category name="com.yourcompany.yourproject">
<priority value="DEBUG"/>
</category>
<category name="org.apache">
<priority value="WARN"/>
</category>
<category name="org.springframework">
<priority value="WARN"/>
</category>
<!--===================================================================-->
<!-- Appender Assignments -->
<root>
<priority value="ERROR"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>