Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 186074
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T16:01:52+00:00 2022-06-10T16:01:52+00:00

java – Error: javax.ws.rs.NotFoundException: HTTP 404 Not Found

  • 0

[ad_1]

I am trying to test my code that gets all the user details from Keycloak using the Keycloak library. But I keep seeing this error. can anyone help me with this?

Test code

trait Setup {
    val keycloak: Keycloak = mock[Keycloak]
    val keycloakBuilder: KeycloakBuilder = mock[KeycloakBuilder]
    val service = new NewUserService(conf)
    val restEasy: ResteasyClientBuilder = mock[ResteasyClientBuilder]
    val restEasyClient: ResteasyClient = mock[ResteasyClient]
    val realmResource: RealmResource = mock[RealmResource]
    val usersResource: UsersResource = mock[UsersResource]
  }
  "NewUserService#getAllUsers" should {

    "return all users" in new Setup {
      when(restEasy.build()) thenReturn restEasyClient
      when(keycloakBuilder.build()) thenReturn keycloak
      when(restEasy.build()) thenReturn restEasyClient
      when(keycloak.realm(any[String])) thenReturn realmResource
      when(realmResource.users()) thenReturn usersResource
      when(usersResource.list()) thenReturn List(any[UserRepresentation]).asJava
      whenReady(service.getAllUsers) { result =>
        assert(result.isRight)
      }
    }
  }

NewUserService.scala

class NewUserService(conf: Config)(implicit val ec: ExecutionContext, logger: LoggingAdapter) {

  def getAllUsers: Future[Either[NewUserServiceError, util.List[idm.UserRepresentation]]] = {
    val keycloakConf = conf.getConfig("keycloak")
    val serverUrl = keycloakConf.getString("realmServerURL")
    val realm = keycloakConf.getString("realmName")
    val userName = keycloakConf.getString("username")
    val password = keycloakConf.getString("password")
    val clientId = keycloakConf.getString("clientId")
    val clientSecret = keycloakConf.getString("clientSecret")
    val keycloakBuild = KeycloakBuilder
      .builder()
      .serverUrl(serverUrl)
      .realm(realm)
      .username(userName)
      .password(password)
      .clientId(clientId)
      .clientSecret(clientSecret)
      .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(20).build())
      .build()
    val usersList = Future(Try(keycloakBuild.realm("knoldus").users().list()))
    usersList.map {
      case Success(users) =>
        users.asRight
      case Failure(exception) =>
        logger.error(s"Unable to get user details $exception")
        NewUserServiceError.UserNotFoundError.asLeft
    }
  }
}

object NewUserService {

  sealed trait NewUserServiceError

  object NewUserServiceError {
    case object UserNotFoundError extends NewUserServiceError

    case object InternalServerError extends NewUserServiceError
  }

}

I get the connection refused error when i donot start my keycloak server at 8080 port. And when i start it on 8080 port i see user not found error. Please tell me what am i doing wrong.

Error

Unable to get user details javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:8080 [/127.0.0.1] failed: Connection refused

Unable to get user details javax.ws.rs.ProcessingException: javax.ws.rs.NotFoundException: HTTP 404 Not Found

[ad_2]

  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 396 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 370 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 361 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.