Tag: cxf

使用Apache CXF签名和加密SOAP消息

我正在尝试使用Apache CXF编写“安全Hello World”Web服务; 我应该注意到我对Java和WS- *的新东西有些新意。 基本上,我想要做的是一个hello-world Web服务, 使用x.509证书对来自此Web服务的SOAP消息进行签名和加密 。 我已经在Apache CXF网站上阅读了关于WS-Security的教程但是; 我想使用WS-SecurityPolicy而不是拦截器。 谁能指出我正确的方向?

缺少cxf.xml? 在maven中失败,在Eclipse中工作

我正在使用Apache CXF JAX-RS在Eclipse中构建项目。 当我在Eclipse中运行我的主类时,它工作正常。 当我在maven中构建一个具有依赖关系的jar时,它不起作用。 这是我的pom.xml(我通过运行“mvn clean compile assembly:single”来构建): 4.0.0 com.theopentutorials.jaxrs JsonCxfProvider 0.0.1-SNAPSHOT jar org.apache.cxf cxf-rt-frontend-jaxrs 2.7.4 org.apache.cxf cxf-rt-transports-http-jetty 2.7.4 org.apache.cxf cxf-rt-rs-extension-providers 2.7.4 org.slf4j slf4j-log4j12 1.7.5 org.codehaus.jettison jettison 1.3.3 javax.xml.bind jaxb-api 2.2.7 maven-assembly-plugin com.theopentutorials.jaxrs.calc.CalcRESTStartUp jar-with-dependencies 这是我的主要课程: public static void main(String[] args) { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(ResultsXml.class); sf.setResourceProvider(ResultsXml.class, new SingletonResourceProvider(new ResultsXml())); sf.setAddress(“http://localhost:9999/open/”); Server server […]

使用Apache CXF注释的UsernameToken WS-Security(WSS4J)

我正在尝试创建一个“java first”webservice,它将使用简单的UsernameToken WS-Security。 我试图遵循CXF的例子。 当我查询我的wsdl时,我看不到任何与安全相关的内容。 我正在使用CXF 2.7.5而我正在尝试用注释做所有事情。 以下是我失败的尝试: SampleService.java: import java.util.ArrayList; import java.util.Date; import javax.jws.WebParam; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import org.apache.cxf.annotations.EndpointProperties; import org.apache.cxf.annotations.EndpointProperty; @WebService(targetNamespace=”https://test.company.com/ws/”) @SOAPBinding(style = SOAPBinding.Style.RPC) @EndpointProperties({ @EndpointProperty(key = “action”, value=”UsernameToken”), @EndpointProperty(key = “passwordType”, value=”PasswordText”), @EndpointProperty(key = “ws-security.callback-handler”, value=”PasswordHandler”), //@EndpointProperty(key = “ws-security.validate.token”, value=”false”), }) public interface SampleService { @WebMethod public String getSample( […]

CXF 2.2.12:如何在客户端关闭模式validation

我想关闭JAXB绑定消息的模式validation。 我正在处理客户端CXF代码(WSDL第一代)。 我试过用 没有成功(参见参考CXF FAQ )。 我很难找到一种设置此属性的编程方式。 我还探讨了短路CXF并访问解析器,unmarshaller等。 谢谢你的帮助。

CXF客户端SOAP消息格式化

我用来创建CXF客户端的WSDL文件具有以下元素定义: 但是,当我尝试发送SOAP消息时,小数点后的位数超过最大值。 例如,我得到2.48862而期望2.48。 为了解决这个问题,我计划实现一个XmlAdapter来编组值,但是我无法将WSDL中的元素映射到客户端,因为XmlAdapter的onyl类作为注释传递给字段decleration。 @XmlJavaTypeAdapter(CustomXmlAdapter.class) 似乎没有办法通知XmlAdapter该字段在小数点后必须有2位数。 小数位数从元素到元素的变化。 我也没有权限来更改WSDL。 有没有办法在观察WSDL中指定的小数点数时格式化这些元素?

CXF客户端exception:{XXX}的拦截器抛出exception,现在展开

我遇到以下CXFexception: warning: Interceptor for {http://example.com/wsdl/esc/2011-12-12/}AmazonEC2#{http://example.com/wsdl/esc/2011-12-12/}NewDescribeImages has thrown exception, unwinding now java.lang.NullPointerException at org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor.handleMessage(StartBodyInterceptor.java:59) at org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor.handleMessage(StartBodyInterceptor.java:37) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:762) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1582) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1467) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1375) at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47) at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:188) 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:263) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:510) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124) at $Proxy31.newDescribeImages(Unknown Source) at test.App.main(App.java:62) javax.xml.ws.soap.SOAPFaultException: […]

使用NTLM到SharePoint的CXF SOAP客户端

我正在使用适用于SharePoint 2007的CXF Framework(版本:2.7.8)编写SOAP客户端。我已经按照联机文档在此处添加了NTLM支持。 我让客户端工作并跟踪HTTP会话显示正在发送NTLM凭据,但是,我仍然收到401 Unauthorized响应。 码: Lists listService = new Lists(); ListsSoap port = listService.getListsSoap(); BindingProvider bp = (BindingProvider) port; bp.getRequestContext().put(“use.async.http.conduit”, Boolean.TRUE); Credentials creds = new NTCredentials(USER, PASS, “”, DOMAIN); bp.getRequestContext().put(Credentials.class.getName(), creds); Client client = ClientProxy.getClient(proxy); HTTPConduit http = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(36000); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setAutoRedirect(true); http.setClient(httpClientPolicy); // Build request and execute […]

在自定义拦截器中捕获SOAP Fault错误(Soap12FaultOutInterceptor)

我编写了一个自定义CXF拦截器来将所有SOAP请求和响应记录到数据库中,它似乎与正面测试用例和服务器错误一起正常工作。 但是当发生SOAP Fault时,它只是忽略了我的拦截器而没有记录任何内容。 自定义CXF拦截器。 public class DbLogOutInterceptor extends AbstractSoapInterceptor { public void handleMessage(SoapMessage message) { logger.info(“Handling outbound request”); String transaction = MDC.get(mdcKey); logger.info(“OutBound Transaction ID : {} “, transaction); //code to log the SOAP message in database ……. } } 我没有看到这种方法的日志语句 11:56:34,102 INFO [Soap12FaultOutInterceptor] class org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor$Soap12FaultOutInterceptor Internalapplication/soap+xml 11:56:34,103 INFO [EligibilityInfo] Outbound Message ————————— ID: 2 […]

Apache Camel:带有CxfEndpoint的RouteBuilder

你好! 我正在尝试使用Java DSL和RouteBuilder实现Camel路由。 我想从计时器端点发送到cxf端点。 码: public class MyRoute extends RouteBuilder { @Override public void configure() { CamelContext camelContext = getContext(); CxfEndpoint cxfEndpoint = new CxfEndpoint(); cxfEndpoint.setAddress(“http://localhost:8088/interface”); cxfEndpoint.setWsdlURL(“wsdl/contract.wsdl”); cxfEndpoint.setCamelContext(camelContext); cxfEndpoint.setDataFormat(DataFormat.PAYLOAD); try { camelContext.addEndpoint(“myEndpoint”, cxfEndpoint); } catch (Exception e) { e.printStackTrace(); } from(“timer://my-timer?fixedRate=true&period=500”) .transform(constant(“DummyBody”)) .to(“cxf://myEndpoint”); } } 这个路由被插入到使用Spring XML定义的camel上下文中(我有一些其他路由)。 问题: 我收到以下错误: karaf@root> Exception in thread “SpringOsgiExtenderThread-78” org.apache.camel.FailedToCreateProducerException: […]

使用CXF上传多个文件和元数据

我需要使用CXF创建一个文件上载处理程序作为REST Web服务。 我已经能够使用以下代码上传包含元数据的单个文件: @POST @Path(“/uploadImages”) @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadImage(@Multipart(“firstName”) String firstName, @Multipart(“lastName”) String lastName, List attachments) { for (Attachment att : attachments) { if (att.getContentType().getType().equals(“image”)) { InputStream is = att.getDataHandler().getInputStream(); // read and store image file } } return Response.ok().build(); } 现在我需要添加对在同一请求中上传多个文件的支持。 在这种情况下,我得到一个带有multipart/mixed内容类型的附件,而不是带有image/jpeg内容类型的附件,它本身包含我需要的单个image/jpeg附件。 我已经看到了使用元数据上传多个JSON或JAXB对象的示例,但是我无法使用二进制图像数据。 我已尝试直接使用MultipartBody,但它只返回multipart/mixed附件,而不是其中嵌入的image/jpeg附件。 有没有办法递归解析multipart/mixed附件以获取嵌入的附件? 我当然可以得到multipart/mixed附件的输入流,并自己解析文件,但我希望有更好的方法。 UPDATE 这看起来像kludgey,但是下面的代码现在已经足够好了。 我希望看到更好的方式。 for (Attachment att : attachments) […]