cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

JLink - access to session from webservice

tbijnens
1-Newbie

JLink - access to session from webservice

Hi all,

I'm having some issues with my JLink application (java API - synchronous)

The idea is to start a webservice from this JLink application, so we can easily access our ProE session from another application / website.

I have created the following class:

public class CreoWebService {

    static Session curSession;

    String startDirectory;

    public CreoWebService(Session session)

    {

        //setting current session and getting working directory from this session

        curSession = session;

        startDirectory = curSession.GetCurrentDirectory();

       

        //starting webservice

        String address = "http://127.0.0.1:8023/ShapeWebService";

        CreoWebServiceDef wsDef = new CreoWebServiceDef();

        Endpoint endpoint = Endpoint.publish(address, wsDef);

     }

    @WebService

    public class CreoWebServiceDef {

    @WebMethod

    public void test(){

            System.out.print(startDirectory);

            System.out.print(curSession.GetCurrentDirectory());

          }

    }

}

This seems to work fine, until I try to access the ProE session from the webservice.

The first line from 'test()' is executed correctly when the webservice is called. startDirectory was set when starting the webservice and could access 'curSession' without any problem.

Second line however (in green) fails. No exception or anything, it seems to be blocked while trying to execute this line.

At that point ProE is still working ok. When trying to close it, it crashes (not responding).

While closing down, the second line is executed right before crashing.

So if I understand correctly, my webservice can not access the active ProE session... Am I doing something wrong or trying to do something impossible? All suggestions are welcome, I'm running out of ideas

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Tommy -

I may not be able to answer your question, but I'll try. I strongly suspect that you are using JLink with another Java library (javax.xml.ws.Endpoint) that creates new threads to execute its code. Here is what the JLink User Guide says about Java threads in synchronous programs:

J-Link Thread Restrictions

When you run a synchronous J-Link program, you should configure your program so it does not interfere with the main thread of the PTC Creo Parametric program. Because the Java API allows you to run with multiple threads, you should be cautious of using certain Java routines in your program.

The most obvious restriction involves the use of Java language user interfaces. Any Java window that you create must be a dialog box that is blocking (or modal).

Creating a nonblocking frame causes a new thread to begin, which can have unexpected results when running with PTC Creo Parametric. For example, you can use the javax.swing.JDialog class and set modal true. You cannot use javax.swing.JWindow, however, because it starts a thread.

Most services that listen for requests on a port will spawn a new thread or process for each new request.

Second line however (in green) fails. No exception or anything, it seems to be blocked while trying to execute this line.

At that point ProE is still working ok. When trying to close it, it crashes (not responding).

While closing down, the second line is executed right before crashing.

I can't explain why this would be. Again, I think it's a problem caused by method CreoWebServiceDef.test running in a separate thread. If you can find a way to run everything in the same thread, you can then test that explanation.

Good luck with this -

|+|  M a r k  |+|

View solution in original post

2 REPLIES 2

Hi Tommy -

I may not be able to answer your question, but I'll try. I strongly suspect that you are using JLink with another Java library (javax.xml.ws.Endpoint) that creates new threads to execute its code. Here is what the JLink User Guide says about Java threads in synchronous programs:

J-Link Thread Restrictions

When you run a synchronous J-Link program, you should configure your program so it does not interfere with the main thread of the PTC Creo Parametric program. Because the Java API allows you to run with multiple threads, you should be cautious of using certain Java routines in your program.

The most obvious restriction involves the use of Java language user interfaces. Any Java window that you create must be a dialog box that is blocking (or modal).

Creating a nonblocking frame causes a new thread to begin, which can have unexpected results when running with PTC Creo Parametric. For example, you can use the javax.swing.JDialog class and set modal true. You cannot use javax.swing.JWindow, however, because it starts a thread.

Most services that listen for requests on a port will spawn a new thread or process for each new request.

Second line however (in green) fails. No exception or anything, it seems to be blocked while trying to execute this line.

At that point ProE is still working ok. When trying to close it, it crashes (not responding).

While closing down, the second line is executed right before crashing.

I can't explain why this would be. Again, I think it's a problem caused by method CreoWebServiceDef.test running in a separate thread. If you can find a way to run everything in the same thread, you can then test that explanation.

Good luck with this -

|+|  M a r k  |+|

Thanks, I didn't notice that paragraph in the manual yet.

Tried the same code using threads instead of webservices, giving the exact same result. So your analysis is correct...

Might be better to switch to asynchronous API for this...

Thanks

Top Tags