Ajax对spring servlet的调用无法启动IBM连接云的oauth2舞蹈

时间:2015-07-17 14:07:16

标签: ibm-sbt

我正在尝试从我的网页到我的spring servlet进行ajax调用,然后必须使用SBT oauth2端点从连接云中检索数据。 ajax调用对其他servlet工作正常,但没有做oauth2跳舞。

这是我在jquery中的ajax函数。

      $.ajax({
        url: 'getmycontacts',
        type: 'GET',
        cache: false,
        success: function(res) {

            alert("in success");
            console.log(res);
            document.getElementById('returnmsg').innerHTML = res;
            alert(res);
        },            
        error : function(xhr,ajaxOptions,thrownError){
        console.log("in error");
             console.log(xhr.responseText);
             console.log("status code.."+(xhr.status));
        }
    });

Java servlet

    @RequestMapping(value ="/getmycontacts", method = RequestMethod.GET)
 public @ResponseBody String getmycontacts(HttpServletRequest request,
            HttpServletResponse response){


      String message ;

        try {  
            ProfileService service = new ProfileService("smartcloudOA2"); //If no endpoint is specified, it uses default end point i.e connections
            ProfileList profiles = service.getMyContacts();
            String id = service.getMyProfile().getDisplayName(); 
            if(profiles!=null && !profiles.isEmpty())
            {
                 message = id;

            }
            else { message ="no result"; }

    } catch (Throwable e) {
         message = e.getMessage();
    }   



    return message ;

我收到以下错误

> [err] java.lang.IllegalStateException [err]   at
> com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirectWithStatusCode(WebAppDispatcherContext.java:573)
> [err]     at [internal classes] [err]     at
> com.ibm.commons.runtime.impl.servlet.ContextServlet.sendRedirect(ContextServlet.java:76)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler.performOAuth2Dance(OAuth2Handler.java:791)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler._acquireToken(OAuth2Handler.java:567)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler.acquireToken(OAuth2Handler.java:521)
> [err]     at
> com.ibm.sbt.services.endpoints.OAuth2Endpoint.authenticate(OAuth2Endpoint.java:95)
> [err]     at
> com.ibm.sbt.services.client.ClientService.forceAuthentication(ClientService.java:296)
> [err]     at
> com.ibm.sbt.services.client.ClientService.processResponse(ClientService.java:1154)
> [err]     at
> com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1072)
> [err]     at
> com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:1037)
> [err]     at
> com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:997)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:873)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:869)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:859)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:854)
> [err]     at
> com.ibm.sbt.services.client.smartcloud.profiles.ProfileService.getMyProfile(ProfileService.java:109)
> [err]     at
> com.bluefizz.controller.Getcontacts.getmycontacts(Getcontacts.java:35)
> [err]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> [err]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
> [err]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
> [err]     at java.lang.reflect.Method.invoke(Method.java:620) [err]   at
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
> [err]     at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
> [err]     at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
> [err]     at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
> [err]     at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
> [err]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
> [err]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
> [err]     at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1285)
> [err]     at [internal classes] [err]     at
> com.ibm.sbt.util.SBTFilter.doFilter(SBTFilter.java:53) [err]  at
> com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:206)
> [err]     at [internal classes] [err]     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
> [err]     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
> [err]     at java.lang.Thread.run(Thread.java:798) [err]
> java.lang.IllegalStateException [err]     at
> com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirectWithStatusCode(WebAppDispatcherContext.java:573)
> [err]     at [internal classes] [err]     at
> com.ibm.commons.runtime.impl.servlet.ContextServlet.sendRedirect(ContextServlet.java:76)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler.performOAuth2Dance(OAuth2Handler.java:791)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler._acquireToken(OAuth2Handler.java:567)
> [err]     at
> com.ibm.sbt.security.authentication.oauth.consumer.OAuth2Handler.acquireToken(OAuth2Handler.java:521)
> [err]     at
> com.ibm.sbt.services.endpoints.OAuth2Endpoint.authenticate(OAuth2Endpoint.java:95)
> [err]     at
> com.ibm.sbt.services.client.ClientService.forceAuthentication(ClientService.java:296)
> [err]     at
> com.ibm.sbt.services.client.ClientService.processResponse(ClientService.java:1154)
> [err]     at
> com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1072)
> [err]     at
> com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:1037)
> [err]     at
> com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:997)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:873)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:869)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:859)
> [err]     at
> com.ibm.sbt.services.client.ClientService.get(ClientService.java:854)
> [err]     at
> com.ibm.sbt.services.client.smartcloud.profiles.ProfileService.getMyProfile(ProfileService.java:109)
> [err]     at
> com.bluefizz.controller.Getcontacts.getmycontacts(Getcontacts.java:35)
> [err]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> [err]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
> [err]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
> [err]     at java.lang.reflect.Method.invoke(Method.java:620) [err]   at
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
> [err]     at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
> [err]     at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
> [err]     at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
> [err]     at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
> [err]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
> [err]     at
> org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
> [err]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
> [err]     at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1285)
> [err]     at [internal classes] [err]     at
> com.ibm.sbt.util.SBTFilter.doFilter(SBTFilter.java:53) [err]  at
> com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:206)
> [err]     at [internal classes] [err]     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
> [err]     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
> [err]     at java.lang.Thread.run(Thread.java:798)

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>Bluefizz</display-name>
    <filter>
        <display-name>SBTFilter</display-name>
        <filter-name>SBTFilter</filter-name>
        <filter-class>com.ibm.sbt.util.SBTFilter</filter-class>
        <async-supported>false</async-supported>
    </filter>
    <filter-mapping>
        <filter-name>SBTFilter</filter-name>
        <url-pattern>
        /SBTFilter</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>SBTFilter</filter-name>
        <url-pattern>
        /*</url-pattern>
    </filter-mapping>
    <servlet>
        <description>
        </description>
        <display-name>ServiceServlet</display-name>
        <servlet-name>ServiceServlet</servlet-name>
        <servlet-class>com.ibm.sbt.service.core.servlet.ServiceServlet</servlet-class>
        <enabled>true</enabled>
        <async-supported>false</async-supported>
    </servlet>

    <servlet>
        <servlet-name>Dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dispatcher</servlet-name>
        <url-pattern>/getmycontacts</url-pattern>
    </servlet-mapping>

    <resource-ref>
    <description>Reference to a URL resource which points to the configuration properties for the Social Business Toolkit.</description>
    <res-ref-name>url/ibmsbt-sbtproperties</res-ref-name>
    <res-type>java.net.URL</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>



    <servlet>
        <description>
        </description>
        <display-name>LibraryServlet</display-name>
        <servlet-name>LibraryServlet</servlet-name>
        <servlet-class>com.ibm.sbt.jslibrary.servlet.LibraryServlet</servlet-class>
        <enabled>true</enabled>
        <async-supported>false</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServiceServlet</servlet-name>
        <url-pattern>
        /ServiceServlet</url-pattern>
        <url-pattern>
        /service/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>LibraryServlet</servlet-name>
        <url-pattern>
        /LibraryServlet</url-pattern>
        <url-pattern>
        /library/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>home.html</welcome-file>
    </welcome-file-list>
</web-app>

0 个答案:

没有答案