how receive data from apple server notification in spring boot project - in-app-purchase

how to define the endpoint on spring boot server to receive server notification after read the app doc, this is what I am doing now:
#Api
#RequestMapping("/post/notification")
#FeignClient(name = "dolphin-post-service")
#Validated
public interface IAppleServerNotificationController {
/**
* Receive Apple Server Notification
* #param
* #return
*/
#PostMapping("/v1/appleSeverNotification")
Response<Integer> handleNotification(#RequestBody #Valid ServerNotificationRequest request);
}
and this is the entity I am define:
#Data
#NoArgsConstructor
#JsonIgnoreProperties(ignoreUnknown = true)
public class ServerNotificationRequest implements Serializable {
#ApiModelProperty(value = "responseBody")
#NonNull
private String responseBody;
}
but It seems not work. where I am going wrong? Any suggestion?
#Override
#NoCheck
public Response<Integer> handleNotification(ServerNotificationRequest request) {
JSONObject jsonResult = JSONObject.parseObject(request.getResponseBody());
AppleServerNotificationRecord record = new AppleServerNotificationRecord();
record.setResponseBody(request.getResponseBody());
record.setNotificationType(jsonResult.getString("notification_type"));
int result = notificationRecordService.saveNotificationRecord(record);
return new Response<>(result);
}
the responseBody is null!!!

define the request entity like this:
#Data
#NoArgsConstructor
#JsonIgnoreProperties(ignoreUnknown = true)
public class ServerNotificationRequest implements Serializable {
#ApiModelProperty(value = "auto_renew_adam_id")
#JsonProperty("auto_renew_adam_id")
private String autoRenewAdamId;
#ApiModelProperty(value = "auto_renew_product_id")
#JsonProperty("auto_renew_product_id")
private String autoRenewProductId;
#ApiModelProperty(value = "auto_renew_status")
#JsonProperty("auto_renew_status")
private String autoRenewStatus;
#ApiModelProperty(value = "auto_renew_status_change_date")
#JsonProperty("auto_renew_status_change_date")
private String autoRenewStatusChangeDate;
#ApiModelProperty(value = "auto_renew_status_change_date_ms")
#JsonProperty("auto_renew_status_change_date_ms")
private String autoRenewStatusChangeDateMs;
#ApiModelProperty(value = "auto_renew_status_change_date_pst")
#JsonProperty("auto_renew_status_change_date_pst")
private String autoRenewStatusChangeDatePst;
#ApiModelProperty(value = "environment")
private String environment;
#ApiModelProperty(value = "expiration_intent")
#JsonProperty("expiration_intent")
private Integer expirationIntent;
#ApiModelProperty(value = "notification_type")
#JsonProperty("notification_type")
private String notificationType;
#ApiModelProperty(value = "password")
#JsonProperty("password")
private String sharedSecret;
//#ApiModelProperty(value = "unified_receipt")
//#JsonProperty("unified_receipt")
//private String unifiedReceipt;
#ApiModelProperty(value = "bid")
private String bid;
#ApiModelProperty(value = "bvrs")
private String bvrs;
}

Related

Springboot RabbitMq no consumer connected

I'm using springboot and rabbitmq to receive a message.
The first consumer i created works, declared as below:
#Component
public class UserConsumer {
#Autowired
private RabbitTemplate template;
#RabbitListener(queues = MessagingConfig.CONSUME_QUEUE)
public void consumeMessageFromQueue(MassTransitRequest userRequest) {
...
}
}
I then needed a second consumer so i duplicated the above and called it another name:
#Component
public class PackConsumer {
#Autowired
private RabbitTemplate template;
#RabbitListener(queues = MessagingConfig.CONSUME_QUEUE_CREATE_PACK)
public void consumeMessageFromQueue(MassTransitRequest fileRequest) {
...
}
}
Everything works locally on my machine, however when i deploy it the new queue does not process messages because there is no consumer connected to it. The UserConsumer continues to work.
Is there something else i should be doing in order to connect to the new queue at the same time as the original?
During my learning i did add a "MessagingConfig" class as below, however i believe it relates to sending messages and not receiving them or an alternative configuration:
#Configuration
public class MessagingConfig {
public static final String CONSUME_QUEUE = "merge-document-request";
public static final String CONSUME_EXCHANGE = "merge-document-request";
public static final String CONSUME_ROUTING_KEY = "";
public static final String PUBLISH_QUEUE = "merge-document-response";
public static final String PUBLISH_EXCHANGE = "merge-document-response";
public static final String PUBLISH_ROUTING_KEY = "";
public static final String CONSUME_QUEUE_CREATE_PACK = "create-pack-request";
public static final String CONSUME_EXCHANGE_CREATE_PACK = "create-pack-request";
public static final String CONSUME_ROUTING_KEY_CREATE_PACK = "";
public static final String PUBLISH_QUEUE_CREATE_PACK = "create-pack-response";
public static final String PUBLISH_EXCHANGE_CREATE_PACK = "create-pack-response";
public static final String PUBLISH_ROUTING_KEY_CREATE_PACK = "";
#Bean
public Queue queue() {
return new Queue(CONSUME_QUEUE);
}
#Bean
public TopicExchange exchange() {
return new TopicExchange(CONSUME_EXCHANGE);
}
#Bean
public Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(CONSUME_ROUTING_KEY);
}
#Bean
public MessageConverter converter() {
return new Jackson2JsonMessageConverter();
}
#Bean
public AmqpTemplate template(ConnectionFactory connectionFactory) {
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(converter());
return rabbitTemplate;
}
}
Thanks in advance

JAXB parse taken up xml attributes

I'm trying to parse following part of xml. There are two "location" tags. And the second one has taken up attributes. But I can't set JAXB correctly the second class does not set properties. Is there also way to simplify the code using lombook, but keeping fields as private.
<location>
<name>London</name>
<type/>
<country>GB</country>
<timezone/>
<location altitude="0" latitude="51.5085" longitude="-0.1258" geobase="geonames" geobaseid="2643743"/>
</location>
Here is the outer Location class:
#Data
#XmlRootElement(name = "location")
class Location implements Serializable {
private String name;
private String type;
private String country;
private String timezone;
private GeoLocation geoLocation;
#XmlElement(name = "location")
public void setGeoLocation(GeoLocation geoLocation) {
this.geoLocation = geoLocation;
}
}
And the second-one class:
#Data
#XmlRootElement(name = "location")
class GeoLocation { //Ineer location
private String _altitude;
private double _latitude;
private double _longitude;
private String _geobase;
private int _geobaseid;
#XmlElement(name = "altitude")
public void set_altitude(String _altitude) {
this._altitude = _altitude;
}
#XmlElement(name = "latitude")
public void set_latitude(double _latitude) {
this._latitude = _latitude;
}
#XmlElement(name = "longitude")
public void set_longitude(double _longitude) {
this._longitude = _longitude;
}
#XmlElement(name = "geobase")
public void set_geobase(String _geobase) {
this._geobase = _geobase;
}
#XmlElement(name = "geobaseid")
public void set_geobaseid(int _geobaseid) {
this._geobaseid = _geobaseid;
}
}
#Data
#XmlRootElement(name = "location")
#XmlAccessorType(XmlAccessType.FIELD)
class Location implements Serializable {
private String name;
private String type;
private String country;
private String timezone;
#XmlElement(name = "location")
private GeoLocation geoLocation;
}
#Data
#XmlRootElement(name = "location")
#XmlAccessorType(XmlAccessType.FIELD)
class GeoLocation { //Ineer location
#XmlAttribute(name = "altitude")
private String _altitude;
#XmlAttribute(name = "latitude")
private double _latitude;
#XmlAttribute(name = "longitude")
private double _longitude;
#XmlAttribute(name = "geobase")
private String _geobase;
#XmlAttribute(name = "geobaseid")
private int _geobaseid;
}

SDN 4 doesn't create relationship with properties

I am new to Neo4J. I have built a project that uses spring-data-neo4j (4.0.0.BUILD-SNAPSHOT - version), spring-boot (1.2.3.RELEASE - version) and succeeded to create node entities, add properties to node entities and add relationships. It works fine. Now I want to create properties for the relationships. I have used sdn4 university as a reference, here is the link https://github.com/neo4j-examples/sdn4-university .
I want to create a property called "challengedBy" for relationship PLAY_MATCH (Start node is Match and end node is Player). You can have a look on below class.
#RelationshipEntity(type = "PLAY_MATCH")
public class PlayMatch extends Entity {
//Entity is a class with the id property for the node / relationship
#Property
private String challengedBy;
#StartNode
private Match match;
#EndNode
private Player player1;
}
I have created a controller in the project /api/playmatch to create only the relationship between match and a player. So when I pass the values for an existing match node and a player node, the relationship is not created at all.
Any help will be appreciated..
PlayMatch code is
#RelationshipEntity(type = "PLAY_MATCH")
public class PlayMatch extends Entity{
#Property
private String challengedBy;
#StartNode
private Match match;
#EndNode
private Player player1;
public PlayMatch() {
}
public PlayMatch(String challengedBy, Match match,
Player player1) {
super();
this.challengedBy = challengedBy;
this.match = match;
this.player1 = player1;
}
// after this i have getters & setters and toString method for above fields.
}
Match code is
#NodeEntity(label = "Match")
public class Match extends Entity {
private String createdBy;
private Long createdTime;
private String status;
private int noOfGames;
private int noOfPoints;
private String type;
private Long date;
#Relationship(type="PLAY_MATCH",direction= Relationship.UNDIRECTED)
private PlayMatch playMatch;
public Match() {
}
public Match(String createdBy, Long createdTime, String status,
int noOfGames, int noOfPoints, String type, Long date) {
super();
this.createdBy = createdBy;
this.createdTime = createdTime;
this.status = status;
this.noOfGames = noOfGames;
this.noOfPoints = noOfPoints;
this.type = type;
this.date = date;
}
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
// after this i have getters & setters and toString method for above fields.
}
Player code is
#NodeEntity(label = "Player")
public class Player extends Entity {
private String address;
private String preferredSport;
private float height;
private float weight;
private String phone;
private String photo;
#Relationship(type="PLAY_MATCH")
private PlayMatch playMatch;
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
public Player() {
}
public Player(String address, String preferredSport, float height,
float weight, String phone, String photo) {
super();
this.address = address;
this.preferredSport = preferredSport;
this.height = height;
this.weight = weight;
this.phone = phone;
this.photo = photo;
}
// after this i have getters & setters and toString method for above fields.
}
I think you have playmatch relationship within the player end node as well. If you comment the following code in the player node. It should work. I have also attached a json sample to pass from the UI in the match URL (/api/match) instead of (/api/playmatch)
#Relationship(type="PLAY_MATCH")
private PlayMatch playMatch;
public PlayMatch getPlayMatch() {
return playMatch;
}
public void setPlayMatch(PlayMatch playMatch) {
this.playMatch = playMatch;
}
Sample JSON
{
"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19,
"playMatch": {"challengedBy" : "John", "player1" : {"id":732}, "match":{"type": "typename",
"status": "statusname",
"createdTime": 1435928223021,
"noOfGames": 5,
"noOfPoints": 19}}
}
this should create a new match and a new relationship with property challengedBy to an existing player node with id 732.
check it out and let me know if this works.

Neo4j slow saving

I am using neo4j version 1.8.1 and spring-data-neo4j version 2.2.0. RELEASE.
The problem is about neo4j saving speed. I could not realize why this happens. The node is persisting into db for about 30 second. Here is my model class.
#NodeEntity
public class GraphUser {
public static final String FACEBOOK_FRIEND = "FACEBOOK_FRIEND";
public static final String TWITTER_FOLLOW = "TWITTER_FOLLOW";
public static final String CONTACT = "CONTACT";
public static final String KNOWS = "KNOWS";
public static final String BLOCKED = "BLOCKED";
public static final String FAVORITE = "FAVORITE";
#GraphId
private Long id;
#Indexed(unique = true, indexType = IndexType.FULLTEXT, indexName = "userIdIndex")
private String userId;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "facebookIdIndex")
private String facebookId;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "twitterIdIndex")
private String twitterId;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "emailIndex")
private String email;
#Indexed(indexType = IndexType.FULLTEXT, indexName = "phoneNumberIndex")
private String phoneNumber;
private String knowsLevel;
#RelatedTo(type = FACEBOOK_FRIEND, direction = Direction.BOTH)
#Fetch
private Set<GraphUser> facebookRelations = new HashSet<GraphUser>();
#RelatedTo(type = TWITTER_FOLLOW, direction = Direction.OUTGOING)
#Fetch
private Set<GraphUser> twitterRelations = new HashSet<GraphUser>();
#RelatedTo(type = CONTACT, direction = Direction.OUTGOING)
#Fetch
private Set<GraphUser> contacts = new HashSet<GraphUser>();
#RelatedTo(type = KNOWS, direction = Direction.OUTGOING)
#Fetch
private Set<GraphUser> knows = new HashSet<GraphUser>();
#RelatedTo(type = BLOCKED, direction = Direction.OUTGOING)
#Fetch
private Set<GraphUser> blocks = new HashSet<GraphUser>();
#RelatedTo(type = FAVORITE, direction = Direction.OUTGOING)
#Fetch
private Set<GraphUser> favorites = new HashSet<GraphUser>();
#Query(value = "start user=node({self}), user2=node(*), matchedUser=node(*) " +
"where has(user2.userId) and has(matchedUser.userId) and has(user.knowsLevel) and has(user2.knowsLevel) and has(matchedUser.knowsLevel) " +
"and " +
"user.userId<>matchedUser.userId " +
"and " +
"(" +
"(user.knowsLevel='ALL' and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
"or " +
"(user.knowsLevel='SECOND' and ((user)-[:KNOWS]->(matchedUser) or (user)-[:KNOWS]->(user2)-[:KNOWS]->(matchedUser)) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND'))) " +
"or " +
"(user.knowsLevel='FIRST' and (user)-[:KNOWS]->(matchedUser) and (matchedUser.knowsLevel='ALL' or (user)<-[:KNOWS]-(matchedUser) or ((user)<-[:KNOWS]-(user2)<-[:KNOWS]-(matchedUser) and matchedUser.knowsLevel='SECOND')))" +
") " +
"return matchedUser")
#Fetch
private Iterable<GraphUser> matchedUsers;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public String getTwitterId() {
return twitterId;
}
public void setTwitterId(String twitterId) {
this.twitterId = twitterId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getKnowsLevel() {
return knowsLevel;
}
public void setKnowsLevel(String knowsLevel) {
this.knowsLevel = knowsLevel;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Set<GraphUser> getFacebookRelations() {
return facebookRelations;
}
public void setFacebookRelations(Set<GraphUser> facebookRelations) {
this.facebookRelations = facebookRelations;
}
public Set<GraphUser> getTwitterRelations() {
return twitterRelations;
}
public void setTwitterRelations(Set<GraphUser> twitterRelations) {
this.twitterRelations = twitterRelations;
}
public Set<GraphUser> getContacts() {
return contacts;
}
public void setContacts(Set<GraphUser> contacts) {
this.contacts = contacts;
}
public Set<GraphUser> getKnows() {
return knows;
}
public void setKnows(Set<GraphUser> knows) {
this.knows = knows;
}
public Set<GraphUser> getBlocks() {
return blocks;
}
public void setBlocks(Set<GraphUser> blocks) {
this.blocks = blocks;
}
public Set<GraphUser> getFavorites() {
return favorites;
}
public void setFavorites(Set<GraphUser> favorites) {
this.favorites = favorites;
}
}
What may I be missing ?
Thank you.
Two suspects
Indexes: I see you have around 5 indexes. Write takes longer when you have more indexes as the write should also update the index as part of the transaction.
Eager Fetch: I see you have around 6 relationships that you annotated with #Fetch. I believe spring-data-neo4j tries to re-fetch everything after the commit. And if these relationships/nodes have #Fetch for their own properties annotated with #Fetch then they are recursively fetched.
I suggest you start testing this by first removing #Fetch and then #Index and see if that improves performance. Are you also doing batch inserts?

JSF backing bean sets the property to null

I am trying access the form backing bean data from by controller bean. The value from form
gets set in the bean but when i am trying to access it from the controller bean the value comes null.The null value is in createTicket method :---> ticketData.getSummary());
/*from data bean everything sets here*/
import java.io.Serializable;
import java.util.Date;
import java.util.List;
#SuppressWarnings("PMD")
#ManagedBean(name = "createTicketModelData")
#SessionScoped
public class CreateTicketModelData implements CreateTicketData, Serializable {
private static final long serialVersionUID = 1L;
protected String incidentType;
private TicketId ticketId;
protected UserId receiverId;
protected String summary;
private String description;
private String asset;
private Date dateTime;
protected Date reported;
private Date dateChangeNeeded;
private String priority;
protected List<Attachment> attachments;
public void setAttachments(final List<Attachment> attachments) {
this.attachments = attachments;
}
protected String orgUnit;
protected String location;
protected String costCenter;
private Type type = Type.INCIDENT;
private String severity;
#Override
public String getAsset() {
return asset;
}
#Override
public List<Attachment> getAttachments() {
return attachments;
}
public String getCostCenter() {
return costCenter;
}
.....//getter seters
----------------------------------------------------------------------
/*this is the controller bean where i am not able to get the form data values*/
#ManagedBean(name = "createTicketBaseBean")
#SessionScoped
public class CreateTicketBaseBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final transient Logger LOGGER = LoggerFactory.getLogger(CreateTicketBaseBean.class);
#ManagedProperty(value = "#{ticketData}")
private transient CreateTicketModelData ticketData;
#ManagedProperty(value = "#{ticketingService}")
transient TicketingService dispatcher;
#PostConstruct
protected void init() {
this.workplaceBean = JSFUtils.findBean("selectWorkplaceComponentBean");
this.selectUserBean = JSFUtils.findBean("selectUserBean");
}
public void createTicket(final ActionEvent event) {
Response response = null;
System.out.println("ticket summary------------" + ticketData.getSummary());
setTicketData();
LOGGER.info("Incident type in ticketdatabean---->" + incidentType);
try {
response = dispatcher.createTicket(ticketData);
} catch (Exception e) {
LOGGER.error(e);
FacesMessageUtil.addGlobalUnexpectedErrorMessage();
}
LOGGER.info("Response is---->" + response.getTicketId());
ticketId = response.getTicketId();
}
Try changing the value in the annotation #ManagedProperty(value = "#{ticketData}") to use the bean name that you have annotated it with "createTicketModelData".

Resources