Jetty configuration for adding new Handler

classic Classic list List threaded Threaded
5 messages Options
Saurabh Sharma Saurabh Sharma
Reply | Threaded
Open this post in threaded view
|

Jetty configuration for adding new Handler

Hi,

 

We are using  ignite-rest-http module to make Rest http calls. For that we have included ignite-rest-http dependency in our ignite module and are able to make http calls successfully.

Now when we are trying to configure Jetty's RewriteHandler to set HeaderPatternRule to set "Access-Control-Allow-Origin" this handler is not being called and response header is not being set when we make http call.

However I could see this handler being set at the time of ignite startup during debugging.

 

We are using following configuration. Could you please suggest if we are missing anything.

 

<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Arg name="threadPool">

        <!-- Default queued blocking thread pool -->

        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">

            <Set name="minThreads">20</Set>

            <Set name="maxThreads">200</Set>

        </New>

    </Arg>

    <New id="httpCfg" class="org.eclipse.jetty.server.HttpConfiguration">

        <Set name="secureScheme">https</Set>

        <Set name="securePort">8443</Set>

        <Set name="sendServerVersion">true</Set>

        <Set name="sendDateHeader">true</Set>

    </New>

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">myheader</Set>

                                                  <Set name="value">the value of myheader</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

    <Call name="addConnector">

        <Arg>

            <New class="org.eclipse.jetty.server.ServerConnector">

                <Arg name="server"><Ref refid="Server"/></Arg>

                <Arg name="factories">

                    <Array type="org.eclipse.jetty.server.ConnectionFactory">

                        <Item>

                            <New class="org.eclipse.jetty.server.HttpConnectionFactory">

                                <Ref refid="httpCfg"/>

                            </New>

                        </Item>

                    </Array>

                </Arg>

                <Set name="host">

                  <SystemProperty name="IGNITE_JETTY_HOST" default="localhost"/>

                </Set>

                <Set name="port">

                  <SystemProperty name="IGNITE_JETTY_PORT" default="8080"/>

                </Set>

                <Set name="idleTimeout">30000</Set>

                <Set name="reuseAddress">true</Set>

            </New>

        </Arg>

    </Call>

    <Set name="handler">

        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

            <Set name="handlers">

                <Array type="org.eclipse.jetty.server.Handler">

                    <Item>

                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>

                    </Item>

                </Array>

            </Set>

        </New>

    </Set>

               

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">Access-Control-Allow-Origin</Set>

                                                  <Set name="value">*</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

 

                <Set name="handler">

                  <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

                                <Set name="handlers">

                                  <Array type="org.eclipse.jetty.server.Handler">

                                                <Item>

                                                  <Ref refid="RewriteHandler"/>

                                                </Item>

                                  </Array>

                                </Set>

                  </New>

                </Set>

    <Set name="stopAtShutdown">false</Set>

</Configure>

 

Thanks,

Saurabh

 

IMPORTANT NOTICE: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the system manager and/or the sender immediately.
Saurabh Sharma Saurabh Sharma
Reply | Threaded
Open this post in threaded view
|

RE: Jetty configuration for adding new Handler

Hi,

 

Could anyone please tell us how to add response header "Access-Control-Allow-Origin" in the response returned from the rest call to ignite.

 

Thanks,
Saurabh

 

From: Saurabh Sharma [mailto:[hidden email]]
Sent: Thursday, June 23, 2016 7:46 PM
To: [hidden email]
Subject: Jetty configuration for adding new Handler

 

Hi,

 

We are using  ignite-rest-http module to make Rest http calls. For that we have included ignite-rest-http dependency in our ignite module and are able to make http calls successfully.

 

Now when we are trying to configure Jetty's RewriteHandler to set HeaderPatternRule to set "Access-Control-Allow-Origin" this handler is not being called and response header is not being set when we make http call.

However I could see this handler being set at the time of ignite startup during debugging.

 

We are using following configuration. Could you please suggest if we are missing anything.

 

<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Arg name="threadPool">

        <!-- Default queued blocking thread pool -->

        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">

            <Set name="minThreads">20</Set>

            <Set name="maxThreads">200</Set>

        </New>

    </Arg>

    <New id="httpCfg" class="org.eclipse.jetty.server.HttpConfiguration">

        <Set name="secureScheme">https</Set>

        <Set name="securePort">8443</Set>

        <Set name="sendServerVersion">true</Set>

        <Set name="sendDateHeader">true</Set>

    </New>

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">myheader</Set>

                                                  <Set name="value">the value of myheader</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

    <Call name="addConnector">

        <Arg>

            <New class="org.eclipse.jetty.server.ServerConnector">

                <Arg name="server"><Ref refid="Server"/></Arg>

                <Arg name="factories">

                    <Array type="org.eclipse.jetty.server.ConnectionFactory">

                        <Item>

                            <New class="org.eclipse.jetty.server.HttpConnectionFactory">

                                <Ref refid="httpCfg"/>

                            </New>

                        </Item>

                    </Array>

                </Arg>

                <Set name="host">

                  <SystemProperty name="IGNITE_JETTY_HOST" default="localhost"/>

                </Set>

                <Set name="port">

                  <SystemProperty name="IGNITE_JETTY_PORT" default="8080"/>

                </Set>

                <Set name="idleTimeout">30000</Set>

                <Set name="reuseAddress">true</Set>

            </New>

        </Arg>

    </Call>

    <Set name="handler">

        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

            <Set name="handlers">

                <Array type="org.eclipse.jetty.server.Handler">

                    <Item>

                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>

                    </Item>

                </Array>

            </Set>

        </New>

    </Set>

               

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">Access-Control-Allow-Origin</Set>

                                                  <Set name="value">*</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

 

                <Set name="handler">

                  <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

                                <Set name="handlers">

                                  <Array type="org.eclipse.jetty.server.Handler">

                                                <Item>

                                                  <Ref refid="RewriteHandler"/>

                                                </Item>

                                  </Array>

                                </Set>

                  </New>

                </Set>

    <Set name="stopAtShutdown">false</Set>

</Configure>

 

Thanks,

Saurabh

 

IMPORTANT NOTICE: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the system manager and/or the sender immediately.

Andrey Novikov Andrey Novikov
Reply | Threaded
Open this post in threaded view
|

Re: Jetty configuration for adding new Handler

In reply to this post by Saurabh Sharma
Hi Saurabh,

I've investigated ignite-rest-http module and found that handler from configuration will be overrided by default handler (org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java:332)

I've created issue for fix this problem https://issues.apache.org/jira/browse/IGNITE-3370

As temporally workaround you may do the following:

1) Extend embedded server class and place it into HandlerCollectionServer jar, add as dependency to project or if your using binary distributive put it into libs folder.

package my.company.jetty;

public class HandlerCollectionServer extends Server {
    private HandlerCollection hndCol;

    public HandlerCollectionServer(@Name("threadpool") ThreadPool pool) {
        super(pool);

        super.setHandler(hndCol = new HandlerCollection());
    }

    /** {@inheritDoc} */
    @Override public void setHandler(Handler hnd) {
    // Workaround. Don't override, just add to handlers collection.
        hndCol.addHandler(hnd);
    }
}

2) Add dependency to project.

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-rewrite</artifactId>
    <version>${jetty.version}</version>
</dependency>

3) Use following jetty configuration:

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="my.company.jetty.HandlerCollectionServer">
    <Arg name="threadPool">
        <!-- Default queued blocking thread pool -->
        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
            <Set name="minThreads">20</Set>
            <Set name="maxThreads">200</Set>
        </New>
    </Arg>
    <Set name="stopAtShutdown">false</Set>

    <New id="httpCfg" class="org.eclipse.jetty.server.HttpConfiguration">
        <Set name="secureScheme">https</Set>
        <Set name="securePort">8443</Set>
        <Set name="sendServerVersion">true</Set>
        <Set name="sendDateHeader">true</Set>
    </New>

    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.ServerConnector">
                <Arg name="server">
                    <Ref refid="Server"/>
                </Arg>
                <Arg name="factories">
                    <Array type="org.eclipse.jetty.server.ConnectionFactory">
                        <Item>
                            <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                                <Ref refid="httpCfg"/>
                            </New>
                        </Item>
                    </Array>
                </Arg>
                <Set name="host">
                    <SystemProperty name="IGNITE_JETTY_HOST" default="localhost"/>
                </Set>
                <Set name="port">
                    <SystemProperty name="IGNITE_JETTY_PORT" default="8080"/>
                </Set>
                <Set name="idleTimeout">30000</Set>
                <Set name="reuseAddress">true</Set>
            </New>
        </Arg>
    </Call>
    <Set name="handler">
    <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="rules">
<Array type="org.eclipse.jetty.rewrite.handler.Rule">
<Item>
<New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">*.*</Set>
<Set name="name">Access-Control-Allow-Origin</Set>
<Set name="value">*</Set>
</New>
</Item>
</Array>
  </Set>
        </New>
    </Set>
</Configure>


On Fri, Jun 24, 2016 at 5:10 PM, Saurabh Sharma <[hidden email]> wrote:

Hi,

 

Could anyone please tell us how to add response header "Access-Control-Allow-Origin" in the response returned from the rest call to ignite.

 

Thanks,
Saurabh

 

From: Saurabh Sharma [mailto:[hidden email]]
Sent: Thursday, June 23, 2016 7:46 PM
To: [hidden email]
Subject: Jetty configuration for adding new Handler

 

Hi,

 

We are using  ignite-rest-http module to make Rest http calls. For that we have included ignite-rest-http dependency in our ignite module and are able to make http calls successfully.

 

Now when we are trying to configure Jetty's RewriteHandler to set HeaderPatternRule to set "Access-Control-Allow-Origin" this handler is not being called and response header is not being set when we make http call.

However I could see this handler being set at the time of ignite startup during debugging.

 

We are using following configuration. Could you please suggest if we are missing anything.

 

<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Arg name="threadPool">

        <!-- Default queued blocking thread pool -->

        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">

            <Set name="minThreads">20</Set>

            <Set name="maxThreads">200</Set>

        </New>

    </Arg>

    <New id="httpCfg" class="org.eclipse.jetty.server.HttpConfiguration">

        <Set name="secureScheme">https</Set>

        <Set name="securePort">8443</Set>

        <Set name="sendServerVersion">true</Set>

        <Set name="sendDateHeader">true</Set>

    </New>

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">myheader</Set>

                                                  <Set name="value">the value of myheader</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

    <Call name="addConnector">

        <Arg>

            <New class="org.eclipse.jetty.server.ServerConnector">

                <Arg name="server"><Ref refid="Server"/></Arg>

                <Arg name="factories">

                    <Array type="org.eclipse.jetty.server.ConnectionFactory">

                        <Item>

                            <New class="org.eclipse.jetty.server.HttpConnectionFactory">

                                <Ref refid="httpCfg"/>

                            </New>

                        </Item>

                    </Array>

                </Arg>

                <Set name="host">

                  <SystemProperty name="IGNITE_JETTY_HOST" default="localhost"/>

                </Set>

                <Set name="port">

                  <SystemProperty name="IGNITE_JETTY_PORT" default="8080"/>

                </Set>

                <Set name="idleTimeout">30000</Set>

                <Set name="reuseAddress">true</Set>

            </New>

        </Arg>

    </Call>

    <Set name="handler">

        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

            <Set name="handlers">

                <Array type="org.eclipse.jetty.server.Handler">

                    <Item>

                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>

                    </Item>

                </Array>

            </Set>

        </New>

    </Set>

               

                <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">

                  <Set name="rules">

                                <Array type="org.eclipse.jetty.rewrite.handler.Rule">

 

                                  <Item>

                                                <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">

                                                  <Set name="pattern">*.*</Set>

                                                  <Set name="name">Access-Control-Allow-Origin</Set>

                                                  <Set name="value">*</Set>

                                                </New>

                                  </Item>

 

                                </Array>

                  </Set>

                </New>

 

                <Set name="handler">

                  <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">

                                <Set name="handlers">

                                  <Array type="org.eclipse.jetty.server.Handler">

                                                <Item>

                                                  <Ref refid="RewriteHandler"/>

                                                </Item>

                                  </Array>

                                </Set>

                  </New>

                </Set>

    <Set name="stopAtShutdown">false</Set>

</Configure>

 

Thanks,

Saurabh

 

IMPORTANT NOTICE: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the system manager and/or the sender immediately.


GB GB
Reply | Threaded
Open this post in threaded view
|

Re: Jetty configuration for adding new Handler

Hi Andry/Saurabh,

I also have same issue as in original post.
I tried exact steps as mentioned by Andry but still facing same issue. Header "Access-Control-Allow-Origin" is still not set in the response. Does anything else needed in Jetty Configuration other than what Andry mentioned?

Thanks a lot.

GB GB
Reply | Threaded
Open this post in threaded view
|

Re: Jetty configuration for adding new Handler

Hello Andrey/Saurabh,

I could get it working with following additions in the jetty configuration :

<Set name="handler">
    <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="rules">
<Array type="org.eclipse.jetty.rewrite.handler.Rule">
<Item>
<New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">/</Set>
<Set name="name">Access-Control-Allow-Origin</Set>
<Set name="value">*</Set>
</New>
</Item>
<Item>
<New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">/</Set>
<Set name="name">Access-Control-Allow-Methods</Set>
<Set name="value">GET,POST</Set>
</New>
</Item>
</Array>
  </Set>
        </New>
    </Set>

Basically had to add "Access-Control-Allow-Methods" too.

Thanks,
Gaurav


On Mon, Jan 23, 2017 at 6:29 PM, GB <[hidden email]> wrote:
Hi Andry/Saurabh,

I also have same issue as in original post.
I tried exact steps as mentioned by Andry but still facing same issue.
Header "Access-Control-Allow-Origin" is still not set in the response. Does
anything else needed in Jetty Configuration other than what Andry mentioned?

Thanks a lot.





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Jetty-configuration-for-adding-new-Handler-tp5841p10197.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.