Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Problems handling ResponseType
[Texo] Problems handling ResponseType [message #1001874] Thu, 17 January 2013 13:45 Go to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi!

I am interessted in using Texo in a project. So I installed it and created a little servlet. The servlet itself works, but I have problems to handle the JSON string that is returned by the server.
The string looks like that (shortened version):

{"endRow":"25","_eclass":"response|ResponseType","totalRows":"26","status":"success","startRow":"0","data":[{"_eclass":"users|User","db_version":1,"db_Id":1,"_id":"1","name":"Testuser neu","role":{"_eclass":"users|Role","db_Id":2,"_id":"2","_proxy":true,"_uri":"ht.tp://localhost:8080/texo/jsonws/users|Role/2#","_title":"Admin"}, and so on....

So i create a JSONObject with that string. No I am not sure about the following steps.
I tried the following two conversions:

1.

JSONObject obj = new JSONObject(json);
JSONModelConverter mConv = ComponentProvider.getInstance().newInstance(
				JSONModelConverter.class);
ResponseType type = (ResponseType) mConv.convert(obj);

This led to the following error message:
Exception in thread "main" java.lang.IllegalArgumentException: Fragment format not supported for fragment: 
	at org.eclipse.emf.texo.utils.ModelUtils.getTypeAndIdFromUri(ModelUtils.java:574)
	at org.eclipse.emf.texo.resolver.DefaultObjectResolver.fromUri(DefaultObjectResolver.java:235)
	at org.eclipse.emf.texo.json.JSONModelConverter.fromUri(JSONModelConverter.java:60)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.resolveObject(BaseJSONModelConverter.java:120)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:107)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:371)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:215)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
	at de.test.texo.test.TexoTest.getUser(TexoTest.java:132)
	at de.test.texo.test.TexoTest.main(TexoTest.java:104)


2.

Second approach using the JSONEMFConverter:
JSONObject obj = new JSONObject(json);
JSONEMFConverter conv = ComponentProvider.getInstance().newInstance(
				JSONEMFConverter.class);
DynamicEObjectImpl eObj = (DynamicEObjectImpl) conv.convert(obj);


Well, that is ok, but do I have any possibility to use the objects as objects of their own type? Maybe convert them from DynamicEObjectImpl?

I would be really happy about some help or hints that could help me with that.
Thanks a lot!

Bastian
Re: [Texo] Problems handling ResponseType [message #1001897 is a reply to message #1001874] Thu, 17 January 2013 14:21 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Bastian,
The first approach is good, only you need to add this call before formatting:
mConv.getUriResolver().setUseWebServiceUriFormat(true)
(I enhanced the exception message to give some more information).

Note there seems to be a typo in the json below: ht.tp instead of http, but I guess it is only in the post itself.

gr. Martin

On 01/17/2013 02:45 PM, Bastian Wagenfeld wrote:
> Hi!
>
> I am interessted in using Texo in a project. So I installed it and created a little servlet. The servlet itself works,
> but I have problems to handle the JSON string that is returned by the server. The string looks like that (shortened
> version):
>
> {"endRow":"25","_eclass":"response|ResponseType","totalRows":"26","status":"success","startRow":"0","data":[{"_eclass":"users|User","db_version":1,"db_Id":1,"_id":"1","name":"Testuser
> neu","role":{"_eclass":"users|Role","db_Id":2,"_id":"2","_proxy":true,"_uri":"ht.tp://localhost:8080/texo/jsonws/users|Role/2#","_title":"Admin"},
> and so on....
>
> So i create a JSONObject with that string. No I am not sure about the following steps.
> I tried the following two conversions:
>
> 1.
>
>
> JSONObject obj = new JSONObject(json);
> JSONModelConverter mConv = ComponentProvider.getInstance().newInstance(
> JSONModelConverter.class);
> ResponseType type = (ResponseType) mConv.convert(obj);
>
> This led to the following error message:
> Exception in thread "main" java.lang.IllegalArgumentException: Fragment format not supported for fragment: at
> org.eclipse.emf.texo.utils.ModelUtils.getTypeAndIdFromUri(ModelUtils.java:574)
> at org.eclipse.emf.texo.resolver.DefaultObjectResolver.fromUri(DefaultObjectResolver.java:235)
> at org.eclipse.emf.texo.json.JSONModelConverter.fromUri(JSONModelConverter.java:60)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.resolveObject(BaseJSONModelConverter.java:120)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:107)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:371)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:215)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
> at de.test.texo.test.TexoTest.getUser(TexoTest.java:132)
> at de.test.texo.test.TexoTest.main(TexoTest.java:104)
>
> 2.
>
> Second approach using the JSONEMFConverter:
>
> JSONObject obj = new JSONObject(json);
> JSONEMFConverter conv = ComponentProvider.getInstance().newInstance(
> JSONEMFConverter.class);
> DynamicEObjectImpl eObj = (DynamicEObjectImpl) conv.convert(obj);
>
>
> Well, that is ok, but do I have any possibility to use the objects as objects of their own type? Maybe convert them from
> DynamicEObjectImpl?
>
> I would be really happy about some help or hints that could help me with that.
> Thanks a lot!
>
> Bastian


--

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] Problems handling ResponseType [message #1001904 is a reply to message #1001897] Thu, 17 January 2013 14:30 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
And as an additional tip... The JSONModelConverter resolves references and other things through this ObjectResolver.
There are different implementations available, for example an ObjectResolver which will resolve against a database or an
object resolver (JSONWebServiceObjectResolver) which works with a webservice.

To use the EntityManagerObjectStore:
getNewObjectStore() (2 matches)
EntityManagerObjectStore localObjectStore = new EntityManagerObjectStore();
localObjectStore.setEntityManager(entityManager);
localObjectStore.setUri(URI.createURI("http://my.local.uri"));
mConv.setObjectResolver(localObjectStore);

gr. Martin

On 01/17/2013 03:21 PM, Martin Taal wrote:
> Hi Bastian,
> The first approach is good, only you need to add this call before formatting:
> mConv.getUriResolver().setUseWebServiceUriFormat(true)
> (I enhanced the exception message to give some more information).
>
> Note there seems to be a typo in the json below: ht.tp instead of http, but I guess it is only in the post itself.
>
> gr. Martin
>
> On 01/17/2013 02:45 PM, Bastian Wagenfeld wrote:
>> Hi!
>>
>> I am interessted in using Texo in a project. So I installed it and created a little servlet. The servlet itself works,
>> but I have problems to handle the JSON string that is returned by the server. The string looks like that (shortened
>> version):
>>
>> {"endRow":"25","_eclass":"response|ResponseType","totalRows":"26","status":"success","startRow":"0","data":[{"_eclass":"users|User","db_version":1,"db_Id":1,"_id":"1","name":"Testuser
>>
>> neu","role":{"_eclass":"users|Role","db_Id":2,"_id":"2","_proxy":true,"_uri":"ht.tp://localhost:8080/texo/jsonws/users|Role/2#","_title":"Admin"},
>>
>> and so on....
>>
>> So i create a JSONObject with that string. No I am not sure about the following steps.
>> I tried the following two conversions:
>>
>> 1.
>>
>>
>> JSONObject obj = new JSONObject(json);
>> JSONModelConverter mConv = ComponentProvider.getInstance().newInstance(
>> JSONModelConverter.class);
>> ResponseType type = (ResponseType) mConv.convert(obj);
>>
>> This led to the following error message:
>> Exception in thread "main" java.lang.IllegalArgumentException: Fragment format not supported for fragment: at
>> org.eclipse.emf.texo.utils.ModelUtils.getTypeAndIdFromUri(ModelUtils.java:574)
>> at org.eclipse.emf.texo.resolver.DefaultObjectResolver.fromUri(DefaultObjectResolver.java:235)
>> at org.eclipse.emf.texo.json.JSONModelConverter.fromUri(JSONModelConverter.java:60)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.resolveObject(BaseJSONModelConverter.java:120)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:107)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:371)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:215)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:108)
>> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:103)
>> at de.test.texo.test.TexoTest.getUser(TexoTest.java:132)
>> at de.test.texo.test.TexoTest.main(TexoTest.java:104)
>>
>> 2.
>>
>> Second approach using the JSONEMFConverter:
>>
>> JSONObject obj = new JSONObject(json);
>> JSONEMFConverter conv = ComponentProvider.getInstance().newInstance(
>> JSONEMFConverter.class);
>> DynamicEObjectImpl eObj = (DynamicEObjectImpl) conv.convert(obj);
>>
>>
>> Well, that is ok, but do I have any possibility to use the objects as objects of their own type? Maybe convert them from
>> DynamicEObjectImpl?
>>
>> I would be really happy about some help or hints that could help me with that.
>> Thanks a lot!
>>
>> Bastian
>
>


--

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] Problems handling ResponseType [message #1001908 is a reply to message #1001904] Thu, 17 January 2013 14:43 Go to previous message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Martin,

Thanks a lot! It worked. I think your answer saved a lot of my time.
The "ht.tp" thing was just an accident and not the real string. Smile

Bastian
Previous Topic:[Texo] Problems handling JSON response
Next Topic:Adding/Editing/Deleting Ecore objects programmatically using EditingDomain
Goto Forum:
  


Current Time: Sat Apr 20 03:28:42 GMT 2024

Powered by FUDForum. Page generated in 0.04048 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top