Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Post servlet giving 403 forbidden error during post ajax call

Avatar

Level 3

Hi Team,

Hope you are doing great.

 

Can you please me to resolve 403 error during post servlet call 

Forbidden

Cannot serve request to /bin/servlets/job-apply on this server


Apache Sling

import Vue from 'vue';
import Axios from "axios";

if(document.getElementById("job-details")){

var app = new Vue({
el: '#job-listing',
data:{
jobList: [],
},

mounted(){
const now = new Date();
var origin = location.origin;
var URL = origin+"/bin/servlets/job-apply";
const config = {
headers: {
"Content-Type": "application/json; charset=utf-8"
}
}
Axios.post(URL, config)
.then(response =>{
this.jobList = response.data;
console.log(this.jobList,'bhagchand saini')
});
},
})
}
 
 

package com.ranosys.website.core.servlets;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ranosys.website.core.services.SalesforceHttpService;

/**

*
* This method makes an HTTP call send data to salesforce
*
*/
@component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=HTTP servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_POST, "sling.servlet.paths=" + "/bin/servlets/job-apply" })
public class SalesforceJobApply extends SlingAllMethodsServlet {

/**
* Generated serialVersionUid
*/
private static final long serialVersionUID = -2014397651676211439L;

/**
* Logger
*/
private static final Logger log = LoggerFactory.getLogger(SalesforceJobApply.class);

@reference
private SalesforceHttpService httpService;

/**
* Overridden doPost() method
*/
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException{
log.error("---------basfhdsaggsaddshj----------");
try {
log.info("---------basfhdsaggsaddshj----------");
//response.getWriter().println(jsonResponse2);

} catch (Exception e) {

log.error(e.getMessage(), e);
}
}

}

 

Can you please anyone help on this

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
11 Replies

Avatar

Community Advisor

Could you please try the below one -

 

To make this form submission process operational on AEM instance I have added servlet path via

http://<aem-instance>:port/system/console/configMgr

DEBAL_DAS_0-1650975046500.png

 

Please use your servlet path: /bin/servlets/job-apply in above configuration and let me know.

Avatar

Community Advisor

Please access localhost:4502/system/console/configMgr and the search Adobe Granite CSRF filter.

Avatar

Community Advisor

From the screenshot it looks like '/' is missing. Value should be /bin/servlets/job-apply

Avatar

Correct answer by
Community Advisor

Avatar

Employee Advisor

Hi @bhagchand ,

I think @DEBAL_DAS has noted it right, the "/" is missing in the literal starting, please append the same and try.

Please paste the following value :

/bin/servlets/job-apply

Thanks.