use of java.rmi.server.UID in project camel by apache.
the class JavaSpaceProducer method process.
public void process(Exchange exchange) throws Exception {
Entry entry;
Object body = exchange.getIn().getBody();
if (!(body instanceof Entry)) {
entry = new InEntry();
if (body instanceof BeanInvocation) {
((InEntry) entry).correlationId = (new UID()).toString();
}
if (body instanceof byte[]) {
((InEntry) entry).binary = true;
((InEntry) entry).buffer = (byte[]) body;
} else {
((InEntry) entry).binary = false;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(body);
((InEntry) entry).buffer = bos.toByteArray();
}
} else {
entry = (Entry) body;
}
Transaction tnx = null;
if (transactionHelper != null) {
tnx = transactionHelper.getJiniTransaction(transactionTimeout).transaction;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Writing body : " + entry);
}
javaSpace.write(entry, tnx, Lease.FOREVER);
if (ExchangeHelper.isOutCapable(exchange)) {
OutEntry tmpl = new OutEntry();
tmpl.correlationId = ((InEntry) entry).correlationId;
OutEntry replyCamelEntry = null;
while (replyCamelEntry == null) {
replyCamelEntry = (OutEntry) javaSpace.take(tmpl, tnx, 100);
}
Object obj;
if (replyCamelEntry.binary) {
obj = replyCamelEntry.buffer;
} else {
ByteArrayInputStream bis = new ByteArrayInputStream(replyCamelEntry.buffer);
ObjectInputStream ois = new ObjectInputStream(bis);
obj = ois.readObject();
}
exchange.getOut().setBody(obj);
}
if (tnx != null) {
tnx.commit();
}
}
use of java.rmi.server.UID in project hive by apache.
the class TestGenericAvroRecordWritable method writableContractIsImplementedCorrectly.
@Test
public void writableContractIsImplementedCorrectly() throws IOException {
Schema schema = AvroSerdeUtils.getSchemaFor(schemaJSON);
GenericRecord gr = new GenericData.Record(schema);
gr.put("first", "The");
gr.put("last", "Doctor");
assertEquals("The", gr.get("first"));
assertEquals("Doctor", gr.get("last"));
AvroGenericRecordWritable garw = new AvroGenericRecordWritable(gr);
garw.setFileSchema(gr.getSchema());
garw.setRecordReaderID(new UID());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
garw.write(daos);
AvroGenericRecordWritable garw2 = new AvroGenericRecordWritable(gr);
garw.setFileSchema(gr.getSchema());
garw2.setRecordReaderID(new UID());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dais = new DataInputStream(bais);
garw2.readFields(dais);
GenericRecord gr2 = garw2.getRecord();
assertEquals("The", gr2.get("first").toString());
assertEquals("Doctor", gr2.get("last").toString());
}
use of java.rmi.server.UID in project Openfire by igniterealtime.
the class SendMail method sendMessage.
public boolean sendMessage(String message, String host, String port, String username, String password) {
boolean ok = false;
String uidString = "";
try {
// Set the email properties necessary to send email
final Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.server", host);
if (ModelUtil.hasLength(port)) {
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", port);
}
Session sess;
if (ModelUtil.hasLength(password) && ModelUtil.hasLength(username)) {
sess = Session.getInstance(props, new MailAuthentication(username, password));
} else {
sess = Session.getDefaultInstance(props, null);
}
Message msg = new MimeMessage(sess);
StringTokenizer toST = new StringTokenizer(toField, ",");
if (toST.countTokens() > 1) {
InternetAddress[] address = new InternetAddress[toST.countTokens()];
int addrIndex = 0;
String addrString = "";
while (toST.hasMoreTokens()) {
addrString = toST.nextToken();
address[addrIndex] = (new InternetAddress(addrString));
addrIndex = addrIndex + 1;
}
msg.setRecipients(Message.RecipientType.TO, address);
} else {
InternetAddress[] address = { new InternetAddress(toField) };
msg.setRecipients(Message.RecipientType.TO, address);
}
InternetAddress from = new InternetAddress(myAddress);
msg.setFrom(from);
msg.setSubject(subjectField);
UID msgUID = new UID();
uidString = msgUID.toString();
msg.setHeader("X-Mailer", uidString);
msg.setSentDate(new Date());
MimeMultipart mp = new MimeMultipart();
// create body part for textarea
MimeBodyPart mbp1 = new MimeBodyPart();
if (getCustomerName() != null) {
messageText = "From: " + getCustomerName() + "\n" + messageText;
}
if (isHTML) {
mbp1.setContent(messageText, "text/html");
} else {
mbp1.setContent(messageText, "text/plain");
}
mp.addBodyPart(mbp1);
try {
if (!isHTML) {
msg.setContent(messageText, "text/plain");
} else {
msg.setContent(messageText, "text/html");
}
Transport.send(msg);
ok = true;
} catch (SendFailedException sfe) {
Log.warn("Could not connect to SMTP server.");
}
} catch (Exception eq) {
Log.warn("Could not connect to SMTP server.");
}
return ok;
}
use of java.rmi.server.UID in project jdk8u_jdk by JetBrains.
the class ConnectionInputStream method done.
/**
* Done with input stream for remote call. Send DGC ack if necessary.
* Allow sending of ack to fail without flagging an error.
*/
void done(Connection c) {
if (dgcAckNeeded) {
Connection conn = null;
Channel ch = null;
boolean reuse = true;
DGCImpl.dgcLog.log(Log.VERBOSE, "send ack");
try {
ch = c.getChannel();
conn = ch.newConnection();
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.writeByte(TransportConstants.DGCAck);
if (ackID == null) {
ackID = new UID();
}
ackID.write((DataOutput) out);
conn.releaseOutputStream();
/*
* Fix for 4221173: if this connection is on top of an
* HttpSendSocket, the DGCAck won't actually get sent until a
* read operation is attempted on the socket. Calling
* available() is the most innocuous way of triggering the
* write.
*/
conn.getInputStream().available();
conn.releaseInputStream();
} catch (RemoteException e) {
reuse = false;
} catch (IOException e) {
reuse = false;
}
try {
if (conn != null)
ch.free(conn, reuse);
} catch (RemoteException e) {
// eat exception
}
}
}
use of java.rmi.server.UID in project hive by apache.
the class Utils method serializeAndDeserializeRecord.
public static AvroGenericRecordWritable serializeAndDeserializeRecord(GenericData.Record record, Schema fileSchema) throws IOException {
AvroGenericRecordWritable garw = new AvroGenericRecordWritable(record);
garw.setRecordReaderID(new UID());
// Assuming file schema is the same as record schema for testing purpose.
garw.setFileSchema(fileSchema);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
garw.write(daos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dais = new DataInputStream(bais);
AvroGenericRecordWritable garw2 = new AvroGenericRecordWritable();
garw2.setRecordReaderID(new UID());
garw2.readFields(dais);
return garw2;
}
Aggregations