Как я могу подключиться к веб -службе Apache CXF, размещенной на Apache Tomcat (WS Security включена)?JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как я могу подключиться к веб -службе Apache CXF, размещенной на Apache Tomcat (WS Security включена)?

Сообщение Anonymous »

Я использую пример WSSEC_SIGN_ENC в образцах безопасности WS в apachecxf jar, развернутом под Apache Tomcat 7.0.29.
my web.xml: < / p > < b r / > < b r / > < c o d e > & l t ; ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? & g t ; < b r / > & l t ; w e b - a p p x m l n s : x s i = " h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / X M L S c h e m a - i n s t a n c e " x m l n s = " h t t p : / / j a v a . s u n . c o m / x m l / n s / j a v a e e " x s i : s c h e m a L o c a t i o n = " h t t p : / / j a v a . s u n . c o m / x m l / n s / j a v a e e h t t p : / / j a v a . s u n . c o m / x m l / n s / j a v a e e / w e b - a p p _ 3 _ 0 . x s d " i d = " W e b A p p _ I D " v e r s i o n = " 3 . 0 " & g t ; < b r / > & l t ; d i s p l a y - n a m e & g t ; T e s t i n g W e b W s S e c u r i t y & l t ; / d i s p l a y - n a m e & g t ; < b r / > & l t ; w e l c o m e - f i l e - l i s t & g t ; < b r / > & l t ; w e l c o m e - f i l e & g t ; i n d e x . h t m l & l t ; / w e l c o m e - f i l e & g t ; < b r / > < b r / > & l t ; / w e l c o m e - f i l e - l i s t & g t ; < b r / > & l t ; s e r v l e t & g t ; < b r / > & l t ; d e s c r i p t i o n & g t ; A p a c h e C X F E n d p o i n t & l t ; / d e s c r i p t i o n & g t ; < b r / > & l t ; d i s p l a y - n a m e & g t ; c x f & l t ; / d i s p l a y - n a m e & g t ; < b r / > & l t ; s e r v l e t - n a m e & g t ; c x f & l t ; / s e r v l e t - n a m e & g t ; < b r / > & l t ; s e r v l e t - c l a s s & g t ; o r g . a p a c h e . c x f . t r a n s p o r t . s e r v l e t . C X F S e r v l e t & l t ; / s e r v l e t - c l a s s & g t ; < b r / > & l t ; l o a d - o n - s t a r t u p & g t ; 1 & l t ; / l o a d - o n - s t a r t u p & g t ; < b r / > & l t ; / s e r v l e t & g t ; < b r / > & l t ; s e r v l e t - m a p p i n g & g t ; < b r / > & l t ; s e r v l e t - n a m e & g t ; c x f & l t ; / s e r v l e t - n a m e & g t ; < b r / > & l t ; u r l - p a t t e r n & g t ; / s e r v i c e s / * & l t ; / u r l - p a t t e r n & g t ; < b r / > & l t ; / s e r v l e t - m a p p i n g & g t ; < b r / > & l t ; s e s s i o n - c o n f i g & g t ; < b r / > & l t ; s e s s i o n - t i m e o u t & g t ; 6 0 & l t ; / s e s s i o n - t i m e o u t & g t ; < b r / > & l t ; / s e s s i o n - c o n f i g & g t ; < b r / > & l t ; c o n t e x t - p a r a m & g t ; < b r / > & l t ; p a r a m - n a m e & g t ; c o n t e x t C o n f i g L o c a t i o n & l t ; / p a r a m - n a m e & g t ; < b r / > & l t ; p a r a m - v a l u e & g t ; W E B - I N F / c x f - b e a n s . x m l & l t ; / p a r a m - v a l u e & g t ; < b r / > & l t ; / c o n t e x t - p a r a m & g t ; < b r / > & l t ; l i s t e n e r & g t ; < b r / > & l t ; l i s t e n e r - c l a s s & g t ; o r g . s p r i n g f r a m e w o r k . w e b . c o n t e x t . C o n t e x t L o a d e r L i s t e n e r & l t ; / l i s t e n e r - c l a s s & g t ; < b r / > & l t ; / l i s t e n e r & g t ; < b r / > & l t ; / w e b - a p p & g t ; < b r / > < / c o d e > < b r / > < b r / > m y c x f - b e a n s . x m l < / p > < b r / > < b r / > < c o d e > & l t ; ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? & g t ; < b r / > & l t ; b e a n s x m l n s = " h t t p : / / w w w . s p r i n g f r a m e w o r k . o r g / s c h e m a / b e a n s " < b r / > x m l n s : x s i = " h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / X M L S c h e m a - i n s t a n c e " x m l n s : j a x w s = " h t t p : //cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core" xmlns:wsa="http://cxf.apache.org/ws/addressing"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"
xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
xsi:schemaLocation=" http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configura ... p-conf.xsd http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/r ... policy.xsd http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configura ... anager.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/b ... -beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">



































































< /code>

Мой файл wsdl: < / p > < b r / > < b r / > < c o d e > & l t ; ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? & g t ; < b r / > < b r / > & l t ; w s d l : d e f i n i t i o n s n a m e = " H e l l o W o r l d " t a r g e t N a m e s p a c e = " h t t p : / / c x f . a p a c h e . o r g / h e l l o _ w o r l d _ s o a p _ h t t p " < b r / > x m l n s = " h t t p : / / s c h e m a s . x m l s o a p . o r g / w s d l / " < b r / > x m l n s : s o a p = " h t t p : / / s c h e m a s . x m l s o a p . o r g / w s d l / s o a p / " < b r / > x m l n s : t n s = " h t t p : / / c x f . a p a c h e . o r g / h e l l o _ w o r l d _ s o a p _ h t t p " < b r / > x m l n s : x 1 = " h t t p : / / c x f . a p a c h e . o r g / h e l l o _ w o r l d _ s o a p _ h t t p / t y p e s " < b r / > x m l n s : w s d l = " h t t p : / / s c h e m a s . x m l s o a p . o r g / w s d l / " < b r / > x m l n s : x s d = " h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / X M L S c h e m a " & g t ; < b r / > & l t ; w s d l : t y p e s & g t ; < b r / > & l t ; s c h e m a t a r g e t N a m e s p a c e = " h t t p : / / c x f . a p a c h e . o r g / h e l l o _ w o r l d _ s o a p _ h t t p / t y p e s " < b r / > x m l n s = " h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / X M L S c h e m a " e l e m e n t F o r m D e f a u l t = " q u a l i f i e d " & g t ; < b r / > & l t ; e l e m e n t n a m e = " s a y H i " & g t ; < b r / > & l t ; c o m p l e x T y p e/>







































































































< /code>

Клиентский код: < /p>

package demo.wssec.client;

import java.io.Closeable;

import java.lang.reflect.UndeclaredThrowableException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.hello_world_soap_http.Greeter;
import org.apache.cxf.hello_world_soap_http.GreeterService;

import org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;

public final class Client {

private static final String WSU_NS
= "http://docs.oasis-open.org/wss/2004/01/ ... ty-1.0.xsd";

private Client() {
}

public static void main(String args[]) throws Exception {
try {

SpringBusFactory bf = new SpringBusFactory();
URL busFile = Client.class.getResource("wssec.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);

Map outProps = new HashMap();
outProps.put("action", "UsernameToken Timestamp Signature Encrypt");

outProps.put("passwordType", "PasswordDigest");

outProps.put("user", "abcd");
outProps.put("password", "storepassword");
outProps.put("signatureUser", "clientx509v1");

outProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");

outProps.put("encryptionUser", "serverx509v1");
outProps.put("encryptionPropFile", "etc/Client_Encrypt.properties");
outProps.put("encryptionKeyIdentifier", "IssuerSerial");
outProps.put("encryptionParts",
"{Element}{" + WSU_NS + "}Timestamp;"
+ "{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body");

outProps.put("signaturePropFile", "etc/Client_Sign.properties");
outProps.put("signatureKeyIdentifier", "DirectReference");
outProps.put("signatureParts",
"{Element}{" + WSU_NS + "}Timestamp;"
+ "{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body;"
+ "{}{http://www.w3.org/2005/08/addressing}ReplyTo;");

outProps.put("encryptionKeyTransportAlgorithm",
"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
outProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");

bus.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

Map inProps = new HashMap();

inProps.put("action", "UsernameToken Timestamp Signature Encrypt");
inProps.put("passwordType", "PasswordText");
inProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");

inProps.put("decryptionPropFile", "etc/Client_Sign.properties");
inProps.put("encryptionKeyIdentifier", "IssuerSerial");

inProps.put("signaturePropFile", "etc/Client_Encrypt.properties");
inProps.put("signatureKeyIdentifier", "DirectReference");

inProps.put("encryptionKeyTransportAlgorithm",
"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
inProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");

bus.getInInterceptors().add(new WSS4JInInterceptor(inProps));

// Check to make sure that the SOAP Body and Timestamp were signed,
// and that the SOAP Body was encrypted
DefaultCryptoCoverageChecker coverageChecker = new DefaultCryptoCoverageChecker();
coverageChecker.setSignBody(true);
coverageChecker.setSignTimestamp(true);
coverageChecker.setEncryptBody(true);
bus.getInInterceptors().add(coverageChecker);

GreeterService service = new GreeterService();
Greeter port = service.getGreeterPort();

String[] names = new String[] {"Anne", "Bill", "Chris", "Sachin Tendulkar"};
// make a sequence of 4 invocations
for (int i = 0; i < 4; i++) {
System.out.println("Invoking greetMe...");
String response = port.greetMe(names);
System.out.println("response: " + response + "\n");
}

// allow asynchronous resends to occur
Thread.sleep(30 * 1000);

if (port instanceof Closeable) {
((Closeable)port).close();
}

bus.shutdown(true);

} catch (UndeclaredThrowableException ex) {
ex.getUndeclaredThrowable().printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
System.exit(0);
}
}
}
< /code>

Когда я выполняю клиент -код, он сказал: < /p>

Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '404: Not Found' when communicating with http://localhost:12000/TestingWebWsSecu ... reeterPort
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1526)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1486)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1305)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
... 9 more

javax.xml.ws.WebServiceException: Could not send Message.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
at com.sun.proxy.$Proxy40.greetMe(Unknown Source)
at demo.wssec.client.Client.main(Client.java:120)
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '404: Not Found' when communicating with http://localhost:12000/TestingWebWsSecu ... reeterPort
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1526)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1486)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1305)
at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50)
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:541)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
... 2 more


Подробнее здесь: https://stackoverflow.com/questions/183 ... s-security
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»