How to get string query params from URL in Domino

460 Views Asked by At

After some time I managed to make a redirect from some API.

However, now I'm facing a different problem.

It seems, that there's just no way to get a query param from URL.

The button looks like that:

 <xp:eventHandler event="onclick" submit="true"
    refreshMode="complete">
    <xp:this.action><![CDATA[#{javascript:
    var redirectUrl = context.getUrl().toString();
    var errorRedirectUrl = context.getUrl().toString();

    var EGRZAuthObject = new ru.iteko.egrz.requestprocessors.EGRZAuthorization();

    //auth which redirects
    EGRZAuthObject.initializeAuthProcess(redirectUrl, errorRedirectUrl);

    print("marker param is " + param.get("marker"));
    print("marker param is " + facesContext.getExternalContext().getRequest().getQueryString());
    print("url " + context.getUrl().toString());

    }]]></xp:this.action>
 </xp:eventHandler>

The method which redirects is as follows:

public static void initializeAuthProcess(String redirectUrl, String apiRedirectUrl) throws ClientProtocolException, IOException 
{
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try
        {
            HttpContext context = new BasicHttpContext(); 
            String urlToGoTo = AuthURLs.ESIALoginURL(redirectUrl, apiRedirectUrl);
            HttpGet httpGet = new HttpGet(urlToGoTo);
            HttpResponse response1 = httpclient.execute(httpGet, context);

            HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute( 
                     HttpCoreContext .HTTP_REQUEST);
            HttpHost currentHost = (HttpHost)  context.getAttribute( 
                        HttpCoreContext .HTTP_TARGET_HOST);
            String redirectURLEsia = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());

            FacesContext fc = FacesContext.getCurrentInstance();
            ExternalContext externalContext = fc.getExternalContext();
            externalContext.redirect(redirectURLEsia);
        }
        finally
        {
            httpclient.close();
        }
}

Here's what happens:

  1. In a browser the user initializes auth process by pressing the button
  2. Then initializeAuthProcess executes a request to the system A
  3. System A takes us to the system B, we redirect the user there
  4. The user goes through authorization process in the system B
  5. System B (after auth) redirects the user to our system
  6. And it appends some sort of token in our system's URL called marker

Later on, we should do something with the marker...

The problem is that we don't know how to get the marker. It's always either null or empty. In a browser, however, we always can see it after auth in the system B successfully completed.

enter image description here

I get the following output:

marker param is null
marker param is 
url https://oursystem.com/Nav2.xsp

We also wondering how to remove it from the URL after processing is completed. But as of now, we need to get it at least.

How can we do that?

Thanks in advance.

EDIT:

Obviously the thing is that the code gets executed immediately without waiting for the user authorization in the system B.

For instance if we press the button again we'll have marker param.

So we need a different approach there we should define marker and do something with it

2

There are 2 best solutions below

0
stwissel On

You looking at the wrong end. There are 2 options: pick the marker from the returned response1 calling the other systems or move that code to the page you redirect to

0
umeli On

If you click the button, you are redirected to the other page. Testing for the marker should therefore be in the callback step between 5 & 6. Check in the beforeRenderResponse event if the marker is there and then you can react to that.