我有以下json来解析 int JSONObject并通过 http 客户端发送它以使用其REST API在OIM 11g PS3中创建用户。
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]}}