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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Spring scheduled method

dullnigAlex
6-Contributor

Spring scheduled method

I have a Spring scheduled method in Windchill and want to call some methods, but i get the erro that there is no active method context. So I tried to call the method via RemoteMethodServer.invoke(). This actually works but i always get the following error in the log:

2023-12-07 10:44:13,675 ERROR [pool-14-thread-1] wt.method.client  - RemoteMethodServer.invoke() called on default method server from within method server! Probable bad loopback code! java.lang.Exception
at wt.method.RemoteMethodServer.logQuestionableOrBadInvokeCall(RemoteMethodServer.java:1581)
at wt.method.RemoteMethodServer.invoke(RemoteMethodServer.java:647)
at at.techsoft.ifactory.worker.components.QueueRetryMechanism.doRetry(QueueRetryMechanism.java:51)
at at.techsoft.ifactory.worker.components.QueueRetryMechanism.retryFailedEntries(QueueRetryMechanism.java:31)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
 
 
Is there a way to get the active method context without calling RemoteMethodServer.inoke()?
The code runs in the ServerManager I think.
Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions

I solved it by calling a rest servlet.
The Rest servlet has an active method context so there is no preoblem.

View solution in original post

6 REPLIES 6

Hi @dullnigAlex 

I do not use invoke, I use just getDefault

RemoteMethodServer.getDefault().setUserName("----");
RemoteMethodServer.getDefault().setPassword("----");

Then I use standard Windchill methods.

PetrH

If I only get the default i get:

2023-12-07 11:28:19,882 ERROR [pool-14-thread-1] org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler  - Unexpected error occurred in scheduled task wt.method.MethodServerException: No active method context
at wt.method.MethodContext.getContext(MethodContext.java:1831)
at wt.session.StandardSessionManager.isAccessEnforced(StandardSessionManager.java:416)
at wt.queue.QueueMonitorHelper.queueEntries(QueueMonitorHelper.java:1445)
at wt.queue.StandardQueueService.queueEntries(StandardQueueService.java:501)
at jdk.internal.reflect.GeneratedMethodAccessor428.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at wt.services.ServiceFactory$ServerInvocationHandler.invoke(ServiceFactory.java:399)
at com.sun.proxy.$Proxy76.queueEntries(Unknown Source)
at at.techsoft.ifactory.worker.components.QueueRetryMechanism.retryFailedEntries(QueueRetryMechanism.java:42)
at jdk.internal.reflect.GeneratedMethodAccessor427.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
 

Does your scheduler method calls the Windchill http address by URL?

PetrH 

I've tried it with this:

@Component
public class QueueRetryMechanism implements RemoteAccess {

private static final TSLogger logger = new TSLogger(QueueRetryMechanism.class.getCanonicalName());

@Scheduled(initialDelay = 60000, fixedRate = 120000)
public void retryFailedEntries() throws IOException {
RemoteMethodServer.getDefault().setUserName("wtadmin");
RemoteMethodServer.getDefault().setPassword("wtAdm!n");
try {
ProcessingQueue queue = (ProcessingQueue) QueueHelper.manager.getQueue("IFactoryWorkerQueue", ProcessingQueue.class);
Enumeration enumeration = QueueHelper.manager.queueEntries(queue);
System.out.println(enumeration);
} catch (WTException e) {
logger.error(e);
}
}

With Component Scan and annotation driven the class is loaded

I solved it by calling a rest servlet.
The Rest servlet has an active method context so there is no preoblem.

Do you mean following?

WcRestServlet.getInstance();

PetrH

Top Tags