How to add an image to MediaModel in Hybris? - sap-commerce-cloud

I am trying to read and add an image programatically to MediaModel but not able to do.

Hot folders are based on Spring Integration project. You need some inbound-adapter to read image file, some service activator which converts image and outbound adapter that writes converter media to new folder.
<file:inbound-channel-adapter id="readFiles" directory="/path/to/data/mymedia"
filename-regex="^(.*)-(\d+)\.jpg">
<int:poller fixed-rate="1000" />
</file:inbound-channel-adapter>
<int:service-activator input-channel="readFiles" output-channel="convertedMedias" ref="someSpringBean"
method="someMethod" />
<file:outbound-gateway request-channel="convertedMedias"
directory="/path/to/data/convertedmedia" delete-source-files="true" />

Related

Receive the acknowledgement from TCP server to our application using spring Integration

Currently we are using Spring Integration 2.1.0 Release in our application.
Application flow is as below:
Some operation is performed in application and we got the output string in String via Active MQ.
I have used message-driven-channel-adapter and service-activator to read the data from queue.
That data is displayed successfully on Server(application is working as client) using tcp-outbound-gateway.
Problem is while getting the acknowledgement from server.
Created a new channel and entered in reply-channel in tcp-outbound-gateway
Passing the same channel in service-activator as input channel.
It is showing below error:
[task-scheduler-5] 2017-10-05 18:32:20,732 ERROR org.springframework.integration.handler.LoggingHandler - org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers.
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:108)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
Code is as below
<context:property-placeholder />
<!-- Gateway and connection factory setting -->
<int:channel id="telnetLandingChannel" />
<int:channel id="telnetReplyChannel" />
<beans:bean id="clientCustomSerializer"
class="com.telnet.core.serializer.CustomSerializer">
<beans:property name="terminatingChar" value="10" />
<beans:property name="maxLength" value="65535" />
</beans:bean>
<int:gateway id="gw" default-reply-channel="telnetReplyChannel" default-reply-timeout="100000"
service-interface="com.telnet.core.integration.connection.ParseTcpConfiguration$SimpleGateway"
default-request-channel="telnetLandingChannel"/>
<ip:tcp-connection-factory id="clientFactory"
type="client" host="localhost" port="7777" single-use="false" using-nio="false"
serializer="${client.serializer}" deserializer="${client.serializer}" />
<ip:tcp-outbound-gateway id="clientInGw"
request-channel="telnetLandingChannel"
connection-factory="clientFactory"
reply-channel="telnetReplyChannel"
reply-timeout="100000"/>
<!-- To send the messege over server via JMS and serviceActivator -->
<int:channel id="incidentDispatchMessageChannel" />
<int:channel id="jmsChannel" />
<beans:bean id="customClientServiceActivator"
class= "com.telnet.core.integration.CustomClientServiceActivator">
</beans:bean>
<int-jms:message-driven-channel-adapter id="incidentDispatchMessageChannelAdapter" error-channel="errorChannel"
connection-factory="mqConnectionFactory"
destination-name="${incident.processing.messaging.dispatch.queues}"
channel="incidentDispatchMessageChannel"/>
<int:service-activator id="incidentMessageActivator"
input-channel="incidentDispatchMessageChannel"
output-channel="jmsChannel"
ref="customClientServiceActivator" method="getOutboundMessage">
</int:service-activator>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="jmsChannel"
output-channel="telnetLandingChannel"/>
<!-- To receive the acknowledgement message on server via serviceActivator -->
<int:service-activator id="incidentAck"
input-channel="telnetReplyChannel"
ref="customClientServiceActivator" method="getAck">
</int:service-activator>
I have studied various article on stackverFlow but not able to get any solution
Yeah... That isn't clear by the error what channel is guilty.
On the other hand you really use very old Spring Integration version.
Would be great to consider to upgrade to the latest: http://projects.spring.io/spring-integration/.
However I think that issue is somehow around exactly that reply-channel, which you use not only for the <service-activator> but for the <int:gateway> as well.
I suggest you to remove default-reply-channel="telnetReplyChannel" from the gateway definition, remove reply-channel="telnetReplyChannel" from the <ip:tcp-outbound-gateway> definition. And let them communicate via replyChannel header populated by the gateway during request.
Regarding your <int-jms:message-driven-channel-adapter> flow which leads to the same <ip:tcp-outbound-gateway>, I would suggest to still stay with the replyChannel header but here populate it via <header-enricher> before sending message to the telnetLandingChannel. That replyChannel via <header-enricher> would be exactly an input-channel for the subsequent <int:service-activator> to handle ack from the <ip:tcp-outbound-gateway>.
I got the solution of this issue, there are multiple xmls in our code but i have added the code in one to show flow in stackOverflow.
Issue was i had defined in a xml which has only configuration part like Outbound adapter connection factory where as it should be defined in another xml where I am using service activator. Changed the place of channel definition and it worked.
I want to disconnect the TCP (as server) the moment i got the response message. As of now I am using so-timeout, so my TCP server will gets timedout after the time given in so-timeout, but requirement is to disconnect the connection the moment TCP print/display the acknowledgement. Please suggest how can I implement this.

Java 7 DSL representation for spring integration "int-jms:message-driven-channel-adapter"

I have code to read message from IBM MQ with spring integration config as below. I need to convert to Java 7 DSL using Spring integration annotations.
<bean id="inQueue" class="com.ibm.mq.jms.MQQueue" depends-on="esbQueueConnectionFactory">
<constructor-arg value="******" />
</bean>
<int:channel id="readFromChannel">
<int:interceptors>
<!-- <int:wire-tap channel="logger" /> -->
</int:interceptors>
</int:channel>
<int-jms:message-driven-channel-adapter
id="jmsInAdapter" connection-factory="esbQueueConnectionFactory"
destination="inQueue" channel="readFromChannel" />
<bean id="msgProcesser" class="com.gap.si.service.MessageProcessService" />
<int:service-activator id="servAct"
input-channel="readFromChannel" ref="msgProcesser" method="processMessage" />
If you want to use the Java DSL, see the reference manual.
Use the Jms factory class
IntegrationFlows.from(Jms.messageDriven...)
.handle(...)
.get();
If you want to use just annotations, see the Spring Integration reference manual.
The message driven adapter is simply a #Bean of type JmsMessageDrivenEndpoint which gets a listener container and a ChannelPublishingJmsMessageListener.

Spring Integration: Routing messages by percentage of messages received

How would I implement a requirement to split an existing Spring Integration based request channel to route a fixed percentage of messages to a Rabbit MQ based channel? Routing is NOT to be based on payload or header. Is there an out of the box way to specify that one out of so may should go on one channel and remaining on the other? Thanks
Here's one way...
<bean id="counter" class="java.util.concurrent.atomic.AtomicInteger" />
<int:router id="percentageRouter" input-channel="routePercentage"
expression="#counter.getAndIncrement() % 10 == 0">
<int:mapping value="true" channel="tenpercent" />
<int:mapping value="false" channel="ninetypercent" />
</int:router>

Spring Integration HTTP

Spring Integration HTTP support.
Hi I am trying channel routing based on the path attribute.
For example if the configuration is as follow
I would like to send the message to different channel based on path that is path="gateway/search" value. Had a look at header based routing and payloadtype routing. Can u please suggest the way to implement.
<!-- Inbound/Outbound Channels -->
<int:channel id="ServiceSearchRequest" />
<int:channel id="ServiceSearchResponse" />
<int-http:inbound-gateway id="inboundEmployeeSearchRequestGateway"
supported-methods="GET, POST" request-channel="ServiceSearchRequest"
reply-channel="ServiceSearchResponse"
mapped-response-headers="Content-Type"
path="ieg/Service/search" request-payload-type="java.lang.String"
reply-timeout="5000">
</int-http:inbound-gateway>
<int-http:outbound-gateway request-channel="ServiceSearchRequest"
reply-channel="ServiceSearchResponse"
url="http://localhost:8080/proj/Service/avgWaitTime123.json"
http-method="POST" expected-response-type="java.lang.String"
mapped-response-headers="Content-Type" />
It's not clear what you are asking for; you only have a single path (ieg/dataService/search) so all messages would go to a single channel if you routed on the path.
If you mean you want to route based on some query string parameter ..?foo=bar then you can add a <header/> element to the inbound gateway to capture it as a header; e.g.
<int-http:header name="foo" expression="#requestParams.foo.get(0)" />
You can then use a header value router. For a full list of variables available for header expressions, see the reference documentation (scroll down to URI Template Variables and Expressions.

Spring integration-Service activator getting called twice

Hi this is my spring integration configuration..When i hit my service using mozilla fire fox rest console two times its getting called.For example if i hit some service in service-activator (CA request activator),On certaion un predicatable scenarios it s getting called twice.I dont know whetther it is mozilla issue or configuration issue.I tried using new window but this problem persists.In first case my service activator returning xml response properly but immediately it s getting called again.Only on rare scenarios its calling twice.
<int:channel id="accountRequest" />
<int:channel id="accountResponse" />
<int:channel id="catRequestChannel" />
<int:channel id="mataccountRequest" />
<int:channel id="errorChannel"/>
<int-http:inbound-gateway id="cwebAccountManagementGateway"
supported-methods="GET, POST"
request-channel="accountRequest"
reply-channel="accountResponse"
mapped-request-headers="*"
mapped-response-headers="*"
view-name="/policies"
path="/services/{class}/{method}"
reply-timeout="50000"
error-channel="errorChannel">
<int-http:header name="serviceClass" expression="#pathVariables.class"/>
<int-http:header name="serviceMethod" expression="#pathVariables.method"/>
</int-http:inbound-gateway>
<int:header-value-router input-channel="accountRequest"
header-name="state"
default-output-channel="accountRequest" resolution-required="false">
<int:mapping value="MA"
channel="mataccountRequest" />
<int:mapping value="CA"
channel="catRequestChannel" />
</int:header-value-router>
<int:service-activator id="accountServiceActivator"
input-channel="mataccountRequest"
output-channel="accountResponse"
ref="serviceGatewayAdapter"
method="requestHandler"
send-timeout="60000"/>
<int:service-activator id="caRequestActivator"
input-channel="catRequestChannel"
output-channel="accountResponse"
ref="caServiceGatewayAdapter"
method="requestHandler"
send-timeout="60000"/>
<int:service-activator id="errorRequestActivator"
input-channel="errorChannel"
output-channel="accountResponse"
ref="errorGatewayAdapter"
method="errorHandler"
send-timeout="60000"/>
for eg:This is my url
http://localhost:9085/springintegrationsample/create?mail=15999999#mail.com&idNumber=80010600010
if i edit the mail to some other values it ll get called twice
if i change agan it s working fine.I dont understand on what scenarios its getting called twice
You are using the same "requestHandler" for both of your service activators, so its obvious it will be called twice.
You can't know which activator is called for the handler method as when you debug you can only check for the handler method being called.
To better handle this, use different a handler method for each of your service activators. Even if they are using similar operations, it will be more clear and easy to debug.
I would suggest to add channel interceptors for logging of incoming and outgoing messages just to get a better idea.
cheers

Resources