Help coderanch get a
new server
by contributing to the fundraiser

David C. Meyers

+ Follow
since May 20, 2004
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David C. Meyers

I'm attempting to send an email with an image. The image could be an attachment, or it could be imbedded. I don't have a preference. I am reading the image from a database and through a third party API I get a Point[]. I use the point array to create a BufferedImage. I'd like to try to attach the BufferedImage to the email. I have found sample code to attach an image from a file, but I'd rather not write my image to a file. My problem would be solved if I could create a DataSource from a Buffered image. I'd appreciate any advice.

// code to create the BufferedImage
Point[] pointArray = ...;

BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);

Graphics2D g2 = image.createGraphics();
g2.fillRect(0, 0, 200, 200);


Point lastPoint = null;
for (int i = 0; i < pointArray.length; i++)
if (-1 == pointArray[i].x && -1 == pointArray[i].y)
lastPoint = null;

if (null != lastPoint)
g2.drawLine(lastPoint.x, lastPoint.y, pointArray[i].x, pointArray[i].y);

lastPoint = pointArray[i];

// end BufferedImage Code

// code to send a message with attachment
// from
// Create the message
Message message = new MimeMessage(session);

// Fill its headers
message.setSubject("Embedded Image");
message.setFrom(new InternetAddress(from));
new InternetAddress(to));

// Create your new message part
BodyPart messageBodyPart = new MimeBodyPart();
String htmlText = "<H1>Hello</H1>" +
"<img src=\"cid:memememe\">";
messageBodyPart.setContent(htmlText, "text/html");

// Create a related multi-part to combine the parts
MimeMultipart multipart = new MimeMultipart("related");

// Create part for the image
messageBodyPart = new MimeBodyPart();

// Fetch the image and associate to part
DataSource fds = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(fds));

// Add part to multi-part

// Associate multi-part with message
17 years ago
Perfect! If only JavaRanch had a forum to solve world hunger.

I'm not sure that I can provide an exact amount, but I did find pages to load quite slowly after reaching 50 rows or so of results. The project that I was working on slowly converted all of our xsl to jsp pages.

Good Luck.
That worked! However, the xml that is produced from this is now prepended by 'sch' for example when I call:
System.out.println("messageDocument = " + messageDocument.xmlText());

I get
<sch:message service="MathService" xmlns:sch=""><sch:request><sch:A>10</sch:A><sch:B>20</sch:B><sch peration>none</sch peration></sch:request><sch:response><sch:result/><sch:Result>200</sch:Result></sch:response></sch:message>

I can't have 'sch:' in my xml result that I return. Any suggestions on the best way to return cleaner xml?

I'm attempting to use xml beans to parse an xml message. My xml message is:
String xml = <message xmlns='' xmlns:xsi='' xsi:schemaLocation='schema0.xsd' type='Service'>...</message>

If I use the xml above and I call parse using:

I get back a valid MessageDocument object. I'd like to remove the namespace attributes from the xml String and still be able to parse the string using the Factory parser.

For instance:
String xml = <message type='Service'>...</message>
XmlOptions options = new XmlOptions();
Map namespaceMap = new HashMap();
namespaceMap.put("xmlns", "");
namespaceMap.put("xmlns:xsi", "");
namespaceMap.put("xsi:schemaLocation", "schema0.xsd");
options = options.setLoadAdditionalNamespaces(namespaceMap);
MessageDocument messageDocument = MessageDocument.Factory.parse(xml, options);

This does not work I get:
com.bea.xml.XmlException: error: The document is not a message@ document element namespace mismatch expected "" got ""

I am unable to find any examples of setLoadAdditionalNamespaces, but it seems like this should be the way to supply namespaces other than in the xml message itself.

Any ideas?

Many purists would cringe at static methods for utils, and encourage the singleton approach. However, either approach provides the opportunity for threading issues. Thus I would recommend instantiating your util class before using it.

Also, beware of static SimpleDateFormats. It is NOT thread safe. If two calls hit the same static DateFormat unexpected results may occur. I've had this happen on a system that runs 100 tps. Two different times were being formated in the same ms. They came out the same with the hour of the first time, and the minute and second of the second time.
18 years ago
The synchronized part is in reference to iterating through the collection. If while iterating the Vector has an entry added or removed, the iterator will through a ConcurrentModificationException. You can have multiple threads call get or add on the Vector without issue as long as you are not iterating through it.

From the API:

The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Vector's elements method are not fail-fast.
18 years ago
May I suggest:

String uri = "/Servlet/Case.html";
int lastSlashIndex = url.lastIndexOf('/');
int lastDotIndex = url.lastIndexOf('.');
String name = uri.substring(lastSlashIndex, lastDotIndex);

Good luck.
18 years ago
I'm sure there are many ways to handle this, but here is one suggestion. In your calcStrValue method, use a boolean to keep track of if your token is even or odd. If it is odd check to see if it is a number. If it is even, and it is not +/- throw an exception of your own design and catch it from the caller then display an error message.
18 years ago
HashMap is exactly what you want to achieve you're goal. It will be fast and easy.
18 years ago

It is a common (and good) practice to catch your Java exceptions and re-throw a specific business exception that you create. This way your client can catch this business exception and display a proper error message instead of just bombing if a runtime exception occurs. A runtime exception is an unexpected result and should not be purposely programmed.
18 years ago
What database are you using? All of the databases that I have used with the exception of Oracle auto commit. I would suggest forcing a roll back if you do not want to commit.
I am attempting to access a result set from a query that has the same column name in both tables. This is on a DB2 database using WebLogic 8.

for example:
select * from TABLE_A A, TABLE_B B where A.columnname = B.columnname

when I attempt to access the result set:
ResultSet rs = statement.getResultSet();;

I get DB2Exception: [IBM][JDBC Driver] CLI0611E Invalid column name. SQLSTATE=S0022

I also tried fully qualifying the name USER.TABLE_A.columnname, but I received the same error.

Any ideas?


I am getting an error that I can't explain when attempting to execute a finder on my CMP bean. I am using WebLogic Workshop 8 with DB2.

The ejb-ql is:
* @ejbgen:finder max-elements="1000" ejb-ql="SELECT OBJECT(o) from EventBean as o where (o.eventId = ?1 or ?1 = 'BLANK') and (o.eventName LIKE ?2 or ?2 = 'BLANK') and (o.statusCode = ?3 or ?3 = 'Z')" generate-on="Local" signature="Collection finderByCriteria(java.lang.String eventId, java.lang.String eventName, char statusCode)"

The error that I'm getting is:

FinderException Exception in finderByCriteria while preparing or executing statement: 'weblogic.jdbc.wrapper.PreparedStatement_COM_ibm_db2_jdbc_app_DB2PreparedStatement@326' [IBM][CLI Driver][DB2] SQL0302N The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use. SQLSTATE=22001

I only get this error when I enter in 6 or more characters into the event name param (?2).

This field is a varchar(30). I get the same problem if I remove the like, or send in %xxxx% as the param. Any idea why I might be getting this error? I tried doing straight SQL into the data base with a similar query, and I was able to execute it and get results.

Some more info on my finder:
The user may enter any pieces of criteria. Thus if they do not enter an eventId I set eventId to 'BLANK' so that the query only checks the other two fields.

Thanks in advance.