<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Yeah, I am sorry to misuse this thread
      <span class="moz-smiley-s1"><span> :-) </span></span> It just came
      to my mind when Haim mentioned, that exception is not thrown in
      his code, even if creation of client model obviously failed.<br>
      <br>
      Marek<br>
      <br>
      On 30/05/16 20:24, Stian Thorgersen wrote:<br>
    </div>
    <blockquote
cite="mid:CAJgngAd_see1z_WDMEdjUtrzGO1u1RshGMgngqc2k-oW+NZ0Mw@mail.gmail.com"
      type="cite">
      <div dir="ltr">+1 Not the correct thread for it though ;)</div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On 30 May 2016 at 11:57, Marek Posolda
          <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:mposolda@redhat.com" target="_blank">mposolda@redhat.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <div>Maybe someone already mentions it before. IMO the
                returning "Response" from the create methods on admin
                client is one of the biggest limitation of current
                admin-client. For example if we change ClientResources
                method:<br>
                <br>
                <pre style="background-color:#ffffff;color:#000000;font-family:'DejaVu Sans Mono';font-size:9.0pt"><span style="color:#808000">@POST
</span><span style="color:#808000">@Consumes</span>(MediaType.<span style="color:#660e7a;font-weight:bold;font-style:italic">APPLICATION_JSON</span>)
<span style="color:#000080;font-weight:bold">public </span>Response create(ClientRepresentation clientRepresentation);

</pre>
                to something like:<br>
                <br>
                <pre style="background-color:#ffffff;color:#000000;font-family:'DejaVu Sans Mono';font-size:9.0pt"><span style="color:#808000">@POST
</span><span style="color:#808000">@Consumes</span>(MediaType.<span style="color:#660e7a;font-weight:bold;font-style:italic">APPLICATION_JSON</span>)
<span style="color:#808000">@Produces</span>(MediaType.<span style="color:#660e7a;font-weight:bold;font-style:italic">APPLICATION_JSON</span>)
<span style="color:#000080;font-weight:bold">public </span>ClientRepresentation create(ClientRepresentation clientRepresentation);

</pre>
                <br>
                <br>
                then the advantages will be:<br>
                - You won't need to parse the ID of newly created client
                from the URI location and call additional GET request to
                retrieve newly created client (You usually want newly
                created client when you are creating it)<br>
                - In case the error happened, the exception will be
                thrown on client-side too. With the "Response" object,
                the exception is not thrown on client-side but you are
                supposed to manually check the status code. This may be
                confusing for users, who are not so familiar with the
                admin client. When exception is thrown on client-side,
                it's crystal clear that something bad happened and
                client wasn't successfully created on server side.<br>
                <br>
                Are there any disadvantages? The only one I see is, that
                POST responses from server will need to return the
                representation of created object, but that's maybe
                rather advantage (as you don't need to call additional
                GET request, which in 95% of cases you need). <br>
                <span class="HOEnZb"><font color="#888888"> <br>
                    Marek</font></span>
                <div>
                  <div class="h5"><br>
                    <br>
                    On 30/05/16 08:04, Stian Thorgersen wrote:<br>
                  </div>
                </div>
              </div>
              <div>
                <div class="h5">
                  <blockquote type="cite">
                    <div dir="ltr">What's the status code for the
                      response? It should be 409.</div>
                    <div class="gmail_extra"><br>
                      <div class="gmail_quote">On 27 May 2016 at 09:02,
                        Haim Vana <span dir="ltr">&lt;<a
                            moz-do-not-send="true"
                            href="mailto:haimv@perfectomobile.com"
                            target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:haimv@perfectomobile.com">haimv@perfectomobile.com</a></a>&gt;</span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div> There is an exception in the server log,
                            but it is not thrown, so I am not getting it
                            in my code.
                            <div>
                              <div>
                                <div><br>
                                </div>
                                <div><br>
                                </div>
                                <div><br>
                                </div>
                                <div>-------- Original message --------</div>
                                <div>From: Stian Thorgersen &lt;<a
                                    moz-do-not-send="true"
                                    href="mailto:sthorger@redhat.com"
                                    target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:sthorger@redhat.com">sthorger@redhat.com</a></a>&gt;

                                </div>
                                <div>Date: 5/27/16 09:24 (GMT+02:00) </div>
                                <div>To: Haim Vana &lt;<a
                                    moz-do-not-send="true"
                                    href="mailto:haimv@perfectomobile.com"
                                    target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:haimv@perfectomobile.com">haimv@perfectomobile.com</a></a>&gt;
                                </div>
                                <div>Cc: Marek Posolda &lt;<a
                                    moz-do-not-send="true"
                                    href="mailto:mposolda@redhat.com"
                                    target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:mposolda@redhat.com">mposolda@redhat.com</a></a>&gt;,

                                  <a moz-do-not-send="true"
                                    href="mailto:keycloak-user@lists.jboss.org"
                                    target="_blank">keycloak-user@lists.jboss.org</a>
                                </div>
                                <div>Subject: Re: [keycloak-user] How to
                                  create the same client (same id) for
                                  multiple realms programmatically </div>
                                <div><br>
                                </div>
                                <div>
                                  <div dir="ltr">Do you not get a error
                                    when trying to create it the second
                                    time with the same id? If not please
                                    create a jira.</div>
                                  <div class="gmail_extra"><br>
                                    <div class="gmail_quote">On 26 May
                                      2016 at 20:20, Haim Vana <span
                                        dir="ltr">&lt;<a
                                          moz-do-not-send="true"
                                          href="mailto:haimv@perfectomobile.com"
                                          target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:haimv@perfectomobile.com">haimv@perfectomobile.com</a></a>&gt;</span>
                                      wrote:<br>
                                      <blockquote class="gmail_quote"
                                        style="margin:0 0 0
                                        .8ex;border-left:1px #ccc
                                        solid;padding-left:1ex">
                                        <div bgcolor="white"
                                          lang="EN-US">
                                          <div>
                                            <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Thanks

                                                for your reply.</span></p>
                                            <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                            <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">My

                                                problem was that I have
                                                used setId instead of
                                                setClientId.</span></p>
                                            <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                            <div>
                                              <div
                                                style="border:none;border-top:solid
                                                #e1e1e1
                                                1.0pt;padding:3.0pt 0in
                                                0in 0in">
                                                <p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:windowtext">From:</span></b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:windowtext">
                                                    Marek Posolda
                                                    [mailto:<a
                                                      moz-do-not-send="true"
href="mailto:mposolda@redhat.com" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:mposolda@redhat.com">mposolda@redhat.com</a></a>]
                                                    <br>
                                                    <b>Sent:</b>
                                                    Thursday, May 26,
                                                    2016 4:16 PM<br>
                                                    <b>To:</b> Haim Vana
                                                    &lt;<a
                                                      moz-do-not-send="true"
href="mailto:haimv@perfectomobile.com" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:haimv@perfectomobile.com">haimv@perfectomobile.com</a></a>&gt;;

                                                    <a
                                                      moz-do-not-send="true"
href="mailto:keycloak-user@lists.jboss.org" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a></a><br>
                                                    <b>Subject:</b> Re:
                                                    [keycloak-user] How
                                                    to create the same
                                                    client (same id) for
                                                    multiple realms
                                                    programmatically</span></p>
                                              </div>
                                            </div>
                                            <div>
                                              <div>
                                                <p class="MsoNormal"> </p>
                                                <div>
                                                  <p class="MsoNormal">You
                                                    can use for example:</p>
                                                  <pre style="background:white"><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">RealmResource realm1 = </span><b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif;color:#660e7a">adminClient</span></b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">.realms().realm(</span><b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif;color:green">"realm1"</span></b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">);</span></pre>
                                                  <pre style="background:white"><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">RealmResource realm2 = </span><b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif;color:#660e7a">adminClient</span></b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">.realms().realm(</span><b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif;color:green">"realm2"</span></b><span style="font-size:9.0pt;font-family:&quot;DejaVu Sans Mono&quot;,serif">);</span></pre>
                                                  <pre style="background:white"><span style="font-size:11.5pt;background:#e4e4ff">realm1</span><span style="font-size:11.5pt">.clients().create(clientRepresentation);</span></pre>
                                                  <pre style="background:white"><span style="font-size:11.5pt;background:#e4e4ff">realm</span><span style="font-size:11.5pt">2.clients().create(clientRepresentation);</span></pre>
                                                  <pre style="background:white"><span style="font-size:11.5pt"> </span></pre>
                                                  <p class="MsoNormal"><br>
                                                    For update you can
                                                    take a look at some
                                                    of our tests, which
                                                    are updating client.
                                                    For example this one
                                                    : <a
                                                      moz-do-not-send="true"
href="https://github.com/mposolda/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java#L183"
                                                      target="_blank">
<a class="moz-txt-link-freetext" href="https://github.com/mposolda/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java#L183">https://github.com/mposolda/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java#L183</a></a><br>
                                                    <br>
                                                    Note that you need
                                                    to know client Id
                                                    (this is different
                                                    thant clientId). The
                                                    easiest is to set it
                                                    manually in
                                                    representation
                                                    before you create
                                                    client (via
                                                    client.setId ) like
                                                    it's done in this
                                                    test.<br>
                                                    <br>
                                                    Marek<br>
                                                    <br>
                                                    On 26/05/16 14:54,
                                                    Haim Vana wrote:</p>
                                                </div>
                                                <blockquote
                                                  style="margin-top:5.0pt;margin-bottom:5.0pt">
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Any

                                                      idea regarding the
                                                      below ?</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">As

                                                      a workaround how
                                                      can I update
                                                      existing client
                                                      programmatically ?
                                                      I couldn't find it
                                                      in the admin API.</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Thanks

                                                      again,</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Haim.</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <div>
                                                    <div
                                                      style="border:none;border-top:solid
                                                      #e1e1e1
                                                      1.0pt;padding:3.0pt
                                                      0in 0in 0in">
                                                      <p
                                                        class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">
                                                          Haim Vana <br>
                                                          <b>Sent:</b>
                                                          Thursday, May
                                                          26, 2016 2:17
                                                          PM<br>
                                                          <b>To:</b> <a
moz-do-not-send="true" href="mailto:keycloak-user@lists.jboss.org"
                                                          target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a></a><br>
                                                          <b>Subject:</b>
                                                          How to create
                                                          the same
                                                          client (same
                                                          id) for
                                                          multiple
                                                          realms
                                                          programmatically
                                                        </span></p>
                                                    </div>
                                                  </div>
                                                  <p class="MsoNormal"> </p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Hi,</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">I
                                                      am trying to
                                                      create the same
                                                      client for many
                                                      realms, however it
                                                      creates it only
                                                      once, probably
                                                      because they have
                                                      the same id,
                                                      however in UI I am
                                                      able to create it.</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">Any

                                                      idea how I can
                                                      create the same
                                                      client for
                                                      different realms
                                                      programmatically
                                                      with the same id ?</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:#1f497d">This

                                                      is my code sample:</span></p>
                                                  <pre style="background:white"><span style="font-size:11.5pt">ClientRepresentation clientRepresentation = </span><b><span style="font-size:11.5pt;color:navy">new </span></b><span style="font-size:11.5pt">ClientRepresentation();</span></pre>
                                                  <pre style="background:white"><span style="font-size:11.5pt">clientRepresentation.setId(clientId); // Same clientId for all reamls</span></pre>
                                                  <p class="MsoNormal"
                                                    style="background:white"><span
style="font-size:11.5pt">realm</span><span>.clients().create(clientRepresentation);

                                                      // Client is
                                                      created only for
                                                      first realm</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> </span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">Any
                                                      advice will be
                                                      appreciated,</span></p>
                                                  <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">Haim.</span></p>
                                                  <p class="MsoNormal">The
                                                    information
                                                    contained in this
                                                    message is
                                                    proprietary to the
                                                    sender, protected
                                                    from disclosure, and
                                                    may be privileged.
                                                    The information is
                                                    intended to be
                                                    conveyed only to the
                                                    designated
                                                    recipient(s) of the
                                                    message. If the
                                                    reader of this
                                                    message is not the
                                                    intended recipient,
                                                    you are hereby
                                                    notified that any
                                                    dissemination, use,
                                                    distribution or
                                                    copying of this
                                                    communication is
                                                    strictly prohibited
                                                    and may be unlawful.
                                                    If you have received
                                                    this communication
                                                    in error, please
                                                    notify us
                                                    immediately by
                                                    replying to the
                                                    message and deleting
                                                    it from your
                                                    computer. Thank you.
                                                    <br>
                                                    <br>
                                                    <br>
                                                  </p>
                                                  <pre>_______________________________________________</pre>
                                                  <pre>keycloak-user mailing list</pre>
                                                  <pre><a moz-do-not-send="true" href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a></pre>
                                                  <pre><a moz-do-not-send="true" href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
                                                </blockquote>
                                                <p class="MsoNormal"> </p>
                                              </div>
                                            </div>
                                          </div>
                                          <div>
                                            <div>The information
                                              contained in this message
                                              is proprietary to the
                                              sender, protected from
                                              disclosure, and may be
                                              privileged. The
                                              information is intended to
                                              be conveyed only to the
                                              designated recipient(s) of
                                              the message. If the reader
                                              of this message is not the
                                              intended recipient, you
                                              are hereby notified that
                                              any dissemination, use,
                                              distribution or copying of
                                              this communication is
                                              strictly prohibited and
                                              may be unlawful. If you
                                              have received this
                                              communication in error,
                                              please notify us
                                              immediately by replying to
                                              the message and deleting
                                              it from your computer.
                                              Thank you. </div>
                                          </div>
                                        </div>
                                        <br>
_______________________________________________<br>
                                        keycloak-user mailing list<br>
                                        <a moz-do-not-send="true"
                                          href="mailto:keycloak-user@lists.jboss.org"
                                          target="_blank">keycloak-user@lists.jboss.org</a><br>
                                        <a moz-do-not-send="true"
                                          href="https://lists.jboss.org/mailman/listinfo/keycloak-user"
                                          rel="noreferrer"
                                          target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
                                      </blockquote>
                                    </div>
                                    <br>
                                  </div>
                                </div>
                                The information contained in this
                                message is proprietary to the sender,
                                protected from disclosure, and may be
                                privileged. The information is intended
                                to be conveyed only to the designated
                                recipient(s) of the message. If the
                                reader of this message is not the
                                intended recipient, you are hereby
                                notified that any dissemination, use,
                                distribution or copying of this
                                communication is strictly prohibited and
                                may be unlawful. If you have received
                                this communication in error, please
                                notify us immediately by replying to the
                                message and deleting it from your
                                computer. Thank you. </div>
                            </div>
                          </div>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>