Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand All @@ -18,6 +19,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.versionone</groupId>
<artifactId>VersionOne.SDK.Java.APIClient</artifactId>
<version>16.1.0</version>
<version>16.1.1</version>
<packaging>jar</packaging>

<name>VersionOne.SDK.Java.APIClient</name>
Expand Down Expand Up @@ -76,6 +76,7 @@
</properties>

<build>
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
<plugins>
<!-- Write manifest properties -->
<plugin>
Expand All @@ -87,6 +88,9 @@
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
Expand Down Expand Up @@ -131,7 +135,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>VersionOne.JavaSDK-${project.version}</finalName>
<finalName>VersionOne.SDK.APIClient-${project.version}.${buildNumber}</finalName>
<descriptors>
<descriptor>${basedir}/assembly.xml</descriptor>
</descriptors>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/versionone/apiclient/MetaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.Reader;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -249,7 +250,7 @@ private Document createDocument(String token) throws V1Exception {
reader = _connector.getData(token);
}else {
_v1Connector.useMetaAPI();
reader = _v1Connector.getData(token);
reader = _v1Connector.getData(URLEncoder.encode(token));
}

rc = XMLHandler.buildDocument(reader, token);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/versionone/apiclient/SelectionBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.versionone.apiclient;

import java.net.URLEncoder;

import com.versionone.apiclient.services.BuildResult;
import com.versionone.apiclient.services.QueryBuilder;

Expand All @@ -15,9 +17,9 @@ protected void doBuild(Query query, BuildResult result) {
if (query.getSelection().size() == 1 && !query.getOid().isNull()) {
result.pathParts.add(query.getSelection().get(0).getName());
} else if (query.getSelection().size() > 0) {
result.querystringParts.add("sel=" + query.getSelection().getToken());
result.addQueryParameter("sel", query.getSelection().getToken());
} else {
result.querystringParts.add("sel=");
result.addQueryParameter("sel", "");
}
}
}
14 changes: 11 additions & 3 deletions src/main/java/com/versionone/apiclient/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public QueryResult retrieve(Query query) throws ConnectionException, APIExceptio
reader = _v1Connector.getData(queryUrl);
}
Document doc = XMLHandler.buildDocument(reader, queryUrl);
return parseQueryResult(doc.getDocumentElement(), query);
Element root = doc.getDocumentElement();
removeEmptyTextNodes(root);
return parseQueryResult(root, query);

} catch (ConnectionException ex) {
if (ex.getServerResponseCode() == 404) {
Expand Down Expand Up @@ -179,6 +181,8 @@ public Asset createNew(IAssetType assetType, Oid context) throws V1Exception {
}

Document doc = XMLHandler.buildDocument(reader, path);
Element root = doc.getDocumentElement();
removeEmptyTextNodes(root);
return parseNewAssetNode(doc.getDocumentElement(), assetType);
} catch (Exception ex) {
throw new APIException("Failed to create new asset!", assetType.getToken(), ex);
Expand Down Expand Up @@ -211,7 +215,9 @@ public Oid executeOperation(IOperation op, Oid oid) throws APIException {
reader = _v1Connector.sendData(path, "");
}
Document doc = XMLHandler.buildDocument(reader, path);
Asset asset = parseAssetNode(doc.getDocumentElement());
Element root = doc.getDocumentElement();
removeEmptyTextNodes(root);
Asset asset = parseAssetNode(root);
return asset.getOid();
} catch (Exception ex) {
throw new APIException("Error executing Operation!", op.getName(), ex);
Expand Down Expand Up @@ -332,7 +338,9 @@ public void save(Asset asset, String comment) throws APIException, ConnectionExc
reader = _v1Connector.sendData(path, data);
}
Document doc = XMLHandler.buildDocument(reader, path);
parseSaveAssetNode(doc.getDocumentElement(), asset);
Element root = doc.getDocumentElement();
removeEmptyTextNodes(root);
parseSaveAssetNode(root, asset);
} catch (OidException e) {
throw new APIException("Error processing response", e);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/versionone/apiclient/SortBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SortBuilder extends QueryBuilder {
@Override
protected void doBuild(Query query, BuildResult result) {
if (query.getOrderBy().size() > 0) {
result.querystringParts.add("sort=" + query.getOrderBy().getToken());
result.addQueryParameter("sort", query.getOrderBy().getToken());
}
}
}
39 changes: 34 additions & 5 deletions src/main/java/com/versionone/apiclient/V1APIConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
Expand All @@ -15,9 +17,6 @@
import java.util.Locale;
import java.util.Map;

import sun.net.www.protocol.http.AuthCacheImpl;
import sun.net.www.protocol.http.AuthCacheValue;

import com.versionone.apiclient.exceptions.ConnectionException;
import com.versionone.apiclient.exceptions.SecurityException;
import com.versionone.apiclient.interfaces.IAPIConnector;
Expand Down Expand Up @@ -93,15 +92,45 @@ public V1APIConnector(String url, String userName, String password, ProxyProvide
_url = url;
cookiesManager = CookiesManager.getCookiesManager(url, userName, password);

// WORKAROUND: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6626700
if (userName != null) {
AuthCacheValue.setAuthCache(new AuthCacheImpl());
// WORKAROUND: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6626700
cacheClearWorkaround();
Authenticator.setDefault(new Credentials(userName, password));
}

//Set a default user-agent header
setUserAgentHeader(null, null);
}

private static int getVersion() {
String version = System.getProperty("java.version");
if(version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if(dot != -1) { version = version.substring(0, dot); }
} return Integer.parseInt(version);
}

private void cacheClearWorkaround() {
if (V1APIConnector.getVersion() >= 9) {
return;
}
try {
Class<?> authCacheValueClazz = Class.forName("sun.net.www.protocol.http.AuthCacheValue");
Class<?> authCacheImplClazz = Class.forName("sun.net.www.protocol.http.AuthCacheImpl");
Object authCacheImpl = authCacheImplClazz.newInstance();
Method setAuthCacheMethod = authCacheValueClazz.getMethod("setAuthCache", authCacheImplClazz);
setAuthCacheMethod.invoke(authCacheValueClazz, authCacheImpl);
} catch (ClassNotFoundException cnfe) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (NoSuchMethodException e) {
} catch (java.lang.SecurityException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
}

/**
* Set a value for custom the user-agent header.
Expand Down
Loading