Greetings,

I'm new to this area of programming, so please bear with me if this is something so simple a 5-year-old should be able to deal with. (In the following code I've changed some names for the sake of confidentiality, so the URLs will not actually work.)

I've written a very simple Axis client in Java, to contact a service on a remote IIS machine. I'm passing a String and expecting an acknowledgment back. I have written my own test service, running in Tomcat on my own server, and it works fine. When trying to connect to the IIS machine, my client chokes with various errors depending on the spellings/misspellings of the endpoint URL. Most common is MalformedURLException: no protocol. My code:

public void contact() {
   try {
       Service service = new Service();
       Call call = (Call) service.createCall();
URL url = new URL("http://remote_machine.us:80/product_name/login/Connect.aspx";);
       call.setTargetEndpointAddress(url);
       call.setOperationName(new QName("Connect.aspx", "service_name"));
       SOAPEnvelope se = new SOAPEnvelope();
       Object[] paramValue = new Object[] { "hello from Rick" };
RPCElement rpce = new RPCElement("http://remote_machine.us";, service_name, paramValue);
       se.addBodyElement(rpce);
       Object returnValue = (Object) call.invoke(se);
       System.out.println(returnValue.toString);
   }
   catch (ServiceException se) {
       se.printStackTrace();
   }
   catch (MalformedURLException mue) {
       mue.printStackTrace();
   }
   catch (RemoteException re) {
       re.printStackTrace();
   }
}

I have walked through the Axis source code trying to find a reason for this. Call.invoke() sends me to HTTPSender.invoke():

targetURL = new URL(msgContext.getStrProp(MessageContext.TRANS_URL));
// targetURL is OK
String host = targetURL.getHost();
// host is the domain name minus the protocol, ie: remote_machine.us, I presume this is OK
int port = targetURL.getPort();
// port is 80

// Send the SOAP request to the server
InputStream inp = writeToSocket(socketHolder, msgContext, targetURL,
           otherHeaders, host, port, msgContext.getTimeout(), useFullURL);

// Read the response back from the server
Hashtable headers = new Hashtable();
inp = readHeadersFromSocket(socketHolder, msgContext, inp, headers);

// the returned headers look plausible to me: {connection= close, date= Thu, 29 Nov 2007 15:06:32 GMT, server= Microsoft-IIS/6.0, content-length= 199, x-powered-by= ASP.NET, cache-control= private, x-aspnet-version= 1.1.4322, microsoftofficewebserver= 5.0_Pub, location= /product_name/login/Connect.aspx?ReturnUrl=%2fproduct_name%2flogin%2fConnect.aspx, content-type= text/html; charset=utf-8}
readFromSocket(socketHolder, msgContext, inp, headers);

The fun begins in HTTPSender.readFromSocket:

Integer rc = (Integer)msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
// rc = 302 (moved/redirect)

If rc == 302, readFromSocket() closes the connection and tries to construct a new URL (and a new connection):

// Temporary Redirect (HTTP: 302/307) // close old connection
     inp.close();
socketHolder.getSocket().close(); // remove former result and set new target url
     msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
     msgContext.setProperty(MessageContext.TRANS_URL, location);
 // next try
     invoke(msgContext);

In HTTPSender.invoke():

try {
    BooleanHolder useFullURL = new BooleanHolder(false);
    StringBuffer otherHeaders = new StringBuffer();

// The following line raises a MalformedURLException, since the string it is getting from msgContext is not a complete specification for a URL: "/product_name/login/Connect.aspx?ReturnUrl=%2fproduct_name%2flogin%2fConnect.aspx":

    targetURL = new URL(msgContext.getStrProp(MessageContext.TRANS_URL));
    .
    .
}

When I point a browser at the original URL I am redirected to this page: "http://remote_machine.us:80/product_name/login/LoginDisplay.aspx/product_name/login/Connect.aspx?ReturnUrl=%2fproduct_name%2flogin%2fConnect.aspx";

Questions:
* Is there any way for me to handle this effectively in code? What am I doing wrong? * This is supposed to end up as an automated process; does it make sense for it to blindly follow a redirect without knowing where it's going? Seems risky to me. * Is the 302 a meaningful error code, or could it be masking something else?

Any suggestions most welcome!

Rick Strong




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to