Win a copy of Terraform in Action this week in the Cloud forum!

peter brews

Ranch Hand
+ Follow
since Jan 25, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by peter brews

Thanks for your advice .
I ahve formatted the code:

Thanks,
peter
[ December 13, 2002: Message edited by: Jim Yingst ]
18 years ago
Dear All,
Could you tell me if i am closing the inputstream ,outputstream etc..
correctly or not. I want to ensure that all the open streams gets closed(and also flushed )
properly.I am closing
out.close in try block and also in finally block also. Is it correct to do so OR should i close out,out1,in only in finally. Also what if don't use out.flush().
Following is my code:
import javax.servlet.*;
import javax.servlet.http.*;
...
..
public class SServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/xml" ;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
try {
String urlname = "xyz";
PrintWriter out = response.getWriter();
BufferedReader in = null;
String Name = request.getParameter("name");
String arg0=request.getParameter("arg0");
String REQUEST = "";
if(Name != null & Name != "")
{
if(Name.equals("Robert"))
{
REQUEST="aaaaaaaaaaaaaaa";
..
...
}
else if (Name.equals("smith"))
{
..
REQUEST="bbbbbbbbbbb";
..
}
}
else{

..
}
URL url = new URL(urlname);
HttpURLConnection connection =(HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-length", "" +REQUEST.length());
connection.setRequestProperty("Content-type", "text/xml");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
PrintWriter out1 = new PrintWriter(connection.getOutputStream());
out1.print(REQUEST);
out1.close();
in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
out.print(inputLine);
}
in.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
finally{
out1.close();
out.close();
try{
if (in!=null){
in.close();
}
}catch(Exception e){
e.printStackTrace();
}

}
}
}
Thanks,
peter
18 years ago
Thanks to both of you for all your help.
could you please help me what should i add to what i have now( i am going thorough the documents but it will take little long for me to get it to work)

Thanks,
peter
--edited for code format and capitalization. mfe --
[ November 15, 2002: Message edited by: Michael Ernest ]
Dear All,
I have a 40 java bean each with about 20 -30 different get and set methods.
I want to get the names and values of all the methods in one bean at a time .
And then reformat that data.Is there any thing similar to jdbc getMeataData where you get column name s and it's values. I want to avoid writing 20-30 getProperty statements.
Any help is highly appreciated.
Thanks,
peter
what i want is to collect the info if the current line (currentRecord)does not ends with | until it finds the next |.

Thanks,
pete
19 years ago
yes my erro msg spans multiple lines but if i replace new line with something else then oher part of program logic gets affted and then i may to redo everything . It would be helpful if something can be done on what i have without much modifications.

Thanks,
pete
19 years ago
yes . i tried to interchange the tokenizing i.e
\n with | and | with \n . but that does not gave me desired result.Is there any other workaround possible.

Thanks,
peter
19 years ago
Thanks or your reply. Actaully BadArgument is just as an example.
Yes you arr right i forget to catch IOException.
19 years ago
Dera All,
Please help me as this is urgent that i need to fix:
The value of each token should be the value between two consecutive token(|).So in the example below the value of token after msg[0]
should be
"error: cannot insert NULL into the emp table) change the values errorcode is 1111 msg is aa"
My file is as follows:
Name|john|
|robert|
|smith|
|ruby|
msg[0]|error: cannot insert NULL into
(the emp table) change the values
errorcode is 1111
msg is aa
|
city[0]|boston|
phone[0]|5555555555|
|8888888888|
|0|
|0|
The output should be
Name
john
robert
smith
ruby
msg[0]
error: cannot insert NULL into (the emp table)change the values errorcode is 11msg is aa
city[0]
5555555555
8888888888
0
0
what changes should i make to the code below so that if the error message spans multiple lines then all those lines should be printed as 1 token
StringBuffer StringBuf = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
StringBuf.append(line + "\n");
}
String cString = StringBuf.toString();
StringTokenizer tokenizer = new
StringTokenizer(cString, "\n");
while (tokenizer.hasMoreTokens()) {
currentRecord = tokenizer.nextToken();
if (currentRecord.length() > 0) {
token = new StringTokenizer(currentRecord, "|");
String s = token.nextToken().trim();
System.out.println("the string is" +s);

while (token.hasMoreTokens()) {
String testtoken=(String)token.nextToken();
System.out.println("the tetstoken is " +testtoken);
}
Thanks,peter
19 years ago
I have a class which extends exception.
I imported this class im my main class as need i to send user friendly message exception msg to the client if there is the exception occurs in the method called.
Client calls methoCC which calls submethod methodAA and i need the user friendly exeption message from methodAA also as response of methodCC to the client.
I tried some combination of throws and try and catch blocks but it is not working as intended could you please help me .

Thanks,
peter
(please format your code using [ code][ /code] blocks without the spaces - Cindy)
[ October 23, 2002: Message edited by: Cindy Glass ]
19 years ago
Could you please tell what is right way of casting an object to string.
so that i can do string functions like checking for null,equality,contains etc..

Thanks,
peter
19 years ago
Dear All,
In the stateless bean i have business methods and utility methods.Please advice if these utility methods need to syncronized if they are being called by multiple business methods in the same bean and the business methods in turn being called by multiple clients at the same time.

Following is piece of code from my ejb :
public interface MySessionEJB extends EJBObject {
public String businessmethod1(String id,String abc)
throws RemoteException, Exception;
public String businessmethod2( String password, Stringdept)
throws RemoteException, Exception;

Thanks,
smita
19 years ago
Dear All,
My file is as follows:
Name|john|
|robert|
|smith|
|ruby|
msg[0]|error: cannot insert NULL into
(the emp table) change the values
errorcode is 1111
msg is aa
|
city[0]|boston|
phone[0]|5555555555|
|8888888888|
|0|
|0|
The output should be
Name
john
robert
smith
ruby
msg[0]
error: cannot insert NULL into (the emp table) change the values errorcode is 11msg is aa
city[0]
5555555555
8888888888
0
0
what changes should i make to the code below so that if the error message spans multiple lines then all those lines should be printed as 1 token
StringBuffer StringBuf = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
StringBuf.append(line + "\n");
}
String cString = StringBuf.toString();
StringTokenizer tokenizer = new
StringTokenizer(cString, "\n");
while (tokenizer.hasMoreTokens()) {
currentRecord = tokenizer.nextToken();
if (currentRecord.length() > 0) {
token = new StringTokenizer(currentRecord, "|");
String s = token.nextToken().trim();
System.out.println("the string is" +s);

while (token.hasMoreTokens()) {
String testtoken=(String)token.nextToken();
System.out.println("the tetstoken is " +testtoken);
}

Thanks,
smita
19 years ago
Dear All,
Ihave four diffrent busines methods in stateless session ejb which calls different uitility methods defined in the same ejb.
These ultility methods which are being called by lot of diffrent methods in the same bean.Also the business methods can be called by different clients at the same time.
Will there be any problem if call method in method.

for ex.
1. private String formatDateutility(String changeDate) {
..
..
..
return changeddate.toString();
}
2. private String getData(String abc){
...
String date1 = formatDateutility("20000212");
..
}
3.public String placeOrder(String order)
{
..
String getStatus = getData(order);

}
4. public String changeOrder(String Order)
{
..
String changeStatus = getData(Order);
..
}
Thanks,
smita
Dear All,
Could you please advise me where should i define
global variables( which are also constant) in stateless session bean.
Thanks,
Smita