QuickFIX/J - Output Logs to Text File/Console - quickfixj

I am trying to output the console messages received by 'fromApp' to a TextArea in my Swing GUI. I am trying to direct pricing logs that I am pulling. Is there a way I can direct these logs (maybe as a String) to a variable or Text file etc? This is my fromApp:
public void fromApp(quickfix.Message message, SessionID sessionID) throws FieldNotFound,
IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
}
Any ideas let me know! Thanks

Related

Spring AMQP how to access response message when connection is lost while sending using #SendTo

we have a microservice which consumes a message using #RabbitListener and persist data into database, generate a response on successful processing of message and send it using #sendTO to different queue for auditing.
When running Rabbit in HA failover, while sending response if connection is lost the message currently being processed is correctly returned to the queue but database transaction (jpa transaction in our case) is not rolled back , response is never sent.
I read from this issue(https://github.com/spring-projects/spring-amqp/issues/696) that this is "best effort 1PC" transaction synchronization; RabbitMQ does not support XA transactions. The Rabbit tx is committed after the DB tx and there is a possibility the DB tx might commit and the rabbit rolled back; you have to deal with the small possibility of duplicate messages.
But in our case when we retry request, we are treating it as duplicate message and response is never created for this request. is there a way where we can only retry sending response message in case of connection lost exceptions rather than reprocessing request again? I looked at ConditionalRejectingErrorHandler.DefaultExceptionStrategy, it has access only to original request,no way to access response lost during connection failure. Please suggest what's the best way to handle this?
our code looks like:
SpringBootApplication
#EnableJpaRepositories("com.***")
#EnableJpaAuditing
#EnableTransactionManagement
#EnableEncryptableProperties
public class PcaClinicalValidationApplication {
#RabbitListener(queues = "myqueue"
#SendTo("exchange/routingKey")
#Timed) description = "Time taken to process a request")
public Message receivemessage(HashMap<String, Object> myMap, Message requestMessage)
throws Exception {
//business logic goes here
Message message = MessageBuilder.fromMessage(requestMessage)
//add some headers
return message;
}
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory,
SimpleRabbitListenerContainerFactoryConfigurer configurer) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory);
factory.setRetryTemplate(new RetryTemplate());
factory.setReplyRecoveryCallback(ctx -> {
Message failed = SendRetryContextAccessor.getMessage(ctx);
Address replyTo = SendRetryContextAccessor.getAddress(ctx);
Throwable t = ctx.getLastThrowable();
//wrote to a file
serializer.serialize(failed);
return null;
});
return factory;
}
The listener container factory uses a RabbitTemplate in its replyTemplate property - this is used to send the reply.
You can configure a RetryTemplate into that RabbitTemplate to retry sending the reply.
When retries are exhausted, you can add a RecoveryCallback which will get the failed reply and you can save it off someplace and use it when the redelivery occurs.

Fetch message details in Spring RecoveryCallback

I'm publishing messages into RabbitMQ and I would like to track the errors when RabbitMQ is down, for this I added one RetryTemplate with the recovery callback, but the recovery callback only provides this method getLastThrowable() and I'm not sure how to provide the details of the messages that failed when RabbitMQ is down. (as per documentation "The RecoveryCallback is somewhat limited in that the retry context only contains the
lastThrowable field. For more sophisticated use cases, you should use an external
RetryTemplate so that you can convey additional information to the RecoveryCallback via
the context’s attributes") but I don't know how to do that, if anyone could help me with one example that will be awesome.
Rabbit Template
public RabbitTemplate rabbitMqTemplate(RecoveryCallback publisherRecoveryCallback) {
RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);
r.setExchange(exchangeName);
r.setRoutingKey(routingKey);
r.setConnectionFactory(rabbitConnectionFactory);
r.setMessageConverter(jsonMessageConverter());
RetryTemplate retryTemplate = new RetryTemplate();
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
backOffPolicy.setInitialInterval(500);
backOffPolicy.setMultiplier(10.0);
backOffPolicy.setMaxInterval(10000);
retryTemplate.setBackOffPolicy(backOffPolicy);
r.setRetryTemplate(retryTemplate);
r.setRecoveryCallback(publisherRecoveryCallback);
return r;
}
Recovery Callback
#Component
public class PublisherRecoveryCallback implements RecoveryCallback<AssortmentEvent> {
#Override
public AssortmentEvent recover(RetryContext context) throws Exception {
log.error("Error publising event",context.getLastThrowable());
//how to get message details here??
return null;
}
}
AMQP Outbound Adapter
return IntegrationFlows.from("eventsChannel")
.split()
.handle(Amqp.outboundAdapter(rabbitMqTemplate)
.exchangeName(exchangeName)
.confirmCorrelationExpression("payload")
.confirmAckChannel(ackChannel)
.confirmNackChannel(nackChannel)
)
.get();
The isn't possible because the function RabbitTemplate.execute() is already not aware about message you send, because it may be performed from any other method, where we might not have messages to deal:
return this.retryTemplate.execute(
(RetryCallback<T, Exception>) context -> RabbitTemplate.this.doExecute(action, connectionFactory),
(RecoveryCallback<T>) this.recoveryCallback);
What I suggest you to do is like storing message to the ThreadLocal before send and get it from there from your custom RecoveryCallback.

file in use message when trying to write out Request

I am using the code from this post IIS 7 Log Request Body so that I can see what is happening when people attempt to access my site.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
var uniqueid = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);
var logfile = String.Format("C:\\logs\\{0}.txt", uniqueid);
Request.SaveAs(logfile, true);
}
When it runs though, I am getting this message:
The process cannot access the file 'C:\logs\635256490792288683.txt' because it is being used by another process.
Every once in a while, people are having the of no response from the site and I desperately need to find out what is happening.
Any idea how to resolve this?
The resolution of DateTime.Now is not good enough for what you are trying to do. For a quick fix, you could use new Guid().ToString(); but dont do this in production, it is going to really hurt your site performance.

How to auto update/refresh in grails view/site?

I am making an xmpp webchat application in Grails. I have a message listener that can log the recieved messages in console. But how can I do this dinamycally in a website ? I am new to webapp development so please dont down vote. I am guessing Ajax but not sure.
My listener:
private MessageListener messageListener = new MessageListener() {
#Override
public void processMessage(Chat chat, Message message) {
// 'from' and 'to' fields contains senders ids, e.g.
// 17792-1028#chat.quickblox.com/mac-167
// 17744-1028#chat.quickblox.com/Smack
String from = message.getFrom().split("#")[0];
String to = message.getTo().split("#")[0];
org.jivesoftware.smack.packet.Message.Type type = message.getType();
String tajp = type.toString();
println String.format(">>> Message received (from=%s, to=%s, type=%s): %s", from, to, tajp, message.getBody())
if (onMessageReceivedListener != null) {
onMessageReceivedListener.onMessageReceived(message);
}
}
}
I suggest you to take a look on the Events Push plugin. With that you can propagate your messages and notify your clients.
You will need:
Service that notify a new message
Controller method to call this service
Ajax request to the controller, sending the user message
JavaScript to handle incoming messages
I am new to webapp development
Web development is pretty different from desktop, so I suggest you to slow down to something more easy. There's other topics on StackOverflow that will introduce you to Grails.
Also, for webdev, it's essential to know about JavaScript, CSS and HTML for your front end.

iOS Push Notification - JavaPNS - keystore.p12 file security

I am trying to use Apple's Push Notifications. I am using this tutorial here:
http://www.ibm.com/developerworks/java/library/mo-ios-push/#ibm-pcon
I am on the part where I am trying to create the Push Notification. The sample code is here:
http://code.google.com/p/javapns/wiki/PushNotificationBasic and looks like this:
import javapns.Push;
public class PushTest {
public static void main(String[] args) {
Push.alert("Hello World!", "keystore.p12", "keystore_password", false, "Your token");
}
}
I have everything set up except for the keystore.p12 part. Here is what the documentation says about keystores:
Object keystore: a reference to a keystore file, or the actual keystore content. See Preparing certificates for more information about how to create a keystore. You can pass the following objects to this parameter:
java.io.File: a direct pointer to your keystore file
java.lang.String: a path to your local keystore file
java.io.InputStream: a stream providing the bytes from a keystore
byte[]: the actual bytes of a keystore
java.security.KeyStore: an actual loaded keystore
I do not simply want to type in the path of the keystore on my computer (as they do here Getting error while sending Push Notification to iPhone using Java-PNS?) because I feel like that is unsafe.
Which of the objects should I use? My inclination says to use a java.security.KeyStore.
As a final note, this code needs to be hosted on Amazon Web Service's Elastic Beanstalk (if that matters).
---------Edit 1------------
I have tried to put in Richard J. Ross III's code. But before it is possible to learn if my .p12 file setup is correct, I first need to get around an issue concerning JavaPNS (and file structure I believe). Running the code below gives me this error: HTTP Status 404 - Servlet IosSendGameServlet is not available. When I comment out all of the JavaPNS statements, I get this error: HTTP Status 500 - javax.servlet.ServletException: Parameter recievingAppleDeviceID not found. (because I don't put in the parameters) This leads me to believe that there is a problem with the way that JavaPNS is being accessed. Maybe it is in the wrong place in my file structure? It is in the same place as servlet-api (in lib). Perhaps this is a problem with the way I upload to the AWS Elastic Beanstalk server?
package com.google.android.gcm.demo.server;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javapns.Push; //<--gets commented out to receive 500 error
import javapns.communication.exceptions.CommunicationException;//<--gets commented out to receive 500 error
import javapns.communication.exceptions.KeystoreException;//<--gets commented out to receive 500 error
public class IosSendGameServlet extends BaseServlet {
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
#Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String recievingAppleDeviceId = getParameter(req,
"recievingAppleDeviceID");
String sendingUser = getParameter(req, "sendingUser");
InputStream keyStore = this.getClass().getResourceAsStream("/sasSandbox.p12");
//everything below here gets commented out to receive 500 error
try {
Push.alert("Game with " + sendingUser + ": It's your turn!", keyStore, "mypassword", false,
recievingAppleDeviceId);
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
You should use an InputStream, and have the .p12 file in your classpath, and use like this:
InputStream keyStore = this.getClass().getResourceAsStream("nameOfMyKeystore.p12");

Resources