Fórum

Failed to invoke handler method

srinivasa rao, modificado 9 Anos atrás.

Failed to invoke handler method

Regular Member Postagens: 189 Data de Entrada: 29/01/14 Postagens Recentes
Hi All,

I developed a spring portlet in liferay 6.2,sample portlet is working fine,coming to actuall development its didnt work,showing run time exception:

error is as follows:
Failed to invoke handler method [public void com.myowncompany.test.springmvc.controller.MyFirstSpringMVCTestController.lineActivityChart(javax.portlet.ResourceRequest,javax.portlet.ResourceResponse) throws javax.portlet.PortletException,java.io.IOException]; nested exception is java.lang.IllegalStateException: Current request is not of type [javax.portlet.ResourceRequest]: com.liferay.portlet.RenderRequestImpl@53abc22d

My controller class is like this:

@Controller(value="MyFirstSpringMVCTestController")
@RequestMapping("VIEW")

public class MyFirstSpringMVCTestController {
@RenderMapping
public void lineActivityChart(ResourceRequest request,ResourceResponse response)throws PortletException,IOException{
response.setContentType("image/png");
try{
JFreeChart chart = createChart(pdset,"My Activity","Values");
ChartUtilities.writeChartAsPNG(response.getPortletOutputStream(),chart, 380, 260);
/*caloriesConsumed.add(healthDairyIntake.getCaloriesConsumed());
if(!caloriesConsumed.isEmpty()){
return caloriesConsumed;
}*/
response.getPortletOutputStream().close();
} catch (Exception e){
System.out.println();
}
}
Any hints is helpful for me and appricated.

Regards,
Srinivas
thumbnail
Tina Agrawal, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Expert Postagens: 297 Data de Entrada: 03/01/08 Postagens Recentes
From the error it seems when you are invoking this you have created a render request and not a resource request.

Can you paste the code of how you are invoking this?

Tina
thumbnail
Pankaj Kathiriya, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
This is because you are using annotation RenderMapping and your method is having signature is having (ResourceRequest request,ResourceResponse response) in it.

Change annotation to @ResourceMapping, it will resolve your issue.


Regards
thumbnail
Tina Agrawal, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Expert Postagens: 297 Data de Entrada: 03/01/08 Postagens Recentes
Good catch Pankaj. I missed it emoticon
srinivasa rao, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Regular Member Postagens: 189 Data de Entrada: 29/01/14 Postagens Recentes
Hi Pankaj/Tina,

Thanks for ur reply..

I changes it as @ResourceMapping.
but i got an error:

here is my code:
@Controller(value="MyFirstSpringMVCTestController")
@RequestMapping(value="VIEW")


public class MyFirstSpringMVCTestController {
@ResourceMapping
public void lineActivityChart(ResourceRequest request,ResourceResponse response){

try{
System.out.println("Enter intoTry in lineactivitychart");
response.setContentType("image/png");
CategoryDataset pdset = createFitbitDataSet();
JFreeChart chart = createChart(pdset,"My Activity","Values");
ChartUtilities.writeChartAsPNG(response.getPortletOutputStream(),chart, 380, 260);
/*caloriesConsumed.add(healthDairyIntake.getCaloriesConsumed());
if(!caloriesConsumed.isEmpty()){
return caloriesConsumed;
}*/
response.getPortletOutputStream().close();
} catch (Exception e){
System.out.println("Exception"+e);
}
}

private static CategoryDataset createFitbitDataSet() {
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();

System.out.println("Enter into CategoryDataSet");

/*if(enrolleeFitbits != null){
int i = 1;
for(EnrolleeFitbit enrolleeFitbit: enrolleeFitbits){*/

defaultcategorydataset.addValue(600, "CALORIES BURNT", ""+1);
defaultcategorydataset.addValue(650, "CALORIES BURNT", ""+3);
defaultcategorydataset.addValue(700, "CALORIES BURNT", ""+5);
defaultcategorydataset.addValue(750, "CALORIES BURNT", ""+7);
defaultcategorydataset.addValue(800, "CALORIES BURNT", ""+9);
// defaultcategorydataset.addValue(enrolleeFitbit.getCaloriesConsumed(), "CALORIES CONSUMED", ""+i);

/*if(caloriesConsumed != null){
int i = 1;
for(Double calorieConsumed: caloriesConsumed){
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@calorieConsumed:"+calorieConsumed);
defaultcategorydataset.addValue(calorieConsumed, "CALORIES CONSUMED", ""+i);
i++;
}
}*/

return defaultcategorydataset;
}
private static JFreeChart createChart(CategoryDataset categorydataset,String title,String valueAxisLabel) {
JFreeChart jfreechart = ChartFactory.createLineChart(title, null, valueAxisLabel, categorydataset, PlotOrientation.VERTICAL, true, true, false);
jfreechart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
categoryplot.setBackgroundPaint(Color.lightGray);
categoryplot.setRangeGridlinesVisible(false);
java.net.URL url = (MyFirstSpringMVCTestController.class).getClassLoader().getResource("OnBridge11small.png");
if (url != null) {
ImageIcon imageicon = new ImageIcon(url);
jfreechart.setBackgroundImage(imageicon.getImage());
categoryplot.setBackgroundPaint(new Color(0, 0, 0, 0));
}
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
lineandshaperenderer.setBaseShapesVisible(true);
lineandshaperenderer.setDrawOutlines(true);
lineandshaperenderer.setUseFillPaint(true);
lineandshaperenderer.setBaseFillPaint(Color.white);
lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
return jfreechart;
}

}

Error:
EVERE: Servlet.service() for servlet MyhealthDashboard Servlet threw exception
org.springframework.web.portlet.NoHandlerFoundException: No handler found for portlet request: mode 'view', phase 'RENDER_PHASE', parameters map[[empty]]

if i change it as renderpahse it showing different error:

invalid JPG/PNG type
thumbnail
Pankaj Kathiriya, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
Well, there must be life-cycle method defined to Render Phase.

You may refer to links for Spring portlet link1, link2, link3
srinivasa rao, modificado 9 Anos atrás.

RE: Failed to invoke handler method

Regular Member Postagens: 189 Data de Entrada: 29/01/14 Postagens Recentes
Pankaj Kathiriya:
Well, there must be life-cycle method defined to Render Phase.

You may refer to links for Spring portlet link1, link2, link3


Hi Pankaj,

Wt ever u shared links are spring 2.5,but i m using spring 3.2 version..

i tried lot of ways to create a spring portlet with Jfree chart in liferay 6.2,unable to succeeded..is there any sample example to share?
thumbnail
Irfan Basha, modificado 8 Anos atrás.

RE: Failed to invoke handler method

New Member Postagens: 3 Data de Entrada: 21/02/16 Postagens Recentes
The reason it is throwing an error is because it is not finding the correct handler for your request.
If you are using the ResourceMapping, you should specify the param like @ResourceMapping("anyValue"). The DispatcherServlet identifies the method based on the "anyValue" that you are using. This "anyValue" acts as an URL to identify the method.
Generally, We use @ResurceMapping for Ajax Calls or combine with @ActionMapping.
@ActionMapping for form posts, @RequestMapping/RenderMapping method as render method for @ActionMapping.