Hi Rick- most DNS servers wont do lookups on DNS CNAMEs for ServerName With Spaces
but rather CNAMEs without spaces such as private static String URL = "http://127.0.0.1:8080/axis2/services/AddressBookService"; Call.java throws MalformedURLException when the EPR (URL) is malformed M-- ----- Original Message ----- From: "Rick Strong" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Friday, November 30, 2007 6:14 AM Subject: Re: HTML Status Code 302 And Exception When Contacting IIS Service > Hi Martin, > > Thanks. I added the following to my own code while configuring the call: > > call.setProperty(MessageContext.HTTP_TRANSPORT_VERSION, > HTTPConstants.HEADER_PROTOCOL_V11); > Hashtable chunkedTable = new Hashtable(); > chunkedTable.put(HTTPConstants.HEADER_TRANSFER_ENCODING, > HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED); > call.setProperty(HTTPConstants.REQUEST_HEADERS, chunkedTable); > > Now I get similar results, but with one additional go-round. In > HTTPSender.readFromSocket, the first iteration gives me a 100 > (continue), then when I do so, I get the 302 again, then the > MalformedURLException. > > I should probably mention that this is Axis 1.4, Java 1.5 (OS X) > > Rick > > Martin Gainty wrote: > > Hi Rick- > > 1st make sure you are enabling HTTP 1.1 protocol and chunkedEncoding > > transfer-encoding as in this example from /conf/axis2.xml > > > > <transportSender name="http" > > > > class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> > > <parameter name="PROTOCOL">HTTP/1.1</parameter> > > <parameter name="Transfer-Encoding">chunked</parameter> > > > > <!-- If following is set to 'true', optional action part of the > > Content-Type will not be added to the SOAP 1.2 messages --> > > <!-- <parameter name="OmitSOAP12Action">true</parameter> --> > > </transportSender> > > > > Martin- > > ----- Original Message ----- > > From: "Rick Strong" <[EMAIL PROTECTED]> > > To: "AXIS User Mail List" <[email protected]> > > Sent: Thursday, November 29, 2007 8:35 PM > > Subject: HTML Status Code 302 And Exception When Contacting IIS Service > > > > > > > >> 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%2fConnec > > t.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_na > > me/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] > >> > >> > >> > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
