2

私はジャージーが初めてで、検索結果のGETを開発しようとしています。そのためには、検索条件とデータを含むオブジェクトを送信する必要があります。私は何が間違っているのだろうか。Junit テスト ケースで次の例外が発生します。

com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Search/Request/com.mcruiseon.carpool.concrete.SearchConcrete@676e3f returned a response status of 404 Not Found
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
at test.carpool4all.SingleSearchTest.testPost(SingleSearchTest.java:89)

私のサーバー側GET

    @GET
    @Path ("Request/{search}")
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces({ MediaType.APPLICATION_JSON })
    public Response search(@PathParam("search") SearchConcrete searchConcrete) {
        SearchJourneyRequest request = new SearchJourneyRequest(searchConcrete) ;
        SearchJourneyResponse response ;
        clientSession = sessionManager.getClientSession(searchConcrete.getIdentityHash()) ;
        clientSession.getSendQueue().sendRequest(request) ;
        try {
            response = (SearchJourneyResponse)clientSession.waitAndGetResponse(request) ;
        } catch (WaitedLongEnoughException e) {
            return Response.serverError().build() ;
        } catch (UnableToResolveResponseException e) {
            return Response.serverError().build() ;
        }
        return Response.ok(response.getSearchResults()).build();
    }

クライアント側 Junit テスト

SearchConcrete searchProvider = new SearchConcrete(Globals.SearchCriteria.FlexiTime,
    identityHash,
    // more parameters
    );
    service = client.resource(UriBuilder.fromUri("http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Search/Request/"+searchProvider).build());
    Object[] searchResults = service.type(MediaType.APPLICATION_JSON).get(Object[].class);

編集: @eugen のおかげで、これを解決するために、Object[] をプライベート メンバーとして具象クラスを追加しました。GET の代わりに、POST を使用しました。これは固定コードです。今、私の相乗り検索結果が来ています:)。

サービス = client.resource(UriBuilder.fromUri(

"http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Search/Request").build());
            SearchResultsConcrete searchResults = service.type(MediaType.APPLICATION_JSON).post(SearchResultsConcrete.class, searchProvider);
            assertNotNull(searchResults);
            assertNotNull(searchResults.getSearchResults()) ;
            assertTrue(searchResults.getSearchResults().length == 3) ;
            assertTrue(searchResults.getSearchResults()[SearchJourneyResponse.FLEXI_POSITION].length > 0) ;
            assertTrue(searchResults.getSearchResults()[SearchJourneyResponse.FLEXIENDTIME_POSITION].length > 0) ;


@POST
    @Path ("Request")
    @Consumes({ MediaType.APPLICATION_JSON })
    @Produces({ MediaType.APPLICATION_JSON })
    public Response search(JAXBElement<SearchConcrete> element) {
        SearchJourneyRequest request = new SearchJourneyRequest((SearchConcrete)element.getValue()) ;
        SearchJourneyResponse response ;
        clientSession = sessionManager.getClientSession(((SearchConcrete)element.getValue()).getIdentityHash()) ;
        clientSession.getSendQueue().sendRequest(request) ;
        try {
            response = (SearchJourneyResponse)clientSession.waitAndGetResponse(request) ;
        } catch (WaitedLongEnoughException e) {
            return Response.serverError().build() ;
        } catch (UnableToResolveResponseException e) {
            return Response.serverError().build() ;
        }
        return Response.ok(response.getSearchResults()).build();
    }
4

2 に答える 2

2

ここにスラッシュがありません/:

"...Request"+searchProvider

これは

"...Request/" + searchProvider

編集

オブジェクトを URL に追加することはできません。これ

"http://localhost:8081/mCruiseOnCarPool4All/carpool4all/Search/Request/"+searchProvider

toString()メソッドSearchConcreteが呼び出されます。結果は

com.mcruiseon.carpool.concrete.SearchConcrete@676e3f 

サーバーには、これから を再構築する方法がありませんSearchConcrete

于 2012-10-26T08:10:16.900 に答える