
Estou construindo um aplicativo REST no servidor Tomcat 7.
usando a classe Application para bootstrap.
Implementação da classe de aplicativo da seguinte maneira. Criando um objeto singleton de Resource01.
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import com.somename.api.Resource01;
@ApplicationPath("/service")
public class AppConfig extends Application{
public Set<Object> all_resources;
@Override
public Set<Object> getSingletons()
{
all_resources = new HashSet<Object>();
Resource01 z = new Resource01();
all_resources.add(z);
return all_resources;
}
}
A classe de recursos é a seguinte.
Estou fornecendo suporte para 2 métodos http PUT e GET.
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("resource")
public class Resource01 {
@GET
@Path("mailer_status")
@Produces(MediaType.TEXT_HTML)
public String getMailStatus()
{
return "<h2>Mailer is in progress 14.47</h2>";
}
@PUT
@Path("create_config")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String getMailConfig(String config)
{
//String instance_rep = m_config.toString();
return "Payload Delivered";
}
}
tomcat-users.xml é o seguinte.
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
</tomcat-users>
arquivo está localizado em %CATALINA_HOME%/conf
Eu naveguei/naveguei pelo motivo da falha e com base nisso modifiquei o web.xml localizado em% CATALINA_HOME%/webapps/manager/WEB-INF
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>manager-gui</role-name>
</auth-constraint>
<!-- Specifying a Secure Connection -->
<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL (forced SSL), INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Tomcat Manager Application</realm-name>
</login-config>
então eu exporto o projeto web dinâmico como um arquivo war e implanto o arquivo war. para fins de teste, o ARC (cliente de descanso avançado) é usado.
a princípio tentei solicitação GET - a resposta foi recebida. captura de tela anexada.
Obter solicitação
como pode ser visto na captura de tela, 200 respostas OK são recebidas. Consigo ver a string desejada no navegador.
quando tento a solicitação PUT. Recebo o erro 403 Proibido. Estou anexando algumas capturas de tela que descrevem o mesmo.
PUT_REQUEST_HEADER
PUT_REQUEST-PAYLOAD
PUT_RESPONSE
qualquer ajuda/orientação é apreciada.
cumprimentos,
Ashish
Responder1
não dei uma olhada no web.xml mantido na pasta conf.
lá nós tivemos isso
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>TRACE</http-method>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Comentei o método PUT.
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>TRACE</http-method>
<!--<http-method>PUT</http-method>-->
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
e funcionou!