如何公开一个方法来休息服务?

时间:2017-06-01 07:40:25

标签: java rest http-post ejb

我是休息的新手我在这里需要一些帮助。我需要帮助将EJB中的方法暴露给REST。下面的方法是在EJB内部,我只需要使用POST来“rest-ify”这个方法。

public Boolean lockUnlockForecastForCustomer(Long businessEntityPK, Long customerPK, Date currentDate,
                                             Long lockAction, String userid) {
    log.info("Lock/Unlock Forecast for Customer: BE ID" + customerPK + "- Current Date" + currentDate);

    // log.info("Checking Lock Action - Action is: " + lockAction);
    if (lockAction == 1) {
        log.info("Unlocking...");
    } else if (lockAction == 3) {
        log.info("Locking...");
    }

    PreparedStatement stmt = null;
    Connection con = null;
    Integer ret = 0;
    boolean success = false;
    try {
        con = dataSource.getConnection();
        stmt = con
                .prepareStatement("update transactional.CUST_SUBMISSION set LASTTOUCHEDUSER = ?, LASTTOUCHED = CURRENT_TIMESTAMP, SUBMISSIONSTATUS_PK = ?,FORECASTSUBMISSIONSTATUS_PK = ?,INVENTORYSUBMISSIONSTATUS_PK = ?,SALESUBMISSIONSTATUS_PK = ? where CUSTOMER_PK = ? and PLANNINGCALENDAR_PK in (select PLANNINGCALENDAR_PK from master.PLANNINGCAL where BUSINESSENTITY_PK = ? and STARTDATE <= CURRENT_DATE and ENDDATE >= CURRENT_DATE)");

        stmt.setString(1, userid);
        stmt.setLong(2, lockAction);
        stmt.setLong(3, lockAction);
        stmt.setLong(4, lockAction);
        stmt.setLong(5, lockAction);
        stmt.setLong(6, customerPK);
        stmt.setLong(7, businessEntityPK);


        ret = stmt.executeUpdate();
        success = true;

    } catch (Exception e) {
        e.printStackTrace();
        success = false;
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return success;
}

到目前为止,我已经创建了一个新的Rest类和一个不完整的方法,所以基本上这就是我被困住的地方。

@POST
@Path("/lockUnlockCustomer")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response lockUnlockForecastForCustomer(Long businessEntityPK, Long customerPK, Date currentDate,Long lockAction, String userid)
{
    siteLockEJB = new SiteLockEJB();

    return Response.ok().build();
}

0 个答案:

没有答案