Michael Scott

Ranch Hand
+ Follow
since Jan 20, 2003
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 Michael Scott

Thanks Peer. The links you provided contain much useful information.
14 years ago
The following is some of the code I use to connect to a web service. This code functions only if the web service URL starts with 'http' rather than 'https' even though both URL's are valid.

I'd appreciate any ideas on why the code fails when the web service URL starts with 'https', but not when 'http' is used. Thanks.

The error is also included below.
_______________________________________
CODE:


SOAPMessage message = null;
SOAPMessage response = null;
private String EndPointUrl = null;
_________________________________________________
SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();

EndPointUrl = "http:// ... "; // web service URL

URLEndpoint endpoint = new URLEndpoint(EndPointUrl);
response = con.call(message, endpoint);
__________________________________________________

ERROR:


javax.xml.soap.SOAPException: java.net.MalformedURLException: unknown protocol: https at org.apache.axis.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:93)
14 years ago
Peer ... thanks very much for the info. I'll have to read up on this matter some more to get a better understanding of what's involved.
14 years ago
What I was referring to by 'keep-alive' can be seen in the code in the following link. In the Request SOAP Message, there's a line that says: "Connection: keep-alive".

https://coderanch.com/t/221967/Web-Services/java/SAAJ-Invalid-Content-Type-Exception

I have code somewhat similar to that at the above link except that the Request SOAP Message is created using the SOAP API. For example, the connection and message are defined as follows:

------------------------------------------------
SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();

MessageFactory factory = MessageFactory.newInstance();
message = factory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();

SOAPHeader soapheader = envelope.getHeader();
SOAPBody body = envelope.getBody();

message.setProperty(SOAPMessage.WRITE_XML_DECLARATION,"true");
message.setProperty(javax.xml.soap.SOAPMessage.CHARACTER_SET_ENCODING , "utf-8");
-----------------------------------

My question is whether there is a method in the SOAP API that can set the conection to "keep-alive".

Thanks.
14 years ago
Is there a method in the Java API that can be used to set a connection to 'keep-alive' for a SOAP request message?

Thanks.
14 years ago
This seems to work ... append the following to the command in the .bat file:

2> error.txt

Thanks.
14 years ago
Thanks for the feedback. I'm interested in being able to capture the specific error message generated by Antenna House when the .bat file is run - not just a return code. For example, might there be some way of directing the message to a text file on the server. If so, then I'll presume that the application could read this file.
[ August 23, 2007: Message edited by: Michael Scott ]
14 years ago
I have a Java web application that runs a .bat file (shell script) on an AIX box. The .bat file has a command that runs the executable of a product called Antenna House which generates .pdf files.

Antenna House has its own Java classes, including some that generate specific error messages if the PDF generation fails.

I'm interested in how any error messages generated by Antenna House might be returned to the application while running a .bat file.

Thanks.
14 years ago
I added a new entry to this forum with code details. It turns out this was a permissions issue. The code was applying a 'chmod' to the .bat file, but apparently this process did not always complete on time. Adding the line below with the 'waitFor' method seemed to resolve this.

Process chmodChild = Runtime.getRuntime().exec(chmodCommand);
chmodChild.waitFor();


Thanks for your responses.
15 years ago
It turns out this was a permissions issue. The code was applying a 'chmod' to the .bat file, but apparently this process did not always complete on time. Adding the line below with the 'waitFor' method seemed to resolve this.

Process chmodChild = Runtime.getRuntime().exec(chmodCommand);
chmodChild.waitFor();


Thanks.
15 years ago
Thanks for your response David. Perhaps this will make things clearer ...

After, the .bat file is created, three other methods run - one to apply a CHMOD to the .bat file, one to create a string for the .bat command, and a third to actually run the command. The third method is that in which the error sometimes occurs because the .bat file is not found. This method is shown below followed by log statements that are generated by this method.


/**** This method runs the .bat file after checking whether it exists ***/
synchronized void runBATfile(String batCommand) throws NotesException, IOException, InterruptedException {

try {
Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
thread.start();
for (int i = 0; i < 20; i++) {
boolean exists = (new File(batFileName)).exists();
if (exists) {
LogAccessor.getLogger().logAction("batFileName
exists in runBATfile - " + batFileName);
break;
} else {
LogAccessor.getLogger().logAction("batFileName
does not exist in runBATfile - " + batFileName);
sleep(1000);
}
}

Process batChild = Runtime.getRuntime().exec
(batCommand);
batChild.waitFor();
}
catch(Exception e) {
LogAccessor.getLogger().logAction("agent failed.");
LogAccessor.getLogger().logError(e);
}
}

______________________________
The log statements (in order) are as follows:
17: [15:33:38] - batFileName exists in runBATfile -
US6C*73V97H-23.bat
18: [15:33:38] - agent failed.
19: [15:33:38] - java.io.IOException: US6C*73V97H-23.bat:
not found

______________________________

Note that each run generates a unique .bat file name.

What's not apparent is why this code occasionally generates a 'file not found' error after it was previously confirmed by the code that the .bat file exists.

Are you suggesting that each .bat file should be explicitly closed before it is run and that the failure to do so might be the cause of the error?

Thanks again.
[ June 06, 2007: Message edited by: Michael Scott ]
15 years ago
I have code with a synchronized method which creates a .bat file that's used later in the code. Sometimes, when the code runs, it generates an error which says that the .bat file could not be found. However, a logging statement just prior to when the missing .bat file error occurs confirms that the file exists. Furthermore, if I go to a command prompt, I can verify that the .bat file was in fact created within the same minute that the error occurred.

This suggests that there might be a thread or timing issue that occasionally results in the .bat file not being created on time. I assumed that if the method which creates the file is synchronized this would ensure that the file is created before any other code runs. Is this an incorrect assumption?

The synchronized method that creates the .bat file is as follows.

synchronized String createBATfile(String delRef) throws NotesException, IOException {

StringBuffer batFileNameBuffer = new StringBuffer(delRef);
batFileNameBuffer.append
(".bat");
String batFileName = batFileNameBuffer.toString();
File batFile = new File (batFileName);

// Create a file if it does not exist;
try {
boolean batCreateSuccess = batFile.createNewFile();
}
catch(Exception e) {
LogAccessor.getLogger().logAction(".bat file failed to be created.");
LogAccessor.getLogger().logError(e);
}
return batFileName;
}


Here's the code that confirms that the .bat file exists just prior to when the missing file error occurs.

boolean exists = (new File(batFileName)).exists();
if (exists) {
LogAccessor.getLogger().logAction("batFileName exists" + batFileName);
} else {
LogAccessor.getLogger().logAction("batFileName doesn't exist" +
batFileName);
}


Thanks.
15 years ago
I have code that is intended to run a .bat file (shell script) on AIX. The primary steps in the code are listed below. The code generates an error unless it is delayed by a 'sleep' (step 8) prior to when the .bat file runs (step 9). (The error is "Error 404 - HTTP Web Server: Item Not Found Exception".) The 'sleep' must be excessively long in case there are several concurrent runs and so I'm looking to replace it. However, either replacing the 'sleep' with 'join' or making the methods for each of the following steps 'synchronized' still results in the same error.

I'd appreciate any other ideas of how the code might be modified to prevent an error in step 9. Thanks.

Steps:

1.) Create parameter used in some following steps.

2.) Create input file.

3.) Create .bat file.

4.) Add data to input file.

5.) Add commands to .bat file.

6.) Apply chmod to grant permissions to .bat file.

7.) Create exec to run .bat file.

8.) // Code to make thread sleep.

Runnable runnable = new BasicThread();
Thread thread = new Thread(runnable);
thread.start();
thread.sleep(12000);

9.) // Run bat command.

Process batChild = Runtime.getRuntime().exec(batCommand);
batChild.waitFor();
15 years ago
I have code that includes a line which runs a shell script (a .bat file on AIX). The output from this .bat file is incorrect unless the code is delayed before the line that runs the shell script. For example, the 'sleep' method or a statement that writes to a log needs to be applied first to slow down the code sufficiently. These are inefficient work-arounds though and will cause problems if there are a number of concurrent users. The .bat file and other files that it refers to are created by the code prior to when the code runs the .bat file. I'm therefore wondering whether a solution might be to have all the prior code broken up into a series of 'synchronized' methods that might resolve any multi-threading issues.

I'd appreciate any ideas on this. Thanks.
15 years ago
Is there code that is the converse of the following which does not rely on an Else clause?

if (animal.equals("cat") )

I thought this might be expressed as something such as the following. This is not valid though.

if not(animal.equals("cat") )

Thanks.
15 years ago