gpt4 book ai didi

java - 如何在 java 中为 Oracle Identity Management JSON 创建 JSON 对象

转载 作者:行者123 更新时间:2023-11-30 03:14:55 24 4
gpt4 key购买 nike

我有以下 json 来解析 int JSONObject 并通过 http 客户端发送它,以使用其 OIM 11g PS3OIM 11g PS3 中创建用户强>REST API。

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.ParseException;
public class OimApi {

@SuppressWarnings("deprecation")
public static void main(String[] args) throws JSONException, ParseException {
//String url="http://ussltc7146v.dev.sltc.com:14000/idaas/im/scim/v1/Users";
//JsonPack oimRequest = new JsonPack();
//String URL = JsonPack.getJSONString("http://ussltc7146v.dev.sltc.com:14000/idaas/im/scim/v1/Users");

String jsonString ="{ \"schemas\": [\r\n\"urn:ietf:params:scim:schemas:extension:oracle:2.0:OIG:User\",\r\n\"urn:ietf:params:scim:schemas:core:2.0:User\",\r\n\"urn:ietf:params:scim:schemas:extension:oracle:2.0:IDM:User\",\r\n\"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User\"\r\n],\r\n\"userName\": \"ECLIPSE\",\r\n\"password\":\"Passw0rd\",\r\n\"name\": {\r\n\"givenName\": \"first\",\r\n\"familyName\": \"last\"\r\n},\r\n\"emails\": [\r\n{ \"value\": \"antiktest_eclipse@edd.ca.gov\",\r\n\"type\": \"work\"\r\n}\r\n],\r\n\"userType\": \"Full-Time\",\r\n\"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User\": {\r\n\"organization\": \"Xellerate Users\"\r\n}\r\n}";

JSONObject json= new JSONObject(jsonString);
HttpClient httpClient = HttpClientBuilder.create().build();

try {
HttpHost proxy = new HttpHost("127.0.0.1", 9998, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
finally{

}

HttpPost request = new HttpPost("URL for OIM REST API");
StringEntity params =new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
System.out.println("response is "+ response);
// handle response here...
}catch (Exception ex) {

ex.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown(); //Deprecated
}


}

我收到以下错误消息:

  response is HttpResponseProxy{**HTTP/1.1 415 Unsupported Media Type** [Date: Thu, 01 Oct 2015 05:17:44 G                    MT,
Transfer-Encoding: chunked, Content-Type: text/plain,
X-ORACLE-DMS-ECID: cc6ca29dd5361a5c:-25d24
3fd:150213338cb:-8000-00000000000003aa, X-Powered-By: Servlet/2.5
JSP/2.1] ResponseEntityProxy{[Content-Type: text/plain,Chunked: true]}}
<小时/>

enter image description here

最佳答案

根据您收到的错误HTTP 415不支持的媒体类型,看来您在发布到 REST 端点时使用了错误的媒体类型。尝试使用:

request.addHeader("content-type", "application/scim+json");

而不是您现在使用的 application/json。

还要确保您在 OIM 中发布到/Users 的正确 REST 端点。

我本以为您用于请求 JSON 的组织是只读属性,您可能无法使用它来写入新用户。您可能必须使用 urn:ietf:params:scim:schemas:extension:oracle:2.0:OIG:User 类型,并将值设置为 act_key 和引用。

关于java - 如何在 java 中为 Oracle Identity Management JSON 创建 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com