Examples of BasicResponse


Examples of com.alu.e3.prov.restapi.model.BasicResponse

   * @param params
   * @return
   */
  protected final Response execute(Action action, final Object... params) {

    BasicResponse response = (BasicResponse) action.doAction(params);
    ResponseBuilder builder = Response.ok(response);
    if(response.getError() != null){
      builder.status(new Integer(response.getError().getErrorCode()));
    }

    return builder.build();
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

        if(proxy == null) {
        }       
                       
        dataManager.putSettingString(E3Constant.GLOBAL_PROXY_SETTINGS, BeanConverterUtil.toDataModel(proxy).serialize());

        BasicResponse response = new BasicResponse(ProxyResponse.SUCCESS);

        return response;
      }
    };
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

      @Override
      protected Object doAction(Object... params) {       

        dataManager.clearSettingString(E3Constant.GLOBAL_PROXY_SETTINGS);

        BasicResponse response = new BasicResponse(ProxyResponse.SUCCESS);

        return response;
      }
    };
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

  public void testCreateAuth() throws Exception {

    Auth data = newAuthProvision("usedId");
   
   
    BasicResponse response = given()
    .contentType("application/xml")
    .body(data, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .post("")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

  public void testCreateAndDeleteAuth() throws Exception {
   
    Auth data = newAuthProvision("reusableId");   
   
    // Create step
    BasicResponse response = given()
    .contentType("application/xml")
    .body(data, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .body("apiID", notNullValue())
    .log().ifError()
    .when()
    .post("")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);
   
   
    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
   
    // Delete step
    response = given()
    .contentType("application/xml")
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .delete("/" + data.getId())
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
         
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

  public void testSecondCreateAndDeleteAuth() throws Exception {
   
    Auth data = newAuthProvision("reusableId");   
   
    // Create step
    BasicResponse response = given()
    .contentType("application/xml")
    .body(data, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .body("apiID", notNullValue())
    .log().ifError()
    .when()
    .post("")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);
   
   
    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
   
    // Delete step
    response = given()
    .contentType("application/xml")
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .delete("/" + data.getId())
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
         
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

  public void testCreateAndUpdateAuth() throws Exception {
    String id = ""+(System.currentTimeMillis());

    Auth data = newAuthProvision(id);   

    BasicResponse response = given()
    .contentType("application/xml")
    .body(data, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .post("")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
       
    data.setStatus(Status.INACTIVE);
   
   
    response = given()
    .contentType("application/xml")
    .body(data, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .put("/" + id)
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());

   
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

    SSLCert cert = new SSLCert();
   
    cert.setId(id);
    cert.setContent("iurezahfskdqhflk");

    BasicResponse response = given()
    .contentType("application/xml")
    .body(cert, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .post("/certs")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
    if (id != null)
    {
      assertEquals(id, response.getId());
    }
    else
    {
      assertNotNull(response.getId());
      id = response.getId();
    }

    // UPDATE
    cert.setContent(null);
    cert.setDisplayName("titi");
   
    response = given()
    .contentType("application/xml")
    .body(cert, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .put("/certs/" + id)
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());   

    // DELETE
    response = given()
    .contentType("application/xml")
    .body(cert, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .delete("/certs/" + id)
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus())
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

   
    crl.setId(id);
    String content = "abc";
    crl.setContent(content);

    BasicResponse response = given()
    .contentType("application/xml")
    .body(crl, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .post("/crls")
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());
   
    if (id != null)
    {
      assertEquals(id, response.getId());
    }
    else
    {
      assertNotNull(response.getId());
      id = response.getId();
    }

    // UPDATE
    crl.setContent(null);
    crl.setDisplayName("toto");
 
    response = given()
    .contentType("application/xml")
    .body(crl, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .put("/crls/" + id)
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus());   

    // DELETE
    response = given()
    .contentType("application/xml")
    .body(crl, ObjectMapper.JAXB)
    .expect()
    .statusCode(200)
    .rootPath("response")
    .body("status", equalTo("SUCCESS"))
    .log().ifError()
    .when()
    .delete("/crls/" + id)
    .andReturn()
    .as(BasicResponse.class, ObjectMapper.JAXB);

    assertNotNull(response);
    assertEquals("SUCCESS", response.getStatus())
  }
View Full Code Here

Examples of com.alu.e3.prov.restapi.model.BasicResponse

    String message = "";
    int applicationErrorCode = 0;
    int status;
    Throwable cause = ex;

    BasicResponse resp = new BasicResponse(BasicResponse.FAILURE);
    resp.setError(new Error());

    if (ex instanceof AccessDeniedException) {
      // 403 FORBIDDEN
      status = 403;

      applicationErrorCode = ApplicationCodeConstants.AUTHENTICATION_ENABLED_AND_FAILED;
      resp.getError().setErrorText("Access Denied");
     

    } else if (ex instanceof AuthenticationException) {
      //  UNAUTHORIZED
      status = 401;

      applicationErrorCode = ApplicationCodeConstants.UNAUTHORIZED;
      resp.getError().setErrorText("Unauthorized access");
     
    } else if (ex instanceof WebApplicationException) { // CXF raises this
                              // kind of exception
      // 500 INTERNAL_SERVER_ERROR
      status = 500;
      applicationErrorCode = ApplicationCodeConstants.INTERNAL_APPLICATION_ERROR;

      if (ex.getCause() == null) {
        message = ex.toString();
      } else {
        cause = ex.getCause();
        if (cause instanceof SAXParseException) {
          applicationErrorCode = ApplicationCodeConstants.INVALID_XML;
          resp.getError().setErrorText("XML Validation Error: " + ex.getCause().getMessage());

        } else if (cause instanceof ProvisionException) {
          ProvisionException provEx = (ProvisionException) ex.getCause();
          applicationErrorCode = provEx.getErrorCode();
          resp.getError().setErrorText(ex.getCause().getMessage());
         
        } else if (cause instanceof InvalidIDException) {
          // This block is called in API WebService
          // Should do the same as other InvalidIDException catch
          // 404 NOT_FOUND
          status = 404;
          applicationErrorCode = ApplicationCodeConstants.ID_NOT_FOUND;
          resp.getError().setErrorText(ex.getCause().getMessage());
        } else {
          message = cause.getMessage();
          if (message == null) {
            message = ex.getCause().toString();
          }
          applicationErrorCode = ApplicationCodeConstants.INTERNAL_APPLICATION_ERROR;
          resp.getError().setErrorText(message);
        }
      }

    } else if (ex instanceof InvalidIDException) {
      // Should do the same as other InvalidIDException catch
      // 404 NOT_FOUND
      status = 404;
      applicationErrorCode = ApplicationCodeConstants.ID_NOT_FOUND;
      resp.getError().setErrorText(ex.getMessage());

    } else if (ex instanceof NotImplementedException) {
      // 501 NOT_IMPLEMENTED
      status = 501;
      applicationErrorCode = ApplicationCodeConstants.NOT_IMPLEMENTED;
      resp.getError().setErrorText(ex.getMessage());

    else if (ex instanceof ProvisionException) {
      // 500 INTERNAL_SERVER_ERROR
      status = 500;
      ProvisionException provEx = (ProvisionException) ex.getCause();
      applicationErrorCode = provEx.getErrorCode();
      resp.getError().setErrorText(ex.getCause().getMessage());
     
    } else {
      // 500 INTERNAL_SERVER_ERROR
      status = 500;
      message = ex.toString();

      applicationErrorCode = ApplicationCodeConstants.INTERNAL_APPLICATION_ERROR;
      resp.getError().setErrorText("Provisioning Server Error: "+message);

    }
    StackTraceElement[] stack = cause.getStackTrace();
    ArrayList<StackTraceElement> e3Stack = new ArrayList<StackTraceElement>();
    for (StackTraceElement elem : stack) {
      if (elem.getClassName().indexOf("com.alu.e3") != -1) {
        e3Stack.add(elem);
      }
    }

    cause.setStackTrace(e3Stack.toArray(new StackTraceElement[e3Stack.size()]));
    if(logger.isErrorEnabled()) {
      logger.error("E3 Runtime exception (HTTP status:" + status + ")", cause);
    }

    resp.getError().setErrorCode(String.valueOf(applicationErrorCode));
    ResponseBuilder builder = Response.status(status).type(MediaType.APPLICATION_XML).header("X-Application-Error-Code", applicationErrorCode).entity(resp);
    if(status == 401){
      builder.header("WWW-Authenticate", "Basic");
    }
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.