Issues logiing into CMS through Oxyge, methods work fine whe

Oxygen general issues.
Kit Strong
Posts: 13
Joined: Mon Oct 07, 2013 7:19 pm

Issues logiing into CMS through Oxyge, methods work fine whe

Post by Kit Strong »

In the process of trying to integrate some of my previous CMS based work into Oxygen I'm running into a problem where I can't actually authenticate on the server when calling my classes from within an Oxygen Extension.

Here's some of the relevant code that is causing the problem. It works fine when used outside of the Oxygen environment but calling it from an extension always return an authentication failure.

Code: Select all


	private int processLoginRequest(String hostURL)
throws CMSConnectionException, CMSAuthenticationFailure,
UnsupportedEncodingException {
{
DocatoSessionCookie cookie = DocatoSessionCookie.getSessionCookie(
hostURL, false);
cookie.setPath("dil-login.do");
String login = URLEncoder.encode(LOGINID, "UTF-8");
String password = URLEncoder.encode(PASSWORD, "UTF-8");
cookie.setData("project=Freescale&username=" + login + "&password="
+ password);
ONLINE = false;
StringBuffer buf = new StringBuffer();
try {

InputStream input = cookie.request();
if (input == null)
System.err.println("NULL INPUTSTREAM");

<snip...>
}
catch (IOException e) {
System.out.println("IO Exception: ");
debug("IOException: " + hostURL, e);
e.printStackTrace();
// throw new CMSConnectionException(hostURL);
}
}
And here's the pertinent part of the DocatoSessionCookie

Code: Select all


public InputStream request() throws IOException {
URL url = new URL(surl);
URLConnection conn = url.openConnection();
conn.setRequestProperty("user-agent", "SWING");
if (cookie != null && !cookie.equals("")) {
conn.setRequestProperty("Cookie", cookie);
}
if (data != null) {
conn.setDoOutput(true);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
conn.getOutputStream()));
out.write(data);
out.flush();
try{
out.close();
}
catch(Exception ex){}
}

String c = conn.getHeaderField("Set-Cookie");
if (c != null && !c.equals(""))
cookie = c;
InputStream inputStream = conn.getInputStream();
return inputStream;



} // end request

Right now I'm at a bit of a loss as to what could be causing the issue so if anyone has any ideas I'm open.

-Kit
Radu
Posts: 9445
Joined: Fri Jul 09, 2004 5:18 pm

Re: Issues logiing into CMS through Oxyge, methods work fine

Post by Radu »

Hi Kit,

When running in Oxygen, Oxygen installs its own "http" protocol handler based on the Apache HTTP Client libraries.

So using code like this:

Code: Select all

URL url = new URL(surl);
URLConnection conn = url.openConnection();
will return a connection which is not the regular SUN HTTP connection but Oxygen's HTTP connection.
This is probably why behavior differs.
To bypass our HTTP connection and use the one provided by SUN you can do this:

Code: Select all

sun.net.www.protocol.http.HttpURLConnection conn = new HttpURLConnection(url, null);
conn.connect();
.....
instead of requesting the URL to open the connection for you.

But I would still be interested to know why our HTTP connection does not work for you, maybe it has a bug which we can fix.
If you contact us via "support@oxygenxml.com" we can give you a file to enable logging in Oxygen and see exactly the HTTP requests and responses as sent between client and server.
Or as an alternative you could use an HTTP traffic monitor, register the HTTP exchanges between client and server both when our HTTP handler is used and when the SUN handler is used and then you can send the log to us in order to find differences in the HTTP request.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply