質問

AppFuseを使って基本的なアプリケーションシェルを作成し、 appfuseチュートリアル JAX-RSで簡単なRestfulサービスを作成する。それはちょうどうまく機能します。 http://localhost:8080/services/api/personsへの呼び出しは、権利データを持つJSONフォーマット文字列としてPersonオブジェクトのコレクションを返します。

私は、AppFuseによって公開されているRESTfulサービス内からServletRequestおよびServletResponseオブジェクトにアクセスしたい(これらのオブジェクトを必要とする別のライブラリーを使用するため)。

i は、@Context注釈を追加することによって実行可能であるべきです。この stackoverflow post とこのフォーラムPOST

しかし、@Contextタグを追加した場合(下記参照)は、サーバーが再起動されたとき(下に添付されています)のときには、細かくコンパイルされますが、例外がスローされます。

@WebServiceの宣言:

@WebService
@Path("/persons")
public interface PersonManager extends GenericManager<Person, Long> {
    @Path("/")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    List<Person> read();
    ...
}
.

そしてここに、@Context注釈を呼び出すと思います:

@Service("personManager") 
public class PersonManagerImpl extends GenericManagerImpl<Person, Long> implements PersonManager { 
    PersonDao personDao; 
    @Context ServletRequest request; // Exception thrown on launch if this is present 
    @Context ServletContext context;  // Exception thrown on launch of this is present 
    ... 
    } 
.

私はそれを働かせるために含めるために何かを含めること、またはServletRequestを得ることができないことを理解すること、またはそれを理解することができないことを実感しています....すべての手がかりが大歓迎です。

これをIntellijのTomcatで実行しています。

===例外スタックトレース(切り捨て)===

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception; nested exception is java.lang.RuntimeException: java.lang.NullPointerException 
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) 
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) 
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358) 
        ... 37 more 
.

役に立ちましたか?

解決

HttpServletRequestHttpServletContextを直接注射する:

@Context private HttpServletRequest servletRequest;
@Context private HttpServletContext servletContext;
.

他のヒント

メソッドの署名に追加しました。クラスがインスタンス化されているときに要求オブジェクトと応答オブジェクトがまだ存在しないからであるため、想像してみてください。

@Path("/")
@GET
@Produces(MediaType.APPLICATION_JSON)
List<Person> read( @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) { }
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top