Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,21 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.5.Final</version>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>


<!--Gson-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>

<!-- ActiveMQ Artifacts -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.payment.gateway.activeMQ.config;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.payment.gateway.activeMQ.service.GatewayEventListener;
import org.apache.payment.gateway.activeMQ.util.PaymentGatewayConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.stereotype.Component;

import javax.jms.*;
import java.util.HashMap;
import java.util.Map;

@Component
public class GatewayMessagingConfig {

private Environment env;
private GatewayEventListener gatewayEventListener;
private String channelName;

private static final String DEFAULT_BROKER_URL = "tcp://localhost:61616";

private String requestQueueName;
private String responseQueueName;
private CachingConnectionFactory connectionFactory;
private ActiveMQConnectionFactory amqConnectionFactory;
private Map<String, MessageProducer> outboundQueues;
private Session producerSession;

@Autowired
public GatewayMessagingConfig(Environment env, GatewayEventListener gatewayEventListener) {
this.env = env;
this.gatewayEventListener = gatewayEventListener;
outboundQueues = new HashMap<>();

amqConnectionFactory = new ActiveMQConnectionFactory();
try {
amqConnectionFactory.setBrokerURL(DEFAULT_BROKER_URL);
amqConnectionFactory.setUserName("admin");
amqConnectionFactory.setPassword("admin");
} catch (Exception e) {
amqConnectionFactory.setBrokerURL(this.env.getProperty("brokerUrl"));
}

connectionFactory = new CachingConnectionFactory(amqConnectionFactory);
}

public void setChannelName(String channelName) {
this.channelName = channelName;
}

public void connectQueue() {
setRequestQueueName(this.channelName + "." + PaymentGatewayConstants.CHANNEL_INBOUND_USAGE);
setResponseQueueName(this.channelName + "." + PaymentGatewayConstants.CHANNEL_OUTBOUND_USAGE);

// Establish a connection for the producer.
try {

// Establish a connection for the consumer.
// Note: Consumers should not use PooledConnectionFactory.
final Connection consumerConnection = amqConnectionFactory.createConnection();
consumerConnection.start();

// Create a session.
final Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

final Destination consumerDestination = consumerSession.createQueue(getResponseQueueName());

// Create a message consumer from the session to the queue.
final MessageConsumer consumer = consumerSession.createConsumer(consumerDestination);
consumer.setMessageListener(gatewayEventListener);

// Now create the outbound queue
createOutboundQueue(getRequestQueueName());

} catch (Exception E) {

}

}

public void createOutboundQueue(String queueName) {
try {
final Connection producerConnection = connectionFactory.createConnection();
producerConnection.start();

// Create a session.
producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

final Destination producerDestination = producerSession.createQueue(queueName);

// Create a producer from the session to the queue.
final MessageProducer producer = producerSession.createProducer(producerDestination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

outboundQueues.put(queueName, producer);
} catch (JMSException E) {

}
}

public MessageProducer getMessageProducer(String queueName) {
return outboundQueues.get(queueName);
}

public Session getOutboundSession() {
return this.producerSession;
}

public String getRequestQueueName() {
return requestQueueName;
}

public void setRequestQueueName(String requestQueueName) {
this.requestQueueName = requestQueueName;
}

public String getResponseQueueName() {
return responseQueueName;
}

public void setResponseQueueName(String responseQueueName) {
this.responseQueueName = responseQueueName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.payment.gateway.activeMQ.config;

import org.apache.payment.gateway.activeMQ.util.PaymentGatewayConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class InitGatewayQueues {

@Autowired
private GatewayMessagingConfig messagingConfig;

@Autowired
private GatewayMessagingConfig gatewayMessagingConfig;


@PostConstruct
public void init() {
// We are going to initialize a single request queue and response queue, not one per payment channel
gatewayMessagingConfig.setChannelName(PaymentGatewayConstants.ACTIVEMQ_SUBSCRIBER_SERVICE_NAME);
gatewayMessagingConfig.connectQueue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.payment.gateway.activeMQ.config;

import org.apache.payment.gateway.activeMQ.util.PaymentGatewayConstants;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;

@Service
public class OutboundChannelHelper implements ApplicationContextAware {
private ApplicationContext applicationContext;
private GatewayMessagingConfig messagingConfig;

@Autowired
public OutboundChannelHelper(@Lazy GatewayMessagingConfig messagingConfig) {
this.messagingConfig = messagingConfig;
}

public void sendMessage(String channelUsage, String message) {
String channelName = PaymentGatewayConstants.ACTIVEMQ_SUBSCRIBER_SERVICE_NAME;
MessageProducer producer = messagingConfig.getMessageProducer(channelName + "." + channelUsage);
Session session = messagingConfig.getOutboundSession();

//TextMessage payload = TextMessage.withPayload(message).setHeader(PaymentGatewayConstants.CHANNEL_NAME_HEADER, channelName)
// .setHeader(PaymentGatewayConstants.CHANNEL_USAGE_HEADER, channelUsage).build();

// Send the message.
try {
producer.send(session.createTextMessage(message));
} catch (JMSException E) {

}
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.payment.gateway.activeMQ.exception;

public class ChannelNotFoundException extends Exception {

private static final long serialVersionUID = -6042248425029587199L;

public ChannelNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.payment.gateway.config.activeMq.models;
package org.apache.payment.gateway.activeMQ.models;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
Expand Down Expand Up @@ -37,4 +37,4 @@ public static ActionType fromValue(String value) {
return value.equalsIgnoreCase(DELETE.getValue()) ? DELETE : DEFAULT;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package org.apache.payment.gateway.config.activeMq.models;
package org.apache.payment.gateway.activeMQ.models;


import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.payment.gateway.config.activeMq.models;
package org.apache.payment.gateway.activeMQ.models;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Loading