开发者

POST to Java from Wordpress

My page used to be all java with Wicket as front-end. Now, I have a wordpress start-page with a loginform. When I enter the email and password in that loginform, I want to redirect it to a login-service which then redirects the user to the wicket welcome-page if login is successful.

The way I have tried to do this is by sending a POST message from the wordpress page, and handle it with a Service in my java application. This doesn't work well for me.

Is this even a good way to do it? If not, what other ways are possible?

This is the implementation I have attempted today:

(simulation of the post-action from the wordpress page on top)

<FORM action="http://localhost:8080/Login" method="post">
    <P>
    <LABEL for="email">Email: </LABEL>
              <INPUT type="text" id="email"><BR>
    <LABEL for="password">Password: </LABEL>
              <INPUT type="text" id="password"><BR>

    <INPUT type="submit" value="Send"> <INPUT type="reset">
    </P>
 </FORM>

Service:

@Path("/Login")
@Consumes("application/xml")
public class LoginServiceImpl implements LoginService{

 private static final Response USER_AUTHORIZATION_FAILED = Response.status(
   Status.NOT_ACCEPTABLE).build();

 private static final Response USER_SUCCESSFULLY_AUTHORIZED = Response.status(
   Status.ACCEPTED).build();

 @Autowired
 private UserController userController;

 @Override
 @POST
 public Response login(@QueryParam("email") String email, 
   @QueryParam("password") String password) {

  boolean authenticated = userController.authenticate(email,
    password);
  User u = userController.findByEmail(email);

  if (u != null && u.getUserType() == UserType.COMPANY_RECRUITER) {
   handleCompanyRecruiter(u);
   return USER_SUCCESSFULLY_AUTHORIZED;
  } 
  else if ((authenticated && u != null) && (u.getCompany().getIsActive())) {
   signInUser(u);
   setCorrectResponsePage(u);
   return USER_SUCCESSFULLY_AUTHORIZED;
  }
  else{
   return USER_AUTHORIZATION_FAILED;
  }
 }

applicationContext:

 <!-- LOGIN SERVICE --> 
      <jaxrs:server id="loginService" address="/login">
      <jaxrs:serviceBeans>
       <ref bean="loginServiceBean" />
      </jaxrs:serviceBeans>
      <jaxrs:providers>
       <ref bean="jaxbProvider" />
       <ref bean="notFoundExceptionMapper" />
      </jaxrs:providers>
     </jaxrs:server>

<bean class="services.CandidateServiceImpl"
        id="candidateServiceBean" />

Running this, when I enter the form and press send I receive this error:

HTTP ERROR: 404

NOT_FOUND
RequestURI=/Login

Me annotating the LoginServiceImpl with @Path("/Login") is maybe not the right way? How do I redirect the POST to the correct location?

And this is the old Wicket-page for the login:

<wicket:panel>
<wicket:extend>       
    <div id="top_login">   
        <form wicket:id="loginForm">  
              开发者_StackOverflow社区  <div>
                    <label for="loginEmail" wicket:id="loginEmailLabel">Email</label>
                    <input class="text" id="loginEmail" wicket:id="loginEmail" tabindex="101" />
                </div>
                <div>
                    <label for="loginPassword" wicket:id="loginPasswordLabel">Password</label>
                    <input class="text" type="password" id="loginPassword" wicket:id="loginPassword" tabindex="102" />
                </div>
                <div class="loginBtnArea">
                    <input wicket:id="loginButton" class="submit" type="submit" tabindex="103" value="Login" />

                </div>   
            </form> 
            <a wicket:id="forgotPasswordLink"><span class="forgotPassword" wicket:id="forgotPasswordLabel">Forgot your password?</span></a>                          
    </div>
</wicket:extend>
</wicket:panel>


Seems that the problem is in your config and not in the thought procedure itself.

Declare a bean with id loginServiceBean in your applicationContext.

EDIT:

I'm not wholly familiar with the techniques you are using, but could it be that the @Consumes("application/xml")-annotation blocks the request? You could try putting @Consumes("application/x-www-form-urlencoded")-annotation to your method, that is supposed to handle the login data.

Soure: http://docs.sun.com/app/docs/doc/820-4867/ggqqr?a=view

EDIT^2:

Your form's action is http://localhost:8080/Login. If I understand correctly it ought to be http://localhost:8080/Login/login

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜