URL Build Trigger Plugin - Endpoint Issue

Hello, I am attempting to use the URL Build Trigger plugin (found here: https://confluence.jetbrains.com/display/TW/Url+Build+Trigger) with an endpoint that retuns "application/json".
Is this possible?

I am using the following to a service endpoint:
http://localhost:21383/api/builds/SXA70-Rel

When I do I get,

URL build trigger failed with error: URL http://localhost:21383/api/builds/SXA70-Rel: Connection reset
Hide stacktrace

jetbrains.buildServer.buildTriggers.BuildTriggerException: URL build trigger failed with error: URL http://localhost:21383/api/builds/SXA70-Rel: Connection reset
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2.makeTriggerException(UrlBuildTrigger.java:117)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger.processJobResults(AsyncPolledBuildTrigger.java:145)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger.triggerBuild(AsyncPolledBuildTrigger.java:59)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker$4.run(BuildTriggersChecker.java:2)
at jetbrains.buildServer.util.NamedThreadFactory.executeWithNewThreadName(NamedThreadFactory.java:89)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.callTrigger(BuildTriggersChecker.java:67)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.access$900(BuildTriggersChecker.java:71)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker$BuildTriggersGroup.processTriggers(BuildTriggersChecker.java:30)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.triggerBuilds(BuildTriggersChecker.java:75)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$4.doSomething(BuildServerRunner.java:2)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$BuildServerWorker.runAction(BuildServerRunner.java:23)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$BuildServerWorker.run(BuildServerRunner.java:44)
at java.lang.Thread.run(Thread.java:745)
Caused by: jetbrains.buildServer.buildTriggers.async.DetectionException: URL http://localhost:21383/api/builds/SXA70-Rel: Connection reset
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger.createThrowableResult(UrlBuildTrigger.java:203)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger.access$700(UrlBuildTrigger.java:39)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2$1.perform(UrlBuildTrigger.java:169)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger$2.run(AsyncPolledBuildTrigger.java:171)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
... 1 more
Caused by: jetbrains.buildServer.buildTriggers.url.ResourceHashProviderException: URL http://localhost:21383/api/builds/SXA70-Rel: Connection reset
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getResourceHash(HttpResourceHashProvider.java:107)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2$1.perform(UrlBuildTrigger.java:148)
... 4 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:152)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:270)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at sun.reflect.GeneratedMethodAccessor257.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
at com.sun.proxy.$Proxy209.receiveResponseHeader(Unknown Source)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.sendRequest(HttpResourceHashProvider.java:206)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getHttpHeaders(HttpResourceHashProvider.java:182)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getResourceHash(HttpResourceHashProvider.java:87)
... 5 more






If it change the output of the service to "text/plain" (http://localhost:21383/api/builds/SXA70-Rel?showAsText=true) I get this:



URL build trigger failed with error: URL http://localhost:21383/api/builds/SXA70-Rel?showAsText=true: Connection reset
Hide stacktrace

jetbrains.buildServer.buildTriggers.BuildTriggerException: URL build trigger failed with error: URL http://localhost:21383/api/builds/SXA70-Rel?showAsText=true: Connection reset
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2.makeTriggerException(UrlBuildTrigger.java:117)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger.processJobResults(AsyncPolledBuildTrigger.java:145)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger.triggerBuild(AsyncPolledBuildTrigger.java:59)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker$4.run(BuildTriggersChecker.java:2)
at jetbrains.buildServer.util.NamedThreadFactory.executeWithNewThreadName(NamedThreadFactory.java:89)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.callTrigger(BuildTriggersChecker.java:67)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.access$900(BuildTriggersChecker.java:71)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker$BuildTriggersGroup.processTriggers(BuildTriggersChecker.java:30)
at jetbrains.buildServer.serverSide.impl.BuildTriggersChecker.triggerBuilds(BuildTriggersChecker.java:75)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$4.doSomething(BuildServerRunner.java:2)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$BuildServerWorker.runAction(BuildServerRunner.java:23)
at jetbrains.buildServer.serverSide.impl.BuildServerRunner$BuildServerWorker.run(BuildServerRunner.java:44)
at java.lang.Thread.run(Thread.java:745)
Caused by: jetbrains.buildServer.buildTriggers.async.DetectionException: URL http://localhost:21383/api/builds/SXA70-Rel?showAsText=true: Connection reset
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger.createThrowableResult(UrlBuildTrigger.java:203)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger.access$700(UrlBuildTrigger.java:39)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2$1.perform(UrlBuildTrigger.java:169)
at jetbrains.buildServer.buildTriggers.async.impl.AsyncPolledBuildTrigger$2.run(AsyncPolledBuildTrigger.java:171)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
... 1 more
Caused by: jetbrains.buildServer.buildTriggers.url.ResourceHashProviderException: URL http://localhost:21383/api/builds/SXA70-Rel?showAsText=true: Connection reset
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getResourceHash(HttpResourceHashProvider.java:107)
at jetbrains.buildServer.buildTriggers.url.UrlBuildTrigger$2$1.perform(UrlBuildTrigger.java:148)
... 4 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:152)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:270)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at sun.reflect.GeneratedMethodAccessor257.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
at com.sun.proxy.$Proxy209.receiveResponseHeader(Unknown Source)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.sendRequest(HttpResourceHashProvider.java:206)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getHttpHeaders(HttpResourceHashProvider.java:182)
at jetbrains.buildServer.buildTriggers.url.HttpResourceHashProvider.getResourceHash(HttpResourceHashProvider.java:87)
... 5 more



When I use this endpoint in a browser on the TC server, I get the data result expected returned from the service call.


Should this work? What do I need to do differently?
4 comments
Comment actions Permalink

Hi Rufus,

URL trigger just sends an HTTP request (the code can be seen in the sources). Seems like it does not set "Accept" header.
It is then the server part which probably drops the connection resulting in "connection reset".

What is handling "/api/builds/*" path on the server and what server is that?

0
Comment actions Permalink

Yegor,

Thanks for the reply.

I see, so is there something you'd recommend I do on the server-side to get the plugin to behave nicely or do I need to modify the source and build it myself to set an Accept header?

That is a custom Web API service I wrote that retrieves the data we want to use as a trigger for our build and returns it as JSON.

0
Comment actions Permalink

Based on what you are saying, it seems like I would add an ACCEPT header here?


  public String getResourceHash(@NotNull TriggerParameters triggerParameters) throws ResourceHashProviderException {
    CloseableHttpClient httpClient = null;


    final String old = triggerParameters.getOldHash();


    try {
      final URI uri = new URL(triggerParameters.getURL()).toURI();
      final String username = triggerParameters.getUsername();
      final String password = triggerParameters.getPassword();
      final Integer connectionTimeout = triggerParameters.getConnectionTimeout();


      httpClient = createClient(uri, username, password, connectionTimeout);


      // Let's try HEAD request, check headers
      Map<String, String> map = null;
      if (!StringUtil.isEmptyOrSpaces(old)) {
        if (old.startsWith("W/") || old.startsWith("\"")) {
          // Seems it's ETag
          map = Collections.singletonMap(HttpHeaders.IF_NONE_MATCH, old);
        } else if (DateUtils.parseDate(old) != null) {
          // It's date from Last-Modified
          map = Collections.singletonMap(HttpHeaders.IF_MODIFIED_SINCE, old);
        }
      }


      map.put(HttpHeaders.ACCEPT, "*/*");


      final Header[] headers = getHttpHeaders(httpClient, uri, map);

0
Comment actions Permalink

So I did end up pulling down the source from your SVN repository and after unsuccessfully attempting to use ANT to build the plugin straight from the source, I switched to using IntelliJ Idea 14 CE.

I then was able to make my change noted above and build and generate the .zip artifacts. Then the plugin wouldn't show up in list of available plugins when I was modifying my project Triggers. It was at this point that I realized I had installed and built against the JDK 1.8 and TC 9.02 (which is what is running on my build server) is built on JDK 1.7.

Fast-forward, I got it built again against JDK 1.7, re-deployed and re-configured on my project Triggers definition, but alas... it STILL gave me the exception in my OP... argh!

Then I realized after staring at the plugin code for a bit more, that HttpHead was sending a HEAD request to my custom web service that it was not handling... doh. So, in my .NET WebAPI service, I had to add support for handling and responding to a HEAD verb.

Voila! I now get no more exception.

Thanks!

0

Please sign in to leave a comment.