In an Java agent I generate a mail. When I send this only with text then the mail is sent to the recipient. I also want to attach an xml file to the mail. If I attach it my notes server crashes.
I think my code is wrong, this is the part where I want to add the attachment to the mail:
mime = mimeRoot.createChildEntity();
MIMEHeader hdr = mime.createHeader("Content-Disposition");
hdr.setHeaderValAndParams("attachment; filename=" + OrderFilePath);
Stream stream = session.createStream();
System.out.println("Open stream");
//AT THIS IF IT WILL CRASH THE SERVER
if (stream.open(OrderFilePath, "binary")){
System.out.println("in eerste if");
if (stream.getBytes() != 0) {
System.out.println("getbytes !0 ");
mime.setContentFromBytes(stream, "application/octet-stream",MIMEEntity.ENC_IDENTITY_BINARY);
}
else System.out.println
(OrderFilePath + "has no content or is not working");
}
I have some working LotusScript code that does almost the same, with the exception of two lines:
hdr.setHeaderValAndParams("attachment; filename=\\"" + OrderFilePath + "\\"");
and
mime.setContentFromBytes(stream, "application/octet-stream; name=\\"" + OrderFilePath + "\\"",MIMEEntity.ENC_IDENTITY_BINARY);
My LS code, so yo can see for yourself:
ForAll att In attachments
disposition= "attachment"
If att.isInLine Then disposition= "inline"
Set sect = body.createChildEntity()
Call sect.CreateHeader("Content-Disposition").SetHeaderValAndParams(disposition + {; filename="} & att.attName & {";"} )
Call sect.CreateHeader("Content-ID").SetHeaderVal( |<| & ListTag(att) & |>| )
Set stream = session.CreateStream
If stream.Open(att.attFile) Then
Call sect.SetContentFromBytes(stream, strContentType & {; name="} & att.attName & {"}, ENC_IDENTITY_BINARY)
Call stream.Close
End If
End Forall
attachments is a list of Attachment objects that contain only the name and the filepath of an attachment; it isn't a full Notes attachment embedded object thing.
Related
I am reading and processing 2 files from 2 different file locations and comparing the content.
If 2nd file is not available , the rest of the process execute with 1st file. If 2nd file is available, comparison process should happen. For this I am using camel pollEnrich, but here the problem is that, camel is picking the 2nd file at first time only. Without restarting the camel route 2nd file is not getting picked up even if it is present there.
After restarting the camel route it is working fine, but after that its not picking the 2nd file.
I am moving the files to different locations after processing it.
Below is my piece of code,
from("sftp:" + firstFileLocation + "?privateKeyFile=" + ppkFileLocation + "&username=" + sftpUsername
+ "&readLock=changed&idempotent=true&move=" + firstFileArchiveLocation)
.pollEnrich("sftp:" + secondFileLocation + "?privateKeyFile=" + ppkFileLocation + "&username=" + sftpUsername
+ "&readLock=changed&idempotent=true&fileExist=Ignore&move="+ secondFileLocationArchive ,10000,new FileAggregationStrategy())
.routeId("READ_INPUT_FILE_ROUTE")
Need help.
You're setting idempotent=true in the sftp consumer, which means camel will not process the same file name twice. Since you're moving the files, it would make sense to set idempotent=false.
Quoted from camel documentation
Option to use the Idempotent Consumer EIP pattern to let Camel skip
already processed files. Will by default use a memory based LRUCache
that holds 1000 entries. If noop=true then idempotent will be enabled
as well to avoid consuming the same files over and over again.
I'm adding an alternative solution based on comments for the answer posted by Jeremy Ross. My answer is based on the following code example. I've only added the configure() method in the test route for brevity.
#Override
public void configure() throws Exception {
String firstFileLocation = "//127.0.0.1/Folder1";
String secondFileLocation = "//127.0.0.1/Folder2";
String ppkFileLocation = "./key.pem";
String sftpUsername = "user";
String sftpPassword = "xxxxxx";
String firstFileArchiveLocation = "./Archive1";
String secondFileLocationArchive = "./Archive2";
IdempotentRepository repository1 = MemoryIdempotentRepository.memoryIdempotentRepository(1000);
IdempotentRepository repository2 = MemoryIdempotentRepository.memoryIdempotentRepository(1000);
getCamelContext().getRegistry().bind("REPO1", repository1);
getCamelContext().getRegistry().bind("REPO2", repository2);
from("sftp:" + firstFileLocation
+ "?password=" + sftpPassword + "&username=" + sftpUsername
+ "&readLock=idempotent&idempotent=true&idempotentKey=\\${file:name}-\\${file:size}-\\${file:modified}" +
"&idempotentRepository=#REPO1&stepwise=true&download=true&delay=10&move=" + firstFileArchiveLocation)
.to("direct:combined");
from("sftp:" + secondFileLocation
+ "?password=" + sftpPassword + "&username=" + sftpUsername
+ "&readLock=idempotent&idempotent=true&idempotentKey=\\${file:name}-\\${file:size}-\\${file:modified}" +
"&idempotentRepository=#REPO2" +
"&stepwise=true&delay=10&move=" + secondFileLocationArchive)
.to("direct:combined");
from("direct:combined")
.aggregate(constant(true), (oldExchange, newExchange) -> {
if (oldExchange == null) {
oldExchange = newExchange;
}
String fileName = (String) newExchange.getIn().getHeaders().get("CamelFileName");
String filePath = (String) newExchange.getIn().getHeaders().get("CamelFileAbsolutePath");
if (filePath.contains("Folder1")) {
oldExchange.getIn().setHeader("File1", fileName);
} else {
oldExchange.getIn().setHeader("File2", fileName);
}
String file1Name = oldExchange.getIn().getHeader("File1", String.class);
String file2Name = oldExchange.getIn().getHeader("File2", String.class);
if (file1Name != null && file2Name != null) {
// Compare files
// Both files are available
oldExchange.getIn().setHeader("PROCEED", true);
} else if (file1Name != null) {
// No comparison, proceed with File 1
oldExchange.getIn().setHeader("PROCEED", true);
} else {
// Do not proceed, keep file 2 data and wait for File 1
oldExchange.getIn().setHeader("PROCEED", false);
}
String fileName1 = oldExchange.getIn().getHeader("File1", String.class);
String fileName2 = oldExchange.getIn().getHeader("File2", String.class);
oldExchange.getIn().setBody("File1: " + fileName1 + " File2: " + fileName2);
System.out.println(oldExchange);
return oldExchange;
}).completion(exchange -> {
if(exchange.getIn().getHeader("PROCEED", Boolean.class)) {
exchange.getIn().removeHeader("File1");
exchange.getIn().removeHeader("File2");
return true;
}
return false;
}).to("log:Test");
}
In this solution, two SFTP consumers were used, instead of pollEnrich, since we need to capture the file changes of both SFTP locations. I have used an idempotent repository and an idempotent key for ignoring duplicates. Further, I've used the same idempotent repository as the lock store assuming only camel routes are accessing the files.
After receiving the files from SFTP consumers, they are sent to the direct:combined producer, which then routes the exchange to an aggregator.
In the example aggregator strategy I have provided, you can see, that the file names are being stored in the exchange headers. According to the file information retrieved from the headers, the aggregator can decide how to process the file and whether or not to proceed with the exchange. (If only file2 is received, the exchange should not proceed to the next stages/routes)
Finally, the completion predicate expression decides whether or not to proceed with the exchange and log the exchange body, based on the headers set by the aggregator. I have added an example clean-up process in the predicate expression processor as well.
Hope you will get the basic idea of my suggestion to use an aggregator from this example.
Does anyone have an example of retrieving data using Actian's JCL to a loosely coupled pervasive database in Java? The database I am connecting to only has DAT files. My goal is to create a link between pervasive and MS SQL.
I am not looking for a freebie, but someone to point me in the right direction so I can learn and grow.
Thank you in advanced!
Found this in my archives. Don't know when it was written, whether it works, or if this interface is still supported. You don't say what version of PSQL you're using so I don't even know if this will work with your version.
import pervasive.database.*;
public class VersionTest implements Consts
{
public VersionTest()
{
try
{
Session session = Driver.establishSession();
Database db = session.connectToDatabase("PMKE:");
XCursor xcursor = db.createXCursor(57000);
//Using local TABL.DAT (length 255 assures no leftovers!)
xcursor.setKZString(0,255,"plsetup\\tabl.dat");
//Open the file to load local MKDE
int status = xcursor.BTRV(BTR_OPEN);
System.out.println("Local Open status: " + status);
//Using remote TABL.DAT (length 255 assures no leftovers!)
xcursor.setKZString(0,255,"h:\\basic2c\\develop\\tabl.dat");
//set the buffer size
xcursor.setDataSize(15);
//get version
status = xcursor.BTRV(BTR_VERSION);
System.out.println("Version status: " + status);
// should be 15, always prints 5
System.out.println("Version length: " + xcursor.getRecLength());
System.out.println("Version: " + xcursor.getDString(0,15));
// try with an open file on a server
XCursor xcursor2 = db.createXCursor(57000);
//Using remote TABL.DAT (length 255 assures no leftovers!)
xcursor2.setKZString(0,255,"h:\\basic2c\\develop\\tabl.dat");
//Open the file
status = xcursor2.BTRV(BTR_OPEN);
System.out.println("Remote Open status: " + status);
//set the buffer size
xcursor2.setDataSize(15);
//get version
status = xcursor2.BTRV(BTR_VERSION);
System.out.println("Version status: " + status);
// should be 15, always prints 5
System.out.println("Version length: " + xcursor2.getRecLength());
System.out.println("Version: " + xcursor2.getDString(0,15));
// clean up resources
Driver.killAllSessions();
}catch(Exception exp)
{
exp.printStackTrace();
}
}
public static void main(String[] args)
{
new VersionTest();
}
}
JCL APIs are still supported with Actian PSQL v12 and v13.
You can find more documentation on retrieving data using Actian JCL at
http://docs.pervasive.com/products/database/psqlv12/wwhelp/wwhimpl/js/html/wwhelp.htm#href=jcl/java_api.2.2.html
To link to MS Sql Server you would need to create the data dictionary files(DDFs) for the PSQl data files to use with relational interfaces.
im wondering if there is any other way to read out the TeamSpeak Channel Chat with java.
I know that you could use a lua plugin which opens tha java program with the messages as parameter.
The code for the Lua Plugin's event.lua file: (could be outdated)
local function onTextMessageEvent(serverConnectionHandlerID, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored)
print("Testmodule: onTextMessageEvent: " .. serverConnectionHandlerID .. " " .. targetMode .. " " .. toID .. " " .. fromID .. " " .. fromName .. " " .. fromUniqueIdentifier .. " " .. message .. " " .. ffIgnored)
if targetMode == 2 then
os.execute("Program.exe " .. '"' .. message .. '"')
if message == "!command#1" or message == "!command#2" or message == "!command#3" then
folder = os.getenv("APPDATA")
file = io.open(folder .. "/" .. "tmp.txt", "r")
tempfile = file:read("*all")
file:close()
os.remove(folder .. "/" .. "tmp.txt")
ts3.requestSendChannelTextMsg(serverConnectionHandlerID, tempfile, fromID)
end
end
return 0
end
Basicly the Program.exe creates the tmp.txt file and writes the specified (inside the Program.exe) answer to the file which is sent to the chat by the lua plugin.
Now i want to know if there is any way to get the messages directly with java (so that the lua plugin isn't needed anymore)
I'm thankful for any help
I found out that you can simply scan the channel & server chatlogs for new entrys.
The Logs can be found here:
%APPDATA%\Roaming\TS3Client\chats\<UniqueServerID>
Unfortunately i have no idea how the UniqueServerID is generated and where the private chatlogs can be found.
I’m using FreePBX with Asterisk’s Java API.
For the moment, I’m able to display all my SIP peers with their respective states:
public void onManagerEvent(ManagerEvent event)
{
// Look if the event is a IP phone (Peer entry)
if(event instanceof PeerEntryEvent)
{
PeerEntryEvent ev = (PeerEntryEvent)event;
// Get the user extension
peer = ev.getObjectName();
// Add to the array
peersName.add(peer);
}
}
I’m able to display the phone number and name of both callers when a channel is open:
private String GetExtensionPeer(String extension)
{
for (AsteriskChannel e : channels)
if (e.number.equals(extension) && e.bridge != null )
for (AsteriskChannel channel : channels)
if (z.channel.equals(e.bridge))
return " with " + channel.number + " - " + channel.name;
return "";
}
But now, I would like to display the name of my extensions without a channel connection.
In FreePBX's panel, it's look like :
In freepbx you can get list of extensions from asterisk db. To see info, do
asterisk -rx "database show"
To get info use manager action "command" with DBGET.
Other option - got that info from freepbx's mysql db.
First of all, I'll admit I am new to this and I've probably just forgotten to set an option somewhere to the correct variable, but my Googling has failed me and I have no idea what to do, so I was hoping to get some help.
I have based this on the SecureChat example, it can be located here: http://netty.io/docs/unstable/xref/org/jboss/netty/example/securechat/package-summary.html
And the difference I have made, have been only in the SecureChatServerHandler. More precisely in the messageRecieved block:
#Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
// Convert the message to a string
String request = (String) e.getMessage();
System.out.println("Message recieved: " + request);
if (request.equalsIgnoreCase("clients")) {
channels.write("We currently have: " + channels.size() + " clients");
} else if (request.toLowerCase().equals("koko"))
for (Channel c : channels) {
if (c == e.getChannel())
c.write("HELLO WORLD");
}
else {
// Then send it to all channels, but the current one.
for (Channel c : channels)
if (c != e.getChannel())
c.write("[" + e.getChannel().getRemoteAddress() + "] " + request + "\n");
else
c.write("[you] " + request + "\n");
}
if (request.equalsIgnoreCase("bye"))
e.getChannel().close();
}
If I send a normal message that is getting broadcasted, everything works. But if I send a command, like clients or koko, I get no response, until I press enter again and send a empty message. First then I get the response back.
C:\Device Manager\Application Server\Examp
les\SecureChat\SecureChatClient\bin>java -jar client.jar 127.0.0.1 8080
UNKNOWN SERVER CERTIFICATE: CN=securechat.example.netty.gleamynode.net, OU=Contr
ibutors, O=The Netty Project, L=Seongnam-si, ST=Kyunggi-do, C=KR
Welcome to Electus secure chat service!
Your session is protected by TLS_DHE_RSA_WITH_AES_128_CBC_SHA cipher suite
You are the 1th user
koko<ENTER>
<PRESS ENTER AGAIN>
HELLO WORLD[you]
clients<ENTER>
<AND ENTER ONCE AGAIN>
We currently have: 1 clients[you]
What I don't understand, and don't want, is the -pressing of enter button twice- thing. It seems highly inlogical and it is irritating. I didn't have these problem with the Telnet Example.
Thank you for your time.
Regards,
Aldrian.
This is one of those humiliating times where you just forgot one small detail, and that messes everything up.
if (request.equalsIgnoreCase("clients")) {
channels.write("We currently have: " + channels.size() + " clients /n"); // Forgot /n here
} else if (request.toLowerCase().equals("koko"))
for (Channel c : channels) {
if (c == e.getChannel())
c.write("HELLO WORLD /n"); // <- Forgot /n here as well
}