Re: API call from Python issues - need help please!

10 views
Skip to first unread message

Tomohisa Igarashi

unread,
Jun 16, 2021, 10:32:05 AM6/16/21
to AtlasMap
Oops, somehow this was in spam folder, sometimes GMail does weird thing.

I'd suggest to start from example, changing one by one and see what
change exactly causes the error. At least test with Java first, make
sure it works and then migrate to python.

Thanks,
Tomo

On 6/9/21 10:10 AM, Martin Stache wrote:
> Moving this to larger conversation since I need to figure out what I'm
> doing/what's going wrong.
>
> I am using jpype to call the api thanks to Tomohisha's help! I am using
> the .adm example from the code base. The only changes I have made
were to:
>
> 1. Swap out the .adm file (is there an issue with the content in here???
> e.g., xsds?)
> 2. Replace order.json with source-xml-file.xml
> 3. Change JSONSchemaSource to XMLSchemaSource
>
> Attached is the .adm example from the code base with the changes. I
> don't have an IDE/Environment set up to execute the test. Also don't
> know how to switch on debug logging for logsf4j.
>
> Below are lines of code (one-for-one to the java) that I'm using in
> Python. Additionally, I have attached the console log output from
> running the Python code.
>
> Thanks so much for your help!
>
> HERE IS THE PYTHON (TO JAVA) CODE:
>
> # imports
> from java.lang import Thread
> from java.nio.file import Files
> from java.nio.file import Paths
>
> # URL url =
>
Thread.currentThread().getContextClassLoader().getResource("atlasmap-mapping.adm");
> url =
>
Thread.currentThread().getContextClassLoader().getResource("atlasmap-mapping.adm")
> # AtlasContextFactory factory = DefaultAtlasContextFactory.getInstance();
> defaultAtlasContextFactory =
> jpype.JClass('io.atlasmap.core.DefaultAtlasContextFactory').getInstance()
> # AtlasContext context = factory.createContext(url.toURI());
> context = defaultAtlasContextFactory.createContext(url.toURI())
> # AtlasSession session = context.createSession();
> session = context.createSession()
>
> # url =
> Thread.currentThread().getContextClassLoader().getResource("order.json");
> url =
>
Thread.currentThread().getContextClassLoader().getResource("Source_XML_File.xml")
> # String source = new String(Files.readAllBytes(Paths.get(url.toURI())));
> source = str(Files.readAllBytes(Paths.get(url.toURI())))
> #System.out.println("Source document:\n" + source);
> print("Source document:\n" + source)
> # session.setSourceDocument("JSONSchemaSource", source);
> session.setSourceDocument('XMLSchemaSource', source)
> # context.process(session);
> context.process(session)
> # String targetDoc = (String)
> session.getTargetDocument("XMLInstanceSource");
> target = str(session.getTargetDocument("XMLInstanceSource"))
> # printXML(targetDoc);
> print(target)
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "AtlasMap" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to atlasmap+u...@googlegroups.com
> <mailto:atlasmap+u...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/atlasmap/fc29a429-516b-432b-91f2-dad5e6e5849fn%40googlegroups.com

>
<https://groups.google.com/d/msgid/atlasmap/fc29a429-516b-432b-91f2-dad5e6e5849fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages