發表文章

目前顯示的是有「JAX-WS」標籤的文章

Invoking web services via proxy using JAX-RPC and JAX-WS

Invoking Web Services through a proxy using JAX-WS MyService service = null; service = new MyService(); MyServiceSoap port = service.getMyServiceSoap(); BindingProvider bp = (BindingProvider) port; Binding binding = bp.getBinding(); Map ctx = bp.getRequestContext(); ctx.put(BindingProvider.USERNAME_PROPERTY, "proxyuser"); ctx.put(BindingProvider.PASSWORD_PROPERTY, "proxypassword"); Note that we don't specify the Proxy Server here. JAX-WS sends authentication information for the proxy in request headers. Invoking Web Services through a proxy using JAX-WS private HttpTransportInfo getHttpInfo() { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyServer", 9090)); HttpTransportInfo httpInfo = new HttpTransportInfo(); httpInfo.setProxy(proxy); httpInfo.setProxyUsername("proxyuser".getBytes()); httpInfo.setProxyPassword("proxypassword".getBytes()); ret...

JAX-WS WebService Time Out

WebS_Service service = new WebS_Service(wsdlLocation, qName); WebS webS = service.getWebSPort(); Map requestContext = ((BindingProvider)webS).getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlUrl); requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); // Timeout in millis requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 1000); // Timeout in millis
Web Service return Java object with binary data reference: http://blog.bdoughan.com/2011/03/jaxb-web-services-and-binary-data.html

View raw HTTP request on SoapUI

After you sent the soap message to web service end point, please click HTTP log at the bottom of the screen to view the whole HTTP request.

Access web service with username token by SoapUI

Create a new project on SoapUI. Double click on the Binding item. Select Service Endpoint tab page on the property window. Provide username, password. Select PasswordText as the WSS-Type.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser

When you encounter the following error that related to web service. java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser Solution 1: Ensure no xercesImpl.jar in your classpath since the implementation of xerce is built-in wiht JAVA SE 1.6. Solution 2: Use XmlJavaTypeAdapter [ @XmlJavaTypeAdapter(JaxbDateAdapter.class)] to convert XMLGregorianCalendar type to Date type. XMLGregorianCalendar is the built-in Java data type for JAXB mapping with datetime. Example: Binding.xjb <?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://java.sun.com/xml/ns/jaxb"                 xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"                 xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"               ...

Web service (JAX-WS) timeout

//1 minute for connection (( BindingProvider ) wsPort ). getRequestContext (). put ( " com.sun.xml.ws.connect.timeout " , 1 * 60 * 1000 ); //3 minutos for request (( BindingProvider ) wsPort ). getRequestContext (). put ( " com.sun.xml.ws.request.timeout " , 3 * 60 * 1000 );   or  import com.sun.xml.ws.developer.JAXWSProperties use JAXWSProperties. CONNECT_TIMEOUT and JAXWSProperties. REQUEST_TIMEOUT  

Code for web service client to invoke OC4J web service with WSS Username Token policy

Put UsernameToken.xml in the same package of the web service client class. Please find the code below for the coding details: protected Location locationWebSPort = null; protected static volatile LocationWebSManager me; protected String endpoint = null; protected String userName = null; protected String password = null; protected LocationWebSManager(){ } public static LocationWebSManager getInstance(){ if (me == null){ synchronized(LocationWebSManager.class){ me = new LocationWebSManager(); } } return me; } public Location getWebService() throws Exception{ if (locationWebSPort == null){ synchronized(LocationWebSManager.class){ ClientPolicyFeature cpf = new ClientPolicyFeature(); InputStream asStream = LocationWebSManager.class.getResourceAsStream("UsernameToken.xml"); cpf.setEffectivePolicy(new InputStreamPolicySource(asStream)); URL url = new URL(getEndpoint()); QName qName = new QName("http://loc...

Create Web Service with WSS Username Token Polic

Add @WebService(name="", serviceName="", portName="") annotation for the class. Add @Policy(uri = "policy:UsernameToken.xml") for the class. Add @WebMethod(operationName="") for method. Add @WebResult(name="") for method return name. Add @WebParam(name="") for method argument. Create policies folder under WEB-INF. Put the UsernameToken.xml under policies folder. The content of the xml file: <?xml version="1.0"?> <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512" > <sp:SupportingTokens> <wsp:Policy> <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200512/IncludeToken/AlwaysToRecipient"> <wsp:Policy> <sp:WssUsernameToken10/> </wsp:Policy> </sp:UsernameToken> </wsp:Policy> </sp:SupportingTokens...

Generate WebLogic Web Service Client on Eclipse

圖片
Add Dynamic Web Module and Oracle WebLogic Web Service Clients in Project Facets. Add Oracle WebLogic Server 11g in the Project Facets -> Runtimes. Right Click on the project and new a WebLogic Web Services -> Web Service Client. Select Remote WSDL Location. In the Customization Options, choose Define WSDL location at runtime when client instantiated.

JWS Programming Best Practices

The following list provides some best practices when programming the JWS file: When you create a document-literal-bare Web Service, use the @WebParam JWS annotation to ensure that all input parameters for all operations of a given Web Service have a unique name. Because of the nature of document-literal-bare Web Services, if you do not explicitly use the @WebParam annotation to specify the name of the input parameters, WebLogic Server creates one for you and run the risk of duplicating the names of the parameters across a Web Service. In general, document-literal-wrapped Web Services are the most interoperable type of Web Service. Use the @WebResult JWS annotation to explicitly set the name of the returned value of an operation, rather than always relying on the hard-coded name return , which is the default name of the returned value if you do not use the @WebResult annotation in your JWS file. From: http://download.oracle.com/docs/cd/E12840_01/wls/docs103/webserv...

JAX-WS: Configure the service end point at runtime

When deploying your Web Service client you often need to change the endpoint of the service that has been set during the code generation. This short post explains how you can set change it at runtime in the client code. You have two approaches to do that: set the endpoint in the Port using the BindingProvider get the endpoint URL from the WSDL itself at runtime Use the Binding Provider to set the endpoint URL The first approach is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property value of the BindingProvider (Port) using the following code: try { EmployeeServiceService service = new EmployeeServiceService(); EmployeeService port = service.getEmployeeServicePort(); BindingProvider bp = (BindingProvider)port; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://server1.grallandco.com:8282/HumanRessources/EmployeeServiceService" ); Employee emp = port.getEmployee( 123 ); System...