Search in sources :

Example 1 with UID

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();
    }
}
Also used : UID(java.rmi.server.UID) Entry(net.jini.core.entry.Entry) Transaction(net.jini.core.transaction.Transaction) ByteArrayInputStream(java.io.ByteArrayInputStream) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with UID

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());
}
Also used : UID(java.rmi.server.UID) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 3 with UID

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;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) SendFailedException(javax.mail.SendFailedException) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) Properties(java.util.Properties) Date(java.util.Date) SendFailedException(javax.mail.SendFailedException) UID(java.rmi.server.UID) StringTokenizer(java.util.StringTokenizer) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPart(javax.mail.internet.MimeBodyPart) Session(javax.mail.Session)

Example 4 with UID

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
        }
    }
}
Also used : UID(java.rmi.server.UID) RemoteException(java.rmi.RemoteException)

Example 5 with UID

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;
}
Also used : UID(java.rmi.server.UID) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Aggregations

UID (java.rmi.server.UID)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Schema (org.apache.avro.Schema)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 Test (org.junit.Test)2 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 Message (javax.mail.Message)1 SendFailedException (javax.mail.SendFailedException)1 Session (javax.mail.Session)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1