TRANSREPT from RepXSLTransformer to String

Poster Content
nk4um User
Posts: 92
May 14, 2013 17:03

I have a helper method

public <T> T getResource(final INKFRequestContext context, final INKFRequest request, Class<T> classType ) throws NKFException
    {
        INKFRequest request = context.createRequest(uri);
        request.setRequestScope(spaceLevel);
        request.setRepresentationClass(classType);
        return (T) context.issueRequest(request);
    }

I provide the URI and the class type I want. The class knows the spaceLevel it needs to reach out and extract the resource. I do have some time tomorrow if this does not shed some light as to what I am trying to do.

Previously, I was transrepting the object from the issueRequest to the type I wanted. That worked in most cases except in the case where it got cached in a different type than what I was then asking for.

Like · Post Reply
nk4um Moderator
Posts: 848
May 14, 2013 16:57

OK - I've lost the context of this, I thought the problem was with an XSLT not a SQL query. Can we do a quick screen share tomorrow first thing your time?

Like · Post Reply
nk4um User
Posts: 92

Now it fails at an earlier stage with TRANSREPT from ClassLoaderResourceRepresentation to String

The request is for a .sql file, so I want it as a String that I will then do some freemarker on, so I have setRepresentationClass(String.class)

Like · Post Reply
nk4um Moderator
Posts: 848
May 14, 2013 16:44

Ah - ok I see - it looks like the original problem is happening only later - ie the type you get first is sometimes the RBS but is sometimes the compiled form.

In that case - make the original request for the stylesheet ask for it as the compiled form, so that make transreption happen automatically (or not at all if its already the compiled form that comes back)...

INKFRequest request = context.createRequest("res:/resources/state/state.xslt");
request.setRequestScope(spaceLevel);
request.setRepresentationClass(RepXSLTransformer.class)

Does this make sense?

P.

PS With this you should only ever be dealing with the compiled representation so the conditional attempt to transrept is now redundant.

Like · Post Reply
nk4um User
Posts: 92
May 14, 2013 16:34Determining the type

I started to do that before my last post, but found that every Object that was returned was of type ClassLoaderResourceRepresentation. How can I determine the type of representation. The only thing I have seen so far is to try and transrept and if an exception is thrown to just return what I got.

I do not see any methods on ClassLoaderResourceRepresentation or on INKFResponse that allows me to determine the representation type.

Like · Post Reply
nk4um Moderator
Posts: 848
May 14, 2013 15:09

Hi Gary - you're doing a quite sophisticated pattern so you will have to take responsibility to test the type of the class first before attempting to Transrept.

Basically if you already have the thing you want then don't do the Transrept attempt. Just add a condition to compare the class of the representation you have around the transrept request should do it.

P.

Like · Post Reply
nk4um User
Posts: 92
May 14, 2013 14:27TRANSREPT from RepXSLTransformer to RepXSLTransformer

Hi Peter, asking for a RepXSLTranformer did not seem to work. Instead, it tries to tranrept from a RepXSLTranformer to a RepXSLTranformer and fails.

See stack trace.

<some>
  <ex>
    <ex>
      <id>org.netkernel.layer0.nkf.NKFException</id>
    </ex>
    <ex>
      <id>RequestFrameException</id>
      <request>SOURCE res:/state/MN as Object</request>
    </ex>
    <ex>
      <id>SubrequestException</id>
      <space>AA FindLaw On Rails Module /pluggable-overlay/space</space>
      <endpointId>ep:P3VDYH-QA0BD6</endpointId>
      <endpoint>SQLTransactionOverlay</endpoint>
      <ex>
        <id>org.netkernel.layer0.nkf.NKFException</id>
        <stack>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueKernelRequest() line:507</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueRequestForResponse() line:406</level>
          <level>org.netkernel.rdbms.endpoint.SQLTransactionOverlay.onRequest() line:25</level>
          <level>org.netkernel.module.standard.endpoint.TransparentOverlayImpl.onRequest() line:120</level>
          <level>org.netkernel.layer0.nkf.impl.NKFEndpointImpl.onAsyncRequest() line:93</level>
          <level>... 52 more</level>
        </stack>
      </ex>
    </ex>
    <ex>
      <id>RequestFrameException</id>
      <request>SOURCE res:/state/MN as Object</request>
    </ex>
    <ex>
      <id>SubrequestException</id>
      <space>AA FindLaw On Rails Module /pluggable-overlay/space /overlay/space</space>
      <endpointId>ep:P3VDYH-QA0BD6</endpointId>
      <endpoint>MapperOverlay</endpoint>
      <ex>
        <id>org.netkernel.layer0.nkf.NKFException</id>
        <stack>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueKernelRequest() line:507</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueRequestForResponse() line:406</level>
          <level>org.netkernel.module.standard.builtin.mapper.MapperConfig$Mapping.onRequest() line:489</level>
          <level>org.netkernel.module.standard.builtin.mapper.MapperConfig.onRequest() line:228</level>
          <level>org.netkernel.module.standard.endpoint.ConfiguredOverlayImpl.onRequest() line:228</level>
          <level>org.netkernel.layer0.nkf.impl.NKFEndpointImpl.onAsyncRequest() line:93</level>
          <level>... 60 more</level>
        </stack>
      </ex>
    </ex>
    <ex>
      <id>RequestFrameException</id>
      <request>SOURCE active:findlawonrailsruntime+body@httpRequest%3A/body+entity@state+header@httpRequest%3A/headers+id@MN+params@httpRequest%3A/params+trailingslash@ as Object</request>
    </ex>
    <ex>
      <id>SubrequestException</id>
      <space>AA FindLaw On Rails /rootspace[2]</space>
      <endpointId>ep:4EPH8G-W40AUI</endpointId>
      <endpoint>FindLawRailsRunTime</endpoint>
      <ex>
        <id>org.netkernel.layer0.nkf.NKFException</id>
        <stack>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueKernelRequest() line:507</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueRequest() line:424</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.transrept() line:650</level>
          <level>com.fl.nk.SpaceHelper.getResource() line:110</level>
          <level>com.fl.nk.SpaceHelper.getResource() line:104</level>
          <level>com.fl.nk.FindLawRailsRunTime.get() line:617</level>
          <level>com.fl.nk.FindLawRailsRunTime.onSource() line:69</level>
          <level>org.netkernel.module.standard.endpoint.StandardAccessorImpl.onRequest() line:222</level>
          <level>org.netkernel.layer0.nkf.impl.NKFEndpointImpl.onAsyncRequest() line:93</level>
          <level>... 69 more</level>
        </stack>
      </ex>
    </ex>
    <ex>
      <id>RequestFrameException</id>
      <request>TRANSREPT from RepXSLTransformer to RepXSLTransformer</request>
    </ex>
    <ex>
      <id>SubrequestException</id>
      <space>XML / Core Library (private)</space>
      <endpointId>ep:NTX2WY-EFG8WT</endpointId>
      <endpoint>XMLToXSLTransformer</endpoint>
      <ex>
        <id>org.netkernel.layer0.nkf.NKFException</id>
        <stack>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueKernelRequest() line:507</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.issueRequestForResponse() line:406</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.sourcePrimaryForResponse() line:626</level>
          <level>org.netkernel.layer0.nkf.impl.NKFContextImpl.sourcePrimary() line:597</level>
          <level>org.netkernel.xml.accessor.xslt.XMLToXSLTransformer.onTransrept() line:73</level>
          <level>org.netkernel.layer0.nkf.impl.NKFEndpointImpl.onRequest() line:156</level>
          <level>org.netkernel.layer0.nkf.impl.NKFEndpointImpl.onAsyncRequest() line:93</level>
          <level>... 81 more</level>
        </stack>
      </ex>
    </ex>
    <ex>
      <id>RequestFrameException</id>
      <request>TRANSREPT from RepXSLTransformer to IReadableBinaryStreamRepresentation</request>
    </ex>
    <ex>
      <id>Request Resolution Failure</id>
      <message>TRANSREPT from RepXSLTransformer to IReadableBinaryStreamRepresentation</message>
    </ex>
  </ex>
</some>
Like · Post Reply
nk4um Moderator
Posts: 848
May 3, 2013 22:21

Hi Gary - yes for sure you can do that. I'd assumed you wanted a String for some doc service or something. That ought to clean things up.

Like · Post Reply
nk4um User
Posts: 92
May 3, 2013 22:18Maybe keep it as it needs to be

Hi Peter,

Actually, the reason I am sourcing the .xslt is in order to pass it into an active:xslt request as a operator argument. Could I just source it and transrept it directly into RepXSLTransformer and use it as is.

Gary

Like · Post Reply
nk4um Moderator
Posts: 848
May 3, 2013 22:04

Ah I'm being a bit dumb - there's a more elegant answer. Make the String request use the HEADER_NO_CACHE like this...

request.setHeader(INKFRequest.HEADER_NO_CACHE, true);

From the docs this is what this does...

"A header can be set to indicate that the response to a request should not be retrieved from cache even if it is available and that the response should be put back into the cache. Usually it is desirable for an implementing endpoint to decide if a response is cachable and you would not use this header. However occasionally under certain circumstances it is useful for a client to decide."

So add that to the one that you want to use as a String.

Let me know if this sorts you out...

P.

Like · Post Reply
nk4um Moderator
Posts: 848
May 3, 2013 21:56

Hi Gary - this is an interesting scenario. The request for String is usually getting called before some other active:xslt is actually requesting and compiling the stylesheet.

Once its been compiled it is probably geting used frequently and so is cached.

However sometimes you ask for it as String a little later (after it has been used as the compiled transform). Therefore the kernel finds the cached compiled copy and then attempts to transrept it. But this fails because of course there's no decompiler.

Its an unusual situation - one way to force a by-pass of the cached copy would be to create a requst scope in the String request that completely misses the scope of the cached copy. You could do this by injecting an empty value-space into the scope of the String.class request.

But this feels like a bit of hack - this is actually a pattern I've not seen before - its almost as though the kernel could have another state in its state machine that if the TRANSREPT of a cached item fails it would ignore the cached value and make a direct request instead. I'll have to discuss this with Tony next week.

The workaround scope manipulation will definitely sort you out. Basically create a empty ValueSpace and add it in to the scope.

Let me know if this needs more explanation - I'll post detailed example of the scope change when I get back from my travels.

Cheers,

P.

Like · Post Reply
nk4um User
Posts: 92
May 3, 2013 21:20TRANSREPT from RepXSLTransformer to String

We are getting a failure, occasionally that is a TRANSREPT from RepXSLTransformer to String exception. This does not happen all the time, but is rather very intermittent. Clearing the representation cache resolves the problem. The error occurs when we are trying to source a static resource that is a .xslt file.

INKFRequest request = context.createRequest("res:/resources/state/state.xslt");
request.setRequestScope(spaceLevel);
return context.transrept(context.issueRequest(request), String.class);

There may be some case where we make a call to the same resource and ask to transrept to HDSNode.class instead of string, but I cannot think why that would have an impact.

The spaceLevel gets set with the following.

RequestScopeLevelImpl.createOrphanedRootScopeLevel(targetSpace, context.getKernelContext().getRequestScope());
Where targetSpace is from

private ISpace getSpace(INKFRequestContext context, String moduleId, String versionInput)
    {
        IKernel kernel = context.getKernelContext().getKernel();
        IVersion version = new Version(versionInput);
        return kernel.getSpace(new SimpleIdentifierImpl(moduleId), version, version);
    }

As I said, most of the time this seems to work just fine, but under some unknown circumstances we get into a state that it is now puting this .xslt file into a type RepXSLTransformer and it is unable to transrept to String. One solution would be to create a REpXSLTranformer to String transreptor, but that seems weird.

Like · Post Reply