Skip to content
Browse files

Update src/main/java/de/mb/NexusMetadataBuilder.java

Updated Nexus connection test from plugin configuration page
  • Loading branch information...
1 parent 7ddc5e3 commit be746827e0aafe2e7c48c12c474b4c6f04490fe6 @marcelbirkner committed Aug 13, 2012
Showing with 22 additions and 23 deletions.
  1. +22 −23 src/main/java/de/mb/NexusMetadataBuilder.java
View
45 src/main/java/de/mb/NexusMetadataBuilder.java
@@ -157,7 +157,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
return true;
}
- private WebResource getService(final String url, final String user,
+ private static WebResource getService(final String url, final String user,
final Secret password) {
// setup REST-Client
ClientConfig config = new DefaultClientConfig();
@@ -201,28 +201,6 @@ private static CustomMetadataRequest getCustomMetadataRequest(String namespace,
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}
-
- public FormValidation doTestConnection(
- @QueryParameter("nexusUrl") final String nexusUrl,
- @QueryParameter("nexusUser") final String nexusUser,
- @QueryParameter("nexusPassword") final String nexusPassword) throws IOException, ServletException {
-
- System.out.println("doTestConnection");
- try {
- WebResource service = getService(nexusUrl, nexusUser, Secret.fromString( nexusPassword ) );
- String nexusStatus = service.path("service").path("local").path("status").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class).toString();
- System.out.println("doTestConnection " + nexusStatus);
- if( ! nexusStatus.contains( "200 OK") ) {
- System.out.println("Failed");
- return FormValidation.error("Failed. Please check the configuration.");
- }
-
- return FormValidation.ok("Success");
- } catch (Exception e) {
- System.out.println("Exception " + e.getMessage() );
- return FormValidation.error("Client error : " + e.getMessage());
- }
- }
/**
* Descriptor for {@link NexusMetadataBuilder}. Used as a singleton.
@@ -295,6 +273,27 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
save();
return super.configure(req,formData);
}
+
+ /**
+ * Nexus connection test
+ */
+ public FormValidation doTestConnection(
+ @QueryParameter("nexusUrl") final String nexusUrl,
+ @QueryParameter("nexusUser") final String nexusUser,
+ @QueryParameter("nexusPassword") final String nexusPassword) throws IOException, ServletException {
+
+ try {
+ WebResource service = getService(nexusUrl, nexusUser, Secret.fromString( nexusPassword ) );
+ ClientResponse nexusStatus = service.path("service").path("local").path("status").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+ if( nexusStatus.getStatus() == 200 ) {
+ return FormValidation.ok("Success. Connection with Nexus Repository verified.");
+ }
+ return FormValidation.error("Failed. Please check the configuration. HTTP Status: " + nexusStatus);
+ } catch (Exception e) {
+ System.out.println("Exception " + e.getMessage() );
+ return FormValidation.error("Client error : " + e.getMessage());
+ }
+ }
public String getNexusUrl() {
return nexusUrl;

0 comments on commit be74682

Please sign in to comment.
Something went wrong with that request. Please try again.