feed query initial code
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 11 Aug 2011 12:49:52 +0000 (16:49 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 11 Aug 2011 12:49:52 +0000 (16:49 +0400)
.idea/libraries/commons_http.xml [new file with mode: 0644]
nuget-server/nuget-server.iml
nuget-server/src/META-INF/build-server-plugin-nuget.xml
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedClient.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedConstants.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/NuGetFeedReader.java [new file with mode: 0644]
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/FeedReaderTest.java [new file with mode: 0644]

diff --git a/.idea/libraries/commons_http.xml b/.idea/libraries/commons_http.xml
new file mode 100644 (file)
index 0000000..e02ee9b
--- /dev/null
@@ -0,0 +1,23 @@
+<component name="libraryTable">\r
+  <library name="commons-http">\r
+    <CLASSES>\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/httpclient-cache-4.1.2.jar!/" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/httpclient-4.1.2.jar!/" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/httpcore-4.1.2.jar!/" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/httpmime-4.1.2.jar!/" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/commons-codec-1.4.jar!/" />\r
+    </CLASSES>\r
+    <JAVADOC />\r
+    <SOURCES>\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-client-4.1.2-src.zip!/httpcomponents-client-4.1.2/httpmime/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-client-4.1.2-src.zip!/httpcomponents-client-4.1.2/httpclient-contrib/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-client-4.1.2-src.zip!/httpcomponents-client-4.1.2/httpclient-benchmark/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-client-4.1.2-src.zip!/httpcomponents-client-4.1.2/httpclient/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-core-4.1.2-src.zip!/httpcomponents-core-4.1.2/httpcore/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-core-4.1.2-src.zip!/httpcomponents-core-4.1.2/httpcore-nio/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-core-4.1.2-src.zip!/httpcomponents-core-4.1.2/httpcore-contrib/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-core-4.1.2-src.zip!/httpcomponents-core-4.1.2/httpcore-benchmark/src/main/java" />\r
+      <root url="jar://$PROJECT_DIR$/lib/httpcomponents-client/src/httpcomponents-core-4.1.2-src.zip!/httpcomponents-core-4.1.2/httpcore-ab/src/main/java" />\r
+    </SOURCES>\r
+  </library>\r
+</component>
\ No newline at end of file
index 0eff86e9fa55d18d4a77008ed3f00e7b79a57600..0f769ff91571929f7496c248e83bf8a4be58b893 100644 (file)
@@ -38,6 +38,7 @@
     <orderEntry type="library" name="Servlet Api" level="project" />\r
     <orderEntry type="module" module-name="nuget-common" />\r
     <orderEntry type="library" name="Common-Impl" level="project" />\r
+    <orderEntry type="library" name="commons-http" level="project" />\r
   </component>\r
 </module>\r
 \r
index 603fd6f08a5dc72c626a3e15e5c08dca43519c96..81159e567d0c716ad31f007fbd6610d7c71e2035 100644 (file)
@@ -30,4 +30,9 @@
 \r
   <bean class="jetbrains.buildServer.nuget.server.publish.PublishRunTypeRegistrar"/>\r
   <bean class="jetbrains.buildServer.nuget.server.publish.PublishRunType"/>\r
+\r
+\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.FeedClient" destroy-method="dispose"/>\r
+  <bean class="jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader"/>\r
+\r
 </beans>
\ No newline at end of file
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedClient.java b/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedClient.java
new file mode 100644 (file)
index 0000000..40331c4
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.feed.reader;\r
+\r
+import org.apache.http.client.HttpClient;\r
+import org.apache.http.impl.client.DefaultHttpClient;\r
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;\r
+import org.apache.http.params.HttpConnectionParams;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 11.08.11 16:24\r
+ */\r
+public class FeedClient {\r
+  private final HttpClient myClient;\r
+\r
+  public FeedClient() {\r
+    myClient = new DefaultHttpClient(new ThreadSafeClientConnManager());\r
+    HttpConnectionParams.setConnectionTimeout(myClient.getParams(), 10000);\r
+    HttpConnectionParams.setSoTimeout(myClient.getParams(), 10000);\r
+  }\r
+\r
+  @NotNull\r
+  public HttpClient getClient() {\r
+    return myClient;\r
+  }\r
+\r
+  public void dispose() {\r
+    myClient.getConnectionManager().shutdown();\r
+  }\r
+\r
+}\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedConstants.java b/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/FeedConstants.java
new file mode 100644 (file)
index 0000000..8b3b7db
--- /dev/null
@@ -0,0 +1,25 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.feed.reader;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 11.08.11 16:04\r
+ */\r
+public class FeedConstants {\r
+  public static final String FEED_URL = "https://go.microsoft.com/fwlink/?LinkID=206669";\r
+}\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/NuGetFeedReader.java b/nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/NuGetFeedReader.java
new file mode 100644 (file)
index 0000000..f0e05c2
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.server.feed.reader;\r
+\r
+import org.apache.http.HttpHeaders;\r
+import org.apache.http.HttpResponse;\r
+import org.apache.http.client.methods.HttpGet;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 11.08.11 15:42\r
+ */\r
+public class NuGetFeedReader {\r
+  private FeedClient myClient;\r
+\r
+  public NuGetFeedReader(FeedClient client) {\r
+    myClient = client;\r
+  }\r
+\r
+  public void queryPackage(@NotNull String feedUrl,\r
+                           @NotNull String packageId) throws IOException {\r
+    HttpGet get = new HttpGet(feedUrl + "/Packages()");\r
+    get.getParams().setParameter("$filter", "Id eq '" + packageId + "'");\r
+    get.setHeader(HttpHeaders.ACCEPT_ENCODING, "application/xml");\r
+    final HttpResponse execute = myClient.getClient().execute(get);\r
+\r
+    System.out.println(execute);\r
+    execute.getEntity().writeTo(System.out);\r
+  }\r
+}\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/FeedReaderTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/FeedReaderTest.java
new file mode 100644 (file)
index 0000000..bd26772
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.integration;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedClient;\r
+import jetbrains.buildServer.nuget.server.feed.reader.FeedConstants;\r
+import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;\r
+import org.testng.annotations.AfterMethod;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 11.08.11 16:04\r
+ */\r
+public class FeedReaderTest extends BaseTestCase {\r
+  private NuGetFeedReader myReader;\r
+  private FeedClient myClient;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    myClient = new FeedClient();\r
+    myReader = new NuGetFeedReader(myClient);\r
+  }\r
+\r
+  @AfterMethod\r
+  @Override\r
+  protected void tearDown() throws Exception {\r
+    super.tearDown();\r
+    myClient.dispose();\r
+  }\r
+\r
+  @Test\r
+  public void testRead() throws IOException {\r
+    myReader.queryPackage(FeedConstants.FEED_URL, "NuGet.CommandLine");\r
+  }\r
+}\r