제발, 나는 항상 같은 오류를 가지고 며칠 동안 붙어 있습니다. HTTP 헤더에서 정보를 얻기 위해 인터셉터를 추가 한 helloWorld apache cxf 예제를 테스트하고 있습니다.WebLogic 12c에서 Apache CXF 인터셉터가 트리거되지 않았습니까?
IDEA Intellij 11.0.2를 사용하여 개발 중이며 Intelli에서 테스트 할 때 훌륭하게 작동하지만 WebLogic 12c에 이슈를 배포 할 때 항상 null 포인터 예외가 있습니다.
개인용 컴퓨터 (Windows 7 Professional)의 로컬 WebLogic 12c 및 UNIX 서버 AIX 7.1의 WebLogic 12c에서도 동일한 오류가 발생합니다.
JDK 1.7.0과 Apache CXF 2.7.12를 사용합니다.
IDEA Intellij에서 코드를 디버깅 할 때 인터셉터 생성자가 실행되고 handleMessage도 실행되는 것을 볼 수 있습니다. 그러나 WebLogic에서 디버깅 할 때 생성자가 실행되지만 handleMessage는 실행되지 않습니다.
내 문제는이 코드 줄에 있습니다
Message message = PhaseInterceptorChain.getCurrentMessage();
변수 "메시지가"나는 IDEA 인 IntelliJ에서/디버그를 실행할 때 제대로 설치하지만 웹 로직에서/디버그를 실행할 때 항상 NULL이다. 어쨌든, 나는 "handleMessage"가 WebLogic에서는 호출되지 않지만 IDEA에서는 Intellij가 호출되기 전에 문제가 발생한다고 생각합니다.
IDEA Intellij 및 WebLogic에 디버깅의 스크린 샷을 추가하여 의미를 알려줍니다. 내가 디버깅 할 때 나는 당신을 보여 같은 결과 만 더 일을 보았 기 때문에이 3 개 선을 위해
Message message = PhaseInterceptorChain.getCurrentMessage();
: (인 IntelliJ에서 디버깅 할 때
Bus bus = BusFactory.getDefaultBus();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
Message message = chain.getCurrentMessage();
이 내가 무엇을 얻을 나는 라인을 변경 모든 것이 정상적으로 작동 함) :
-> 죄송합니다. 평판이 10 개 이상 될 때까지 이미지를 게시 할 수 없습니다. 어쨌든 여기서는 인터셉터가 프로그래밍 방식으로 추가되었고 인터셉터의 constructor과 handleMessage가 실행되어 모든 것이 잘 작동 함을 보여줍니다. "버스", "체인"및 "메시지"가 올바르게 채워집니다. > 죄송합니다, 나는 적어도 10 명성을 가진 때까지 이미지를 게시 할 수 없습니다 -
:
는 그리고 이것은 웹 로직에서 디버깅 (I 예상대로 작동하지 않을 때) 내가 무엇을 얻을 수 있습니다. 어쨌든, 여기에 요격기가 프로그래밍 방식으로 추가되었고 인터셉터의 생성자가 실행되지만 인터셉터의 handleMessage는 실행되지 않으므로 "버스", "체인"이 채워지지만 "메시지"가 null이기 때문에 결국 오류가 발생합니다.
마지막으로, 몇 가지 코드 :
1) HelloWorldImpl.java
package example;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import javax.jws.WebMethod;
import javax.jws.WebService;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.phase.PhaseManager;
@WebService()
public class HelloWorldImpl implements HelloWorld {
public HelloWorldImpl() {
Bus bus = BusFactory.getDefaultBus();
UserCredentialInterceptor myInterceptor = new UserCredentialInterceptor();
bus.getInInterceptors().add(myInterceptor);
}
@WebMethod
public String sayHelloWorldFrom(String from) {
//Message message = PhaseInterceptorChain.getCurrentMessage();
Bus bus = BusFactory.getDefaultBus();
PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
Message message = chain.getCurrentMessage();
if (message==null) {
System.out.println("HELLOWORLD ERROR");
} else {
System.out.println("HELLOWORLD OK");
}
String result = "Hello, world, from " + from;
System.out.println(result);
return result;
}
}
2) UserCredentialInterceptor.java
package example;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.w3c.dom.NodeList;
import javax.servlet.http.HttpServletRequest;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import java.util.Enumeration;
import javax.servlet.http.Cookie;
public class UserCredentialInterceptor extends AbstractSoapInterceptor {
private SAAJInInterceptor saajIn = new SAAJInInterceptor();
public UserCredentialInterceptor() {
super(Phase.PRE_PROTOCOL);
getAfter().add(SAAJInInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage doc = message.getContent(SOAPMessage.class);
if (doc == null) {
saajIn.handleMessage(message);
doc = message.getContent(SOAPMessage.class);
}
SOAPHeader headerr = null;
try {
headerr = doc.getSOAPHeader();
} catch (SOAPException e) {
e.printStackTrace();
}
if (headerr != null) {
NodeList nodes = headerr.getElementsByTagNameNS("http://asjava.com/types", "Username");
if (nodes != null && nodes.item(0) != null) {
String user = nodes.item(0).getTextContent();
}
}
//if you want to read more http header messages, just use get method to obtain from HttpServletRequest.
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
if(null!=request){
//Read http header to get client IP adress
String addr = request.getRemoteAddr();
//Read http header to get HeaderNames
Enumeration enums = request.getHeaderNames();
//Read http header to get cookie/
Cookie[] cookies = request.getCookies();
}
}
}
3) application.xml을
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd"><application>
<display-name>test_interceptors</display-name>
<module>
<web>
<web-uri>/</web-uri>
<context-root>/</context-root>
</web>
</module>
</application>
4) weblogic-applicatio 엔.XML
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://www.bea.com/ns/weblogic/weblogic-application http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd">
<wls:application-param>
<wls:param-name>webapp.encoding.default</wls:param-name>
<wls:param-value>UTF-8</wls:param-value>
</wls:application-param>
<wls:prefer-application-packages>
<wls:package-name>javax.wsdl.*</wls:package-name>
<wls:package-name>javax.ws.rs.*</wls:package-name>
</wls:prefer-application-packages>
</wls:weblogic-application>
5) web.xml을
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<description>cxf</description>
<display-name>cxf</display-name>
<servlet>
<description>Apache CXF Endpoint</description>
<display-name>cxf</display-name>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
6) weblogic.xml의
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
</beans>
하십시오
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
7) CXF-servlet.xml에
, 어떤 도움 매우 감사드립니다.감사합니다. Felix Mercader.
거대한 코드 블록입니다. 먼저 [묻는 방법] (http://stackoverflow.com/help/how-to-ask)을 읽어보십시오. 모든 (대부분 불필요한) 코드 라인을 읽는 것은 꽤 어렵습니다. –
Intellij 또는 WebLogic에서 디버깅 할 때의 모든 차이점을 보여주기 때문에 두 개의 이미지를 추가하고 싶습니다. 적어도 10 가지 이상의 평판이 없기 때문에 나는 할 수 없습니다. 어쨌든, 내 문제는 줄에있다 Message message = PhaseInterceptorChain.getCurrentMessage(); "message"는 Intellij에 올바르게 채워지지만 WebLogic에서는 null입니다. –