私は非常に古い J2EE/Struts サイトに取り組んでおり、最近 PayPal が SSL 3 プロトコルのサポートを中止したため、支払いゲートウェイが注文の詳細を含む POST を受け入れ、クレジット カードを処理する、新しいホストされたチェックアウト プロセスを実装しようとしています。検証し、別の POST を介して応答コード (およびその他の 100 万の値) を返します。
struts で既存のアクションを利用しようとしていますが、struts-config.xml (/store/order/confirmation.do)で指定されたパスがレンダリングされていないため、ハングアップしています。代わりに、リモート サーバーからの POST 要求が処理され、ActionMapping.findForward() が呼び出された後、アプリケーションはリモート サーバーからの POST で要求されたものと同じパスをレンダリングするだけです(/store/checkout/submitOrder.do)。 .
struts-config.xml の転送に redirect="true" を追加しようとすると、適切なパスにリダイレクトされますが、ログに記録されないためにデバッグできない pagecontext 例外が発生します。
これが機能していた方法は、submitOrder フォームが空で、送信入力のみでした。次に、セッションベースのショッピング カートと関連する顧客請求フォームからのチェックアウトの詳細が、応答を生成するために特別なベリサイン ライブラリに渡されます。新しいプロバイダーのフォーム POST を使用したいのですが、このリダイレクトの大失敗で立ち往生しています。
struts-config.xml の行は次のようになります。
<action path="/store/checkout/submitOrder" type="com.company.action.CheckoutAction" parameter="submitOrder" scope="request">
<set-property property="secure" value="true"/>
<forward name="success" path="/store/order/confirmation.do"/>
</action>
そして、アクションは次のようになります。
public ActionForward submitOrder(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String method = request.getMethod();
if (method != null && method.equals("POST")) {
ShoppingCart sc = (ShoppingCart) request.getSession(false).getAttribute("shoppingCart");
if (sc == null) { throw new SessionExpiredException("Submit Order - Shopping Cart is not in session"); }
ResourceBundle appConfig = ResourceBundle.getBundle("resources.application");
PFProClient client = new PFProClient();
/* THIS saveOrder() METHOD WAS RE-WRITTEN TO TAKE the httpservletrequest (form POST) instead of an instance of VerisignResponse, defined in another library. */
client.saveOrder(sc, request);
User user = (User)request.getSession(false).getAttribute(Globals.USER);
if (user != null) { UserModel.saveUser(user, sc.getCustomer(), sc.getOrder()); }
//Remove items from session
request.getSession().setAttribute("customerBillingForm", null);
request.getSession().setAttribute("customerShippingForm", null);
request.getSession().setAttribute("customerCreditForm", null);
request.getSession().setAttribute("cartForm", null);
request.getSession().setAttribute("shoppingCart", null);
//remove the shopping cart from the cookie & DB
ShoppingCartUtils.deleteSavedCartFromCookie(response, request);
//remove the CHECKING_OUT flag
request.getSession().setAttribute(Globals.CHECKING_OUT, null);
//remove the PAYING_WITH_PAYPAL flag
request.getSession().setAttribute(Globals.PAYING_WITH_PAYPAL, null);
// Set cart in request for order confirmation page
request.setAttribute("shoppingCart", sc);
return mapping.findForward("success");
} else {
// HTTP method was not POST
}
return mapping.findForward("success");
}
編集
submitOrder アクションが POST リクエストとして処理されていることを確認しました。以前の POST は単なる空のフォームだったので、余分な POST パラメータが何かを汚し、適切なルーティングを妨げているのではないかと思っています。
tiles-defs.xml では、confirmation.do ビューのリソースは次のとおりです。
<definition name="confirm.order" path="/templates/layouts/order-confirmation.jsp">
...
<put name="content" value="/store/checkout/confirmOrder.jsp"/>
</definition>
アプリケーションはconfirmOrder.jspビューを提供していますが、/store/order/confirmation.do にルーティングしていません。そのため、ページをリロードしようとすると、ユーザーはフォームを再送信するように求められます。これは明らかに望ましくありません。
また、次のように定義されている struts-config.xml の submitOrder アクション定義から name="emptyForm" への参照を削除しました (リモート サーバーから送信されるフォーム POST には emptyForm name 属性がないため)。
<form-bean name="emptyForm" type="org.apache.struts.action.DynaActionForm"/>
それがどのような効果をもたらすかは私にもわかりません。