Class: MediaType not found in namespace

Which IIQ version are you inquiring about?

8.4

Please share any images or screenshots, if relevant.

[Please insert images here, otherwise delete this section]

Please share any other relevant files that may be required (for example, logs).

[Please insert files here, otherwise delete this section]

Share all details about your problem, including any error messages you may have received.

Exception during aggregation. Reason: java.lang.RuntimeException: sailpoint.connector.ConnectorException: BeanShell script error: bsh.EvalError: Sourced file: inline evaluation of: ``import sailpoint.object.QueryOptions; import sailpoint.object.Filter; import . . . ‘’ : Typed variable declaration : Class: MediaType not found in namespace : at Line: 82 : in file: inline evaluation of: ``import org.apache.log4j.Logger; import sailpoint.object.Application; import . . . ‘’ : MediaType Called from method: reassignTASK : at Line: 13 : in file: inline evaluation of: ``import sailpoint.object.QueryOptions; import sailpoint.object.Filter; import . . . ‘’ : reassignTASK ( application , object .getAttribute ( "sys_id" ) , "Identity Not Correlated" , "Global Office 365" ) BSF info: Orbia-ServiceNow-ResourceObjCustomization at line: 0 column: columnNo

Hi,

could you please confirm whether the correct package for the MediaType class has been imported? It might be missing, which could be causing the error.

Thank you.

Class MediaType not found in namespace suggests that you are missing import statement for MediaType class. Please add the import statement and retry.

Hi Vijay,

This is what i am struggling which class file is missing. I check in the entire system and unable to find class as mediatype. Please help as how to find the class file

thanks

Amit

Hi Sanjeev,

import com.squareup.okhttp.MediaType; statmenet is there it’s still failing

thanks

Amit

Then it seems to be conflicting with another class with same name for example “javax.ws.rs.core.MediaType;”. You can try to call your class using the full package name so that it does not confuse it with another class.

It looks like the issue isn’t just about the import but about which MediaType class is actually available in IdentityIQ.

There are two common MediaType classes you may be running into:

  • javax.ws.rs.core.MediaType → included with JAX-RS and usually available in IIQ.

  • com.squareup.okhttp.MediaType / okhttp3.MediaType → part of the OkHttp client library, which is not bundled with IIQ unless you explicitly add the JARs under WEB-INF/lib.

If you’ve already tried import com.squareup.okhttp.MediaType; but the JAR isn’t on your IIQ classpath, it will fail. That’s why you can’t find the class file in your system.

If you are making REST calls from workflows or rules, use javax.ws.rs.core.MediaType instead, since it’s already present. Example:

import javax.ws.rs.core.MediaType;

String contentType = MediaType.APPLICATION_JSON;

If you specifically need OkHttp, then you’ll have to add the appropriate OkHttp JAR (which provides okhttp3.MediaType) into IIQ’s WEB-INF/lib directory and reference it directly.

Hi @ayadav_12

Hi, I noticed that IdentityIQ provides two out-of-the-box import options for MediaType without requiring any external JARs:

  1. import okhttp3.MediaType;

  2. import javax.ws.rs.core.MediaType;

You can choose either of these based on your implementation needs.

Thank you.

Looks like the error is coming from BSH script. Could you provide the Beanshell script that is part of aggregation? Do you know which rule is throwing customization rule?, correlation rule? do you have any other rules?

Hi Aleksander,

Yes, it’s a part of customization rule. The code is attached below please validate:

import org.apache.log4j.Logger;
import sailpoint.object.Application;
import sailpoint.server.Auditor;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONObject;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import sailpoint.tools.GeneralException;
import java.util.Base64;

private Logger myLogger = Logger.getLogger(“Mexichem-SNOW”);
String mediaType = “application/json”;

/**
* Logic to close a specific SCTASK in ServiceNow.
*
* @param application, taskSysId, userEmail, roleAssigned
* @throws GeneralException
*/
public int closeTASK(Application appSnow, String taskSysId, String userEmail, String role) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);

myLogger.debug("Starting Orbia-ServiceNow-Library-Rule closeTASK...");

/* myLogger.debug(“BASE_URL: " + BASE_URL);
myLogger.debug(“USER_NAME: " + USER_NAME);
myLogger.debug(“PASSWORD: " + PASSWORD);
myLogger.debug(“AUTHORIZATION_HEADER_VALUE: " + AUTHORIZATION_HEADER_VALUE);*/
try {
OkHttpClient client = new OkHttpClient();
String requestBody=”{“close_notes”: “Close complete. Task processed for “+userEmail+”. Role: “+role+””,“state”: “3”,“active”: “false”}”;
myLogger.debug(“requestBody: " + requestBody);
RequestBody body = RequestBody.create(JSON, requestBody);
Request request = new Request.Builder()
.url(BASE_URL+”/now/table/sc_task/”+taskSysId)
.addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE)
.put(body)
.build();
myLogger.debug(“URL: " + BASE_URL+”/now/table/sc_task/”+taskSysId);
Response response = client.newCall(request).execute();
JSONObject jobj = new JSONObject(response.body().string());
myLogger.debug(“Response: " + jobj);
Auditor.logAs(USER_NAME, “roadWebservicesRequest”, “teste”, request.urlString(), “{“statusCode”:”+response.code().toString()+”,“reponseBody”:“+jobj+”}", requestBody, “ServiceNow-AdditionalPermissions”);
return response.code();
}
catch(Exception e) {
myLogger.error("Exception occurred -closeTASK-: " + e.toString());
}
myLogger.debug(“Ending Orbia-ServiceNow-Library-Rule closeTASK…”);
}

/**
* Logic to reassign a specific SCTASK in ServiceNow.
*
* @param application, taskSysId, errorDetail, assignedGroup
* @throws GeneralException
*/
public int reassignTASK(Application appSnow, String taskSysId, String errorDetail, String assignedGroup) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);

errorDetail=errorDetail.replace("\n", "");

myLogger.debug("Starting Orbia-ServiceNow-Library-Rule reassignTASK...");
try {
  OkHttpClient client = new OkHttpClient();
  String requestBody="{\"assigned_to\": \"\",\"work_notes\": \"Error: "+errorDetail+"\",\"assignment_group\":\""+assignedGroup+"\"}";      
  myLogger.debug("requestBody: " + requestBody);
  RequestBody body = RequestBody.create(JSON, requestBody);
  Request request = new Request.Builder()
    .url(BASE_URL+"/now/table/sc_task/"+taskSysId)
    .addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE) 
    .put(body)
    .build();
  myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
  Response response = client.newCall(request).execute();
  JSONObject jobj = new JSONObject(response.body().string());
  myLogger.debug("Response: " + jobj);
  Auditor.logAs(USER_NAME, "roadWebservicesRequest", "teste", request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", requestBody, "ServiceNow-AdditionalPermissions");      
  return response.code();
}
catch(Exception e) {
  myLogger.error("Exception occurred -reassignTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule reassignTASK...");

}

/**
* Logic to process a specific SCTASK in ServiceNow.
*
* @param application, identityName, taskSysId, workNote, assignedGroup
* @throws GeneralException
*/
public int processTASK(Application appSnow, String identityName, String taskSysId, String workNote, String assignedGroup) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);

myLogger.debug("Starting Orbia-ServiceNow-Library-Rule processTASK...");
try {
  OkHttpClient client = new OkHttpClient();      
  	String requestBody="{\"assigned_to\": \"sailpoint.integration\",\"work_notes\": \""+workNote+"\",\"state\":\"2\"}";
  myLogger.debug("requestBody: " + requestBody);
  RequestBody body = RequestBody.create(JSON, requestBody);
  Request request = new Request.Builder()
    .url(BASE_URL+"/now/table/sc_task/"+taskSysId)
    .addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE) 
    .put(body)
    .build();
  myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
  Response response = client.newCall(request).execute();
  JSONObject jobj = new JSONObject(response.body().string());
  Auditor.logAs(USER_NAME, "roadWebservicesRequest", identityName, request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", request.toString(), "ServiceNow-AdditionalPermissions");
  myLogger.debug("Response: " + jobj);
  return response.code();
}
catch(Exception e) {
  myLogger.error("Exception occurred -processTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule processTASK...");

}

/**
* Logic to create a new Incident ServiceNow.
*
* @param application, identityName, workNote, assignedGroup
* @throws GeneralException
*/
public int newIncident(Application appSnow, String identityName, String description, String title, String assignedGroup, String businessService) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);

myLogger.debug("Starting Orbia-ServiceNow-Library-Rule processTASK...");
try {
  OkHttpClient client = new OkHttpClient();
  String requestBody = "{\"assignment_group\": \""+assignedGroup+"\",\"description\": \""+description+"\",\"short_description\":\""+title+"\",\"category\":\"Access Issue\",\"business_service\":\""+businessService+"\"}";      
        
  //{"assignment_group":"Global Identity Service","description":"descricao","short_description":"titulo","category":"Access Issue","business_service":""}
  myLogger.debug("requestBody: " + requestBody);
  RequestBody body = RequestBody.create(JSON, requestBody);
  Request request = new Request.Builder()
    .url(BASE_URL+"/now/v1/table/incident")
    .addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE) 
    .post(body)
    .build();
  myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
  Response response = client.newCall(request).execute();
  JSONObject jobj = new JSONObject(response.body().string());
  System.out.println("Request: " + request.toString());
  System.out.println("Response: " + jobj);
  System.out.println(requestBody);
  System.out.println(response.code());
  if(null != identityName){
    Auditor.logAs(USER_NAME, "roadWebservicesRequest", identityName, request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", requestBody, "ServiceNow-AdditionalPermissions");      
  }
  return response.code();
}
catch(Exception e) {
  myLogger.error("Exception occurred -processTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule processTASK...");

}

@ayadav_12

I see in your code you are using import com.squareup.okhttp.MediaType. But Are you sure that you have added the jar file for this import in your WEB-INF/lib folder. Otherwise, SailPoint wont be able to find this jar and it will give you that error.