Skip to content

Commit 6a8b2ca

Browse files
merged from origin
Former-commit-id: 58510e7a9e8cee0299cfd502485132cbc2192d1d
2 parents 7adf74a + 9e54b7f commit 6a8b2ca

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<artifactId>httpclient</artifactId>
2020
<version>4.5.6</version>
2121
</dependency>
22+
2223
<dependency>
2324
<groupId>org.apache.httpcomponents</groupId>
2425
<artifactId>fluent-hc</artifactId>
@@ -29,5 +30,11 @@
2930
<artifactId>commons-cli</artifactId>
3031
<version>1.3.1</version>
3132
</dependency>
33+
<dependency>
34+
<groupId>org.apache.httpcomponents</groupId>
35+
<artifactId>httpmime</artifactId>
36+
<version>4.5.6</version>
37+
</dependency>
38+
3239
</dependencies>
3340
</project>

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/ARUUtil.java

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.oracle.weblogicx.imagebuilder.builder.util;
22

33
import java.io.IOException;
4+
import java.util.List;
45

56
import javax.xml.parsers.DocumentBuilder;
67
import javax.xml.parsers.DocumentBuilderFactory;
@@ -9,7 +10,6 @@
910

1011
import org.w3c.dom.Document;
1112
import org.w3c.dom.Element;
12-
import org.w3c.dom.Node;
1313
import org.w3c.dom.NodeList;
1414

1515
public class ARUUtil {
@@ -19,8 +19,37 @@ public void getAllWLSReleases(String userId, String password) throws IOException
1919
getAllReleases("wls", userId, password);
2020
}
2121

22-
public void getLatestWLSPatches(String version, String userId, String password) throws IOException {
23-
getLatestReleases("wls", version, userId, password);
22+
public void getLatestWLSPatches(String release, String userId, String password) throws IOException {
23+
getLatestPSU("wls", release, userId, password);
24+
}
25+
26+
public void getPatches(String category, List<String> patches, String userId, String password) throws IOException {
27+
for (String patch : patches)
28+
getPatch("wls", patch, userId, password);
29+
}
30+
31+
public void validatePatches(List<String> patches, String category, String version) {
32+
33+
// TODO
34+
35+
// find the release number first based on the version
36+
// build the xml
37+
38+
// <conflict_check_request>
39+
// <platform>912</platform>
40+
// <target_patch_list>
41+
// <installed_patch/>
42+
// </target_patch_list>
43+
// <candidate_patch_list>
44+
// <patch_group rel_id="80111060" language_id="0">7044721</patch_group>
45+
// <patch_group rel_id="80111060" language_id="0">7156923</patch_group>
46+
// <patch_group rel_id="80111060" language_id="0">7210195</patch_group>
47+
// <patch_group rel_id="80111060" language_id="0">7256747</patch_group>
48+
// </candidate_patch_list>
49+
//</conflict_check_request>
50+
51+
// Run against POST /Orion/Services/conflict_checks
52+
2453
}
2554

2655
private Document getAllReleases(String category, String userId, String password) throws IOException {
@@ -29,7 +58,7 @@ private Document getAllReleases(String category, String userId, String password)
2958
// "https://updates.oracle.com/Orion/Services/metadata?table=aru_releases" -o allarus.xml)
3059

3160
Document allReleases = HttpUtil.getXMLContent("https://updates.oracle"
32-
+ ".com/Orion/Services/metadata?table=aru_releases");
61+
+ ".com/Orion/Services/metadata?table=aru_releases", userId, password);
3362

3463
try {
3564

@@ -62,31 +91,60 @@ private Document getAllReleases(String category, String userId, String password)
6291

6392
}
6493

65-
private void getLatestReleases(String category, String version, String userId, String password) throws IOException {
94+
private void getLatestPSU(String category, String release, String userId, String password) throws IOException {
6695

6796
// HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
6897

6998

7099
Document allPatches = HttpUtil.getXMLContent("https://updates.oracle"
71-
+ ".com/Orion/Services/search?product=15991&release=" + version);
100+
+ ".com/Orion/Services/search?product=15991&release=" + release, userId, password);
101+
102+
savepatch(allPatches, userId, password);
103+
}
104+
105+
private void getPatch(String category, String patchNumber, String userId, String password) throws IOException {
106+
107+
// HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
108+
109+
110+
Document allPatches = HttpUtil.getXMLContent("https://updates.oracle"
111+
+ ".com/Orion/Services/search?product=15991&bug=" + patchNumber, userId, password);
112+
113+
savepatch(allPatches, userId, password);
114+
115+
116+
117+
}
72118

119+
private void savepatch(Document allPatches, String userId, String password) throws IOException {
73120
try {
121+
122+
// TODO: needs to make sure there is one and some filtering if not sorting
123+
74124
String downLoadLink = XPathUtil.applyXPathReturnString(allPatches, "string"
75125
+ "(/results/patch[1]/files/file/download_url/text())");
76126

77127
String doloadHost = XPathUtil.applyXPathReturnString(allPatches, "string"
78128
+ "(/results/patch[1]/files/file/download_url/@host)");
79129

130+
String bugname = XPathUtil.applyXPathReturnString(allPatches, "string"
131+
+ "(/results/patch[1]/name");
132+
133+
// TODO find the download location
134+
135+
String fileName = bugname + ".zip";
80136

81-
HttpUtil.downloadFile(doloadHost+downLoadLink, "todo");
137+
HttpUtil.downloadFile(doloadHost+downLoadLink, fileName, userId, password);
138+
139+
// TODO need method to update the cache data table ?
82140

83141
} catch (XPathExpressionException xpe) {
84142
throw new IOException(xpe);
85143
}
86144

145+
}
87146

88147

89-
}
90148

91149
}
92150

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/HttpUtil.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
import javax.xml.parsers.DocumentBuilderFactory;
99
import javax.xml.parsers.ParserConfigurationException;
1010

11+
import org.apache.http.HttpEntity;
1112
import org.apache.http.client.ClientProtocolException;
1213
import org.apache.http.client.CookieStore;
1314
import org.apache.http.client.config.RequestConfig;
1415
import org.apache.http.client.fluent.Executor;
1516
import org.apache.http.client.fluent.Request;
17+
import org.apache.http.entity.mime.HttpMultipartMode;
18+
import org.apache.http.entity.mime.MultipartEntityBuilder;
1619
import org.apache.http.impl.client.BasicCookieStore;
1720
import org.apache.http.impl.client.CloseableHttpClient;
1821
import org.apache.http.impl.client.HttpClientBuilder;
@@ -86,6 +89,36 @@ public static void downloadFile(String url, String destination, String username,
8689

8790
}
8891

92+
public static String checkConflicts(String url, String payload, String username, String password) throws
93+
IOException {
94+
RequestConfig.Builder config = RequestConfig.custom();
95+
config.setCircularRedirectsAllowed(true);
96+
97+
CookieStore cookieStore = new BasicCookieStore();
98+
99+
CloseableHttpClient client = HttpClientBuilder.create()
100+
.setDefaultRequestConfig(config.build())
101+
.useSystemProperties()
102+
.build();
103+
104+
Executor httpExecutor = Executor.newInstance(client).auth(username, password);
105+
httpExecutor.use(cookieStore);
106+
107+
HttpEntity entity = MultipartEntityBuilder.create()
108+
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
109+
.addTextBody("request_xml", payload)
110+
.build();
111+
112+
String result = httpExecutor.execute(Request.Post(url)
113+
.connectTimeout(30000)
114+
.socketTimeout(30000)
115+
.body(entity)
116+
).returnContent().asString();
117+
118+
System.out.println(result);
119+
return result;
120+
}
121+
89122

90123
public static void main(String args[]) throws IOException {
91124

0 commit comments

Comments
 (0)