Can not send response for UDP message - java

I am trying to send message with:
netcat -u localhost 11111abcd
I just need that the client get answer: OK It get the message and try to answer with OK.
But it writes this infinitely to application log:
Message: GenericMessage [payload=byte[2], headers={ip_packetAddress=127.0.0.1/127.0.0.1:49489, ip_address=127.0.0.1, id=8db6aa3b-b56b-6dce-9554-c7b0ce050142, ip_port=49489, ip_hostname=127.0.0.1, timestamp=1494442285767}]
Message Payload: OK
Config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<int:channel id="sendUdp"/>
<int-ip:udp-outbound-channel-adapter id="udpOut" host="localhost" port="11111"
multicast="false" check-length="false"
channel="sendUdp" />
<int-ip:udp-inbound-channel-adapter id="udpIn" port="11111" receive-buffer-size="500"
multicast="false" check-length="false"
channel="receiveUdp"/>
<int:service-activator id="updHandler" input-channel="receiveUdp" output-channel="sendUdp" ref="listener"/>
</beans>
#ServiceActivator
public String handle(Message<?> message) {
System.out.println("*** Message: " + message);
String command = new String((byte[]) message.getPayload());
System.out.println("*** Message Payload: "
+ command);
String response = "OK";
return response;
}

Your outbound adapter is sending messages to the inbound adapter. If you want to reply to a packet, you need to configure the socket and destination expressions. See the documentation.
<int-ip:udp-inbound-channel-adapter id="inbound" port="11111" channel="in" />
<int:channel id="in" />
<int:transformer expression="new String(payload).toUpperCase()"
input-channel="in" output-channel="out"/>
<int:channel id="out" />
<int-ip:udp-outbound-channel-adapter id="outbound"
socket-expression="#inbound.socket"
destination-expression="headers['ip_packetAddress']"
channel="out" />

Related

Couldn't pass the #bean value to another class through Autowiring

I am new to spring. So I couldn't figure out what issue is there in the below code. I have two classes. I am defining a #Bean Channel and am autowiring that bean in the next class. I am using annotation for autowiring. When I try " System.out.println(externalChannel.toString());" am getting null values and the exception null pointer exception is thrown.
#Configuration
public class MessagingConfig
{
#Value("${service.name}")
private String queueName; // NOSONAR
#Value("${${user}")
private String schema;
#Value("${Owner}")
private String owner;
#Bean
public Channel externalChannel()
{
EventsProvider eventsProvider = new EventsProvider();
eventsProvider.setOwner(owner);
System.out.println("-------Cost And Events Channel-------"+eventsProvider.getEventsChannel());
return eventsProvider.getEventsChannel();
}
}
And Another class is
#Component
#LoggedService
#Monitored(useActualType = true)
public class MessagePublish {
#Autowired
private MessagingService messageService;
#Autowired
private Channel externalChannel;
public void publishTPSMessage(SourceTransaction sourceTransaction)
{
TPSEvent event = new TPSEvent(ContextHolder.getContextId(), new Date(), GuidUtils.generateGuid(),sourceTransaction);
Message<TPSEvent> message = new Message<TPSEvent>(event);
message.getHeader().setMessageType(TPSEvent.class.getName());
message.getHeader().setPayloadEncodingType(SystemCodecs.XML.name());
System.out.println(message.toString());
System.out.println(externalChannel.toString());
messageService.publish(externalChannel, message);
}
}
More Info
public Channel getEventsChannel() {
return Channel.builder()
.setName("necessarySources")
.setConnectionName("defaultConnection")
.setType(ChannelType.Topic)
.setConnectionData(AqSqlConnectionData.buildString(this.owner, "Safi"))
.setSubscriberNames(new String[]{"Safi_Autowire"})
.build();
}
Main Class
public class TPSHandler {
public static void main(String[] args) {
BatchExport batchExportBean=getBatchExportASJAXBElement();
System.out.println(" batchExportBean Trans Description : " + batchExportBean.getDueDate());
for(Pay pay :batchExportBean.getPay()) {
SourceTransaction sourceTransaction=mapPayBatchToSourceTransaction(pay,batchExportBean);
String sourceTraString = getSourceTransactionASXML(sourceTransaction);
System.out.println(" sourceTraString : \n" + sourceTraString);
MessagePublish messagePublish= new MessagePublish();
//SourceTransaction sourceTransaction= new SourceTransaction();
messagePublish.publishTPSMessage(sourceTransaction);
}
}
}
My Servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:config-properties.xml" />
<import resource="classpath:datasource.xml" />
<import resource="classpath:transaction-manager.xml" />
<import resource="classpath:jmx.xml" />
<context:component-scan base-package="com.imosAdapter" />
<bean class="com.oasis.services.messaging.config.MessagingServicesConfig" />
<bean class="com.oasis.services.messaging.config.DefaultMessagingConnectorsConfig" />
<bean class="com.oasis.services.messaging.config.LoaderConfig" />
<context:annotation-config />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/config/oasis-component.properties</value>
</property>
</bean>
</beans>
The exception thrown:
Exception in thread "main" java.lang.NullPointerException
at com.imosAdapter.tps.events.MessagePublish.publishTPSMessage(MessagePublish.java:46)
at com.imosAdapter.tps.TPSHandler.main(TPSHandler.java:64)
What is the issue over here? Can anybody help me with this? what exactly I am missing here?
You need to initialize a Spring context at the start of your application when you do not create a servlet / run as a Server.
See Using Spring in a standalone application

Error 415 - Unsupported Media Type with Spring 4

I am upgrading Spring from version 3 (XML based) to 4.2.4 (annotation based)
Controller
#RestController
public class XnetOrderResourceController{
#Autowired
private XnetOrderDao orderDao;
/*
* GET All Orders
*/
#RequestMapping(value = "/getAllOrdersInfo", method =RequestMethod.GET, produces="application/json")
public XnetOrder get(#RequestParam("Id") Long Id) {
XnetOrder order=null;
try{
if(MiscUtils.isNotEmpty(Id)){
order=orderDao.get(Id);
}
}catch(HibernateException e){
log.info(ORDER_DETAIL_NOT_AVAILABLE);
getLogger().error(e.getMessage());
}
return order;
}
/*
* POST(create new) Orders
*/
#RequestMapping(value = "/insertOrders", method =RequestMethod.POST, consumes="application/json", produces="application/json")
public void post(#RequestBody XnetOrder order){
try{
orderDao.post(order);
}catch(HibernateException e){
log.info("Creating the Order operation failed.");
getLogger().error(e.getMessage());
}
}
/*
* PUT (update) orders
*/
#RequestMapping(value="/updateOrders", method=RequestMethod.PUT, consumes="application/json", produces="application/json")
public XnetOrder update(#RequestBody XnetOrder order){
try{
order=orderDao.put(order);
}catch(HibernateException e){
getLogger().error(e.getMessage());
}
return order;
}
/*
* DELETE orders
*/
#RequestMapping(value="/deleteOrders",method=RequestMethod.DELETE)
public void delete(#RequestParam("Id") Long Id){
try{
if(MiscUtils.isNotEmpty(Id)){
orderDao.delete(Id);
log.info("Order is successfully deleted");
}
}catch(HibernateException e){
log.info(XNET_PRODUCT_INVALID_ERROR_MESSAGE);
getLogger().error(e.getMessage());
}
}
}
Spring-Servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="com.nest.extranet" />
<mvc:annotation-driven
content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
<property name="favorParameter" value="true" />
<property name="mediaTypes">
<value>
json=application/json
</value>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
JAR files in my classpath are -
jackson-annotations-2.2.3.jar,
jackson-core-2.2.3.jar,
jackson-databind-2.3.3.jar,
jackson-mapper-asl-1.9.13.jar,
jackson-2.1.0-all.jar
I am able to perform GET operation, which successfully returns JSON value, but PUT and POST operations don't work. I am using Postman as a REST client. I also tried passing the URL for PUT operation after setting the header value Content-Type to aplication/json but it always returns
Error 415 - Unsupported Media Type.
I am getting the following response headers:
Connection → close
Content-Length → 903
Content-Type → text/html; charset=UTF-8
Date → Sat, 14 May 2016 09:16:57 GMT
X-Powered-By → Servlet/2.5 JSP/2.1
Can someone please suggest how to get PUT and POST operations to work?
If you specify produces for the controller method you also need to set the Accepts header on the request.

Issue with File Polling from remote location, connection success but read from local directory with FTP Spring Integration

i have configured FTP with spring integration while using inbound side im unable to get files from remote path, it always read from the local system path
ftp-inbound-listen-dynamic.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">
<context:property-placeholder />
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${ftp.host}" />
<property name="port" value="${ftp.port}" />
<property name="username" value="${ftp.username}" />
<property name="password" value="${ftp.password}" />
<property name="clientMode" value="0" />
<property name="fileType" value="2" />
<property name="bufferSize" value="100000" />
</bean>
<int:channel id="inboundChannel" />
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="inboundChannel" session-factory="ftpSessionFactory" charset="UTF-8"
auto-create-local-directory="true" delete-remote-files="true"
temporary-file-suffix=".writing" remote-directory="${ftp.remote-directory}"
local-directory="${ftp.local-directory}" filter="compositeFilter"
local-filter="localCompositeFilter">
<int:poller fixed-rate="15000" />
</int-ftp:inbound-channel-adapter>
<bean id="compositeFilter"
class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean
class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
<bean
class="org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter">
<constructor-arg name="pattern"
value=".+(\.(?i)(pdf|PDF|csv|CSV|xml|XML))$" />
</bean>
</list>
</constructor-arg>
</bean>
<bean id="localCompositeFilter"
class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean
class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
</list>
</constructor-arg>
</bean>
<int:chain input-channel="inboundChannel">
<int:header-enricher>
</int:header-enricher>
<int:service-activator ref="ftpListenerService"
method="onDataReceived" />
</int:chain>
FtpInboundChannelResolver.java
#Inject
private ApplicationContext applicationContext;
private final String XML_PATH = "/META-INF/integration/dynamic/ftp-inbound-listen-dynamic.xml";
#Value( "${local.ftp.storage.path}" )
private String localStoragePath ;
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
new String[] { XML_PATH }, false );
ctx.setParent( applicationContext );
StandardEnvironment env = new StandardEnvironment( );
Properties props = new Properties( );
props.setProperty( "ftp.host", "192.168.84.131" );
props.setProperty( "ftp.port", "21" );
props.setProperty( "ftp.username", "user" );
props.setProperty( "ftp.password", "pass" );
props.setProperty( "ftp.remote-directory", "/home/user/Public/files" );
props.setProperty( "ftp.local-directory", localStoragePath );
PropertiesPropertySource pps = new PropertiesPropertySource( "ftpprops", props );
env.getPropertySources( ).addLast( pps );
ctx.setEnvironment( env );
ctx.refresh( );
channel = ctx.getBean( "inboundChannel", MessageChannel.class );
FTPListnerService.java
#Service("ftpListenerService")
public class FTPListenerService implements IListenerService {
private static Logger LOGGER = LoggerFactory.getLogger(FTPListenerService.class);
#Inject
private ApplicationContext applicationContext;
public void onDataReceived( File ftpFile) {
LOGGER.info("FTP: file received for processing " );
try{
// read and delete file
String fileName = ftpFile.getName();
byte[] fileContents = FileCopyUtils.copyToByteArray(ftpFile);
ftpFile.delete();
LOGGER.error("Data Received :", fileContents);
}catch(Exception ex){
LOGGER.error("ERROR: while reading ftp transmitted file", ex);
}
}
}
here is my complete FTP Configuration but im unable to read from FTP remote directory it read from local-direstory
Please Help
That's the way it works - files are copied to the local directory and the message payload is the File object in the local directory. If the file already exists locally it is not re-fetched.

JMS - Error adding listener to the MessageConsumer

I'm trying to create a POC for JMS Queue. I used spring mvc controllers as the client to the jms. I get the following error when trying to add asynchronous listeners onto the MessageConsumer object(code snippet). I've read somewhere that the listeners can only be added to the MDB (Message driven beans), is it true?
Setup: Using websphere server bus for JMS. Added jndi for conn factory, destinations etc., for synchronous operation everything is working. But, for asynchronous, this is not working.
Used this for setting up the JMS
[1/28/14 14:38:12:570 CST] 0000005d SystemErr R javax.jms.IllegalStateException: CWSIA0084E: The method MessageConsu
mer.setMessageListener is not permitted in this container.
[1/28/14 14:38:12:572 CST] 0000005d SystemErr R at com.ibm.ws.sib.api.jms.impl.JmsMsgConsumerImpl._setMessageListen
er(JmsMsgConsumerImpl.java:660)
[1/28/14 14:38:12:573 CST] 0000005d SystemErr R at com.ibm.ws.sib.api.jms.impl.JmsMsgConsumerImpl.setMessageListene
r(JmsMsgConsumerImpl.java:609)
CODE:
public void connect(String hostName, String portNumber,
String connectionFactoryString, String consumerJNDIName)
throws Exception {
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, "iiop://" + hostName + ":" + portNumber
+ "");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext initialContext = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext
.lookup(connectionFactoryString);
connection = connectionFactory.createConnection();
connection.start();
// create destination - JMSQueue
Destination destinationReceiver = (Destination) initialContext
.lookup(consumerJNDIName);
consumerSession = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
consumer = consumerSession.createConsumer(destinationReceiver);
consumer.setMessageListener(new MessageListener() { **// ERROR here**
public void onMessage(Message msg) {
try {
System.out.println("received: " + ((TextMessage) msg).getText());
} catch (JMSException ex) {
ex.printStackTrace();
}
}
});
}
To consume messages from Queue you need only MessageListener registered in Spring context.
In web.xml you should register resource reference to JMS resources inside application server:
<resource-ref>
<res-ref-name>jms.jndi.cf.name</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>jms.jndi.queue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Next step is Spring context:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<tx:annotation-driven/>
<context:component-scan base-package="com.jms" />
<!-- Connection Factory -->
<jee:jndi-lookup id="myConnectionFactory" jndi-name="jms.jndi.cf.name" />
<!-- Queue -->
<jee:jndi-lookup id="destination" jndi-name="jms.jndi.queue.name" />
<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.DynamicDestinationResolver">
</bean>
<!-- JMS Queue Template -->
<bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="myConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="receiveTimeout">
<value>20000</value>
</property>
</bean>
<bean id="messageListener" class="com.jms.JMSMessageListener" />
<!-- Message listener container -->
<bean id="jmsConsumerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="myConnectionFactory" />
<property name="destination" ref="destination" />
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
And the final step is MessageListener:
package com.jms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import javax.jms.BytesMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
public class JMSMessageListener implements MessageListener {
private static final Logger LOGGER = LoggerFactory.getLogger(JMSMessageListener.class);
private static final String ENCODNG = "UTF-8";
#Transactional
public void onMessage(Message message) {
if (message instanceof BytesMessage) {
try {
BytesMessage bytesMessage = (BytesMessage) message;
LOGGER.debug("Receive message from Queue:\n" + bytesMessage);
byte[] data = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(data);
String stringMessagePayload = new String(data, ENCODNG);
LOGGER.debug("Message payload: \n" + stringMessagePayload);
}
} catch (Exception ex) {
LOGGER.error("Error has occured: " + ex);
throw new RuntimeException(ex);
}
} else {
throw new IllegalArgumentException("Message must be of type BytesMessage");
}
}
}
I hope this quick example will help you.

Why is this spring bean not initialised? It is always null.

I have a message factory bean configured as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="soapMessageFactory" class="javax.xml.soap.MessageFactory" factory-method="newInstance" />
<bean id="saajMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<constructor-arg ref="soapMessageFactory" />
</bean>
<bean id="myService" class="com.mypackage.TestEndPoint">
<property name="saajMessageFactory" ref="saajMessageFactory" />
</bean>
</beans>
The TestEndpoint class looks like this
#Endpoint
public class TestEndPoint {
ObjectFactory objectFactory = new ObjectFactory();
SaajSoapMessageFactory saajMessageFactory;
#PayloadRoot(namespace="http://ws.mypackage.com", localPart="downloadSaajMessageRequest")
#ResponsePayload
public JAXBElement<DownloadResponseSaajType> invoke(#RequestPayload DownloadSaajMessageRequest req, MessageContext context ) throws Exception {
DownloadResponseSaajType response = new DownloadResponseSaajType();
//DownloadResponseSaajType.PayLoad payload = new DownloadResponseSaajType.PayLoad();
DataHandler handler = new javax.activation.DataHandler(new FileDataSource("c:\\temp\\maven-feather.png"));
SaajSoapMessage message = saajMessageFactory.createWebServiceMessage();
message.addAttachment("picture", handler);
message.addAttachment("picture", handler);
//payload.setMessagePayLoad(handler);
//response.setPayLoad(payload);
response.setRequestName("NAMEOF");
context.setResponse(message);
return objectFactory.createDownloadSaajMessageResponse(response);
}
public void setSaajMessageFactory(SaajSoapMessageFactory saajMessageFactory){
this.saajMessageFactory = saajMessageFactory;
}
public SaajSoapMessageFactory getSaajMessageFactory(){
return saajMessageFactory;
}
}
I am having a few problems trying to get the endpoint to work and when i tried to debug the code i found that saajMessageFactory is never initialised and it is always null. Have i done something wrong with the configuration?
You have to add PayloadRootAnnotationMethodEndpointMapping bean to your configuration xml.
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>

Categories