[Texo] HTTP Basic Authentification failed in JSONEObjectStore [message #1006503] |
Thu, 31 January 2013 14:19 |
peter meyer Messages: 13 Registered: September 2012 |
Junior Member |
|
|
Hi,
currently i´am evalutating Texo for a RCP Client/Server Project.
I use it in a three tier architecture:
RCP Client / Tomcat Server / SQL Database
Now i want to add some enterprise features like authentification.
I configure Tomcat for basic authentifiction and override the beforeConnect Methode in JSONEObjectStore:
@Override
protected void beforeConnect(HttpURLConnection conn){
String userpass= "aUsername:aPassword";
conn.setRequestProperty("Authorization", "Basic "+Base64.encode(userpass.getBytes()));
}
I register the extended class at application start:
ComponentProvider.getInstance().register(JSONEObjectStore.class,JSONEObjectStoreWithAuthentication.class);
When the RCP Client connect to the Tomcat Server and the beforeConnect method is called then i got an exception:
java.lang.IllegalStateException: Already connected
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
at de.texo.json.enhancements.JSONEObjectStoreWithAuthentication.beforeConnect(JSONEObjectStoreWithAuthentication.java:20)
at org.eclipse.emf.texo.json.JSONEObjectStore.doHTTPRequest(JSONEObjectStore.java:93)
at org.eclipse.emf.texo.json.JSONEObjectStore.doRequest(JSONEObjectStore.java:243)
at org.eclipse.emf.texo.json.JSONEObjectStore.query(JSONEObjectStore.java:281)
at org.eclipse.emf.texo.store.TexoResource.query(TexoResource.java:203)
I debugged the code and i think i found the reason is how the doHTTPRequest method of the JSONEObjectStore is implemented.
protected String doHTTPRequest(String urlStr, String method, String content) throws Exception {
String localUrlStr = urlStr == null ? getUri().toString() : urlStr;
final URL url = new URL(adaptUrl(localUrlStr));
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Accept-Charset", UTF8);
if (content != null) {
final byte[] bytes = content.getBytes(UTF8);
conn.setRequestProperty("Content-Type", JSONWebServiceObjectResolver.JSON_CONTENT_TYPE);
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
[b]final OutputStream os = conn.getOutputStream();[/b]
os.write(bytes);
os.flush();
os.close();
}
[b] beforeConnect(conn);[/b]
final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
final StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line + "\n");
}
rd.close();
return sb.toString();
}
beforeConnect(conn) is a called in line 93.
At this point when beforeConnect is called the connection is already connected to ithe server by
final OutputStream os = conn.getOutputStream(); at line 87.
Is there a reason why beforeConnect(conn) is called at that late stage or could it be called at line 81, right after setting the other connection stuff?
|
|
|
Re: [Texo] HTTP Basic Authentification failed in JSONEObjectStore [message #1006506 is a reply to message #1006503] |
Thu, 31 January 2013 14:22 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Peter,
No specific reason and what you propose makes sense. Will change it and publish a new build.
gr. Martin
On 01/31/2013 03:19 PM, peter meyer wrote:
> Hi,
>
> currently i´am evalutating Texo for a RCP Client/Server Project.
>
> I use it in a three tier architecture:
> RCP Client / Tomcat Server / SQL Database
>
> Now i want to add some enterprise features like authentification.
>
> I configure Tomcat for basic authentifiction and override the beforeConnect Methode in JSONEObjectStore:
>
>
> @Override
> protected void beforeConnect(HttpURLConnection conn){
>
> String userpass= "aUsername:aPassword"; conn.setRequestProperty("Authorization", "Basic
> "+Base64.encode(userpass.getBytes()));
> }
>
>
> I register the extended class at application start:
>
> ComponentProvider.getInstance().register(JSONEObjectStore.class,JSONEObjectStoreWithAuthentication.class);
>
>
> When the RCP Client connect to the Tomcat Server and the beforeConnect method is called then i got an exception:
>
>
> java.lang.IllegalStateException: Already connected
> at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
> at
> de.texo.json.enhancements.JSONEObjectStoreWithAuthentication.beforeConnect(JSONEObjectStoreWithAuthentication.java:20)
> at org.eclipse.emf.texo.json.JSONEObjectStore.doHTTPRequest(JSONEObjectStore.java:93)
> at org.eclipse.emf.texo.json.JSONEObjectStore.doRequest(JSONEObjectStore.java:243)
> at org.eclipse.emf.texo.json.JSONEObjectStore.query(JSONEObjectStore.java:281)
> at org.eclipse.emf.texo.store.TexoResource.query(TexoResource.java:203)
>
>
> I debugged the code and i think i found the reason is how the doHTTPRequest method of the JSONEObjectStore is implemented.
>
>
> protected String doHTTPRequest(String urlStr, String method, String content) throws Exception {
> String localUrlStr = urlStr == null ? getUri().toString() : urlStr;
> final URL url = new URL(adaptUrl(localUrlStr));
> final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
>
> conn.setRequestMethod(method);
> conn.setDoInput(true);
> conn.setDoOutput(true);
> conn.setUseCaches(false);
> conn.setRequestProperty("Accept-Charset", UTF8);
>
> if (content != null) {
> final byte[] bytes = content.getBytes(UTF8);
> conn.setRequestProperty("Content-Type", JSONWebServiceObjectResolver.JSON_CONTENT_TYPE);
> conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
>
> final OutputStream os = conn.getOutputStream();
> os.write(bytes);
> os.flush();
> os.close();
> }
>
> beforeConnect(conn);
>
> final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
> final StringBuilder sb = new StringBuilder();
> String line;
> while ((line = rd.readLine()) != null) {
> sb.append(line + "\n");
> }
> rd.close();
> return sb.toString();
> }
>
> beforeConnect(conn) is a called in line 93.
> At this point when beforeConnect is called the connection is already connected to ithe server by
> final OutputStream os = conn.getOutputStream(); at line 87.
>
>
> Is there a reason why beforeConnect(conn) is called at that late stage or could it be called at line 81, right after
> setting the other connection stuff?
>
>
>
>
>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Texo] HTTP Basic Authentification failed in JSONEObjectStore [message #1006522 is a reply to message #1006503] |
Thu, 31 January 2013 14:56 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Peter,
I published a new build which changes this. Let me know if it works (or not...).
https://bugs.eclipse.org/bugs/show_bug.cgi?id=399625
gr. Martin
On 01/31/2013 03:19 PM, peter meyer wrote:
> Hi,
>
> currently i´am evalutating Texo for a RCP Client/Server Project.
>
> I use it in a three tier architecture:
> RCP Client / Tomcat Server / SQL Database
>
> Now i want to add some enterprise features like authentification.
>
> I configure Tomcat for basic authentifiction and override the beforeConnect Methode in JSONEObjectStore:
>
>
> @Override
> protected void beforeConnect(HttpURLConnection conn){
>
> String userpass= "aUsername:aPassword"; conn.setRequestProperty("Authorization", "Basic
> "+Base64.encode(userpass.getBytes()));
> }
>
>
> I register the extended class at application start:
>
> ComponentProvider.getInstance().register(JSONEObjectStore.class,JSONEObjectStoreWithAuthentication.class);
>
>
> When the RCP Client connect to the Tomcat Server and the beforeConnect method is called then i got an exception:
>
>
> java.lang.IllegalStateException: Already connected
> at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(Unknown Source)
> at
> de.texo.json.enhancements.JSONEObjectStoreWithAuthentication.beforeConnect(JSONEObjectStoreWithAuthentication.java:20)
> at org.eclipse.emf.texo.json.JSONEObjectStore.doHTTPRequest(JSONEObjectStore.java:93)
> at org.eclipse.emf.texo.json.JSONEObjectStore.doRequest(JSONEObjectStore.java:243)
> at org.eclipse.emf.texo.json.JSONEObjectStore.query(JSONEObjectStore.java:281)
> at org.eclipse.emf.texo.store.TexoResource.query(TexoResource.java:203)
>
>
> I debugged the code and i think i found the reason is how the doHTTPRequest method of the JSONEObjectStore is implemented.
>
>
> protected String doHTTPRequest(String urlStr, String method, String content) throws Exception {
> String localUrlStr = urlStr == null ? getUri().toString() : urlStr;
> final URL url = new URL(adaptUrl(localUrlStr));
> final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
>
> conn.setRequestMethod(method);
> conn.setDoInput(true);
> conn.setDoOutput(true);
> conn.setUseCaches(false);
> conn.setRequestProperty("Accept-Charset", UTF8);
>
> if (content != null) {
> final byte[] bytes = content.getBytes(UTF8);
> conn.setRequestProperty("Content-Type", JSONWebServiceObjectResolver.JSON_CONTENT_TYPE);
> conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
>
> final OutputStream os = conn.getOutputStream();
> os.write(bytes);
> os.flush();
> os.close();
> }
>
> beforeConnect(conn);
>
> final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
> final StringBuilder sb = new StringBuilder();
> String line;
> while ((line = rd.readLine()) != null) {
> sb.append(line + "\n");
> }
> rd.close();
> return sb.toString();
> }
>
> beforeConnect(conn) is a called in line 93.
> At this point when beforeConnect is called the connection is already connected to ithe server by
> final OutputStream os = conn.getOutputStream(); at line 87.
>
>
> Is there a reason why beforeConnect(conn) is called at that late stage or could it be called at line 81, right after
> setting the other connection stuff?
>
>
>
>
>
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Powered by
FUDForum. Page generated in 0.03248 seconds