Sei sulla pagina 1di 13

Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

Calling GenericSoapService with WS-Security settings in JDeveloper using a Web Service Proxy (Doc ID
1332308.1)

In this Document

Goal
Solution
Still have questions?
References

APPLIES TO:

Oracle WebCenter Content - Version 11.1.1.3.0 and later


Information in this document applies to any platform.

GOAL

This document contains instructions on how to call the UCM 11g GenericSoapService from JDeveloper when the service requires WS-Security
policies.

This example uses the policy wss11_username_token_with_message_protection_client_policy.

SOLUTION

Copy Keystore files to client

In the UCM domain, a default keystore is available and can be used for testing the GenericSoapService using WS-Policy security settings.

For more information on Web Services in UCM 11g, see the Developer's Guide, Chapter 7 and the note below. This contains steps on
creating a custom keystore. For illustrative purposes, the default-keystore.jks is used in the following example.

Document 1334029.1 - Configuring a Keystore in UCM 11g for Use With Web Services

UCM 11g Developer's Guide Link:


http://download.oracle.com/docs/cd/E14571_01/doc.1111/e10807/web_services.htm#CHDDIJJB

Note: A keystore must be configured. See section 12.4.2 of the Developer's Guide for "Configuring SAML Support".

http://download.oracle.com/docs/cd/E17904_01/doc.1111/e10807/c12_web_services.htm#CHDDIJJB

Locate the following directory on the machine where UCM 11g is running:

$MW_HOME/user_projects/domains/<ucm-domain>/config/fmwconfig

For example: /opt/middleware/user_projects/domains/ucm_domain/config/fmwconfig

Several files must be copied to the client machine for the web service test to use the keystore. The files needed in this directory are:

a. cwallet.sso
b. default-keystore.jks (this file must be created on the server before it can be copied. See section 12.4.2 of the Developer's Guide.)
c. jps-config-jse.xml

1 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

Copy these file to the local directory, to a path where JDeveloper can reference them. For this example, they are moved to a Windows
machine in the path C:\fmwconfig.

Creating the Web Service proxy in JDeveloper:


1. Create a new generic application and project in JDeveloper.

2 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

2. Add to the project a Web Service Proxy. Right click on the Project and select "New". In the window that opens, select Web Services ->
Web Service Proxy. Click OK.

3 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

3. Select JAX-WS style.

4. Enter the WSDL location for the GenericSoapService (GenericSoapPort). This URL for UCM 11g is of the following format. Click next.
JDeveloper will parse the WSDL and create Java classes for use in calling the web service.

4 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

http://<host>:<port>/idcws/GenericSoapPort?WSDL

Example:
http://192.168.2.4:16200/idcws/GenericSoapPort?WSDL

5. Accept all defaults by clicking next until the "Policy" screen is displayed. On the Security section, add the appropriate policy that is used
for the web service.

This example has GenericSoapService attached to the WS-Policy oracle/wss11_username_token_with_message_protection_client_policy

5 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

6. Accept the defaults for the remaining pages of the Wizard.


7. A Java class is created in the project called GenericSoapPortClient.java. This is the client class that can be used for testing the web
service. Open this java file for editing. Notice the commented line that states:
// Add your code to call the desired methods.

Below this line is the place to add code to call UCM services.

6 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

8. You will need to import certain packages and classes at the top of the client class in order for this sample code to compile. JDeveloper
may import the packages/classes automatically, but if not, the imports needed for running this test are as follows:

import com.oracle.ucm.Field;
import com.oracle.ucm.Generic;
import com.oracle.ucm.Service;
import com.oracle.ucm.ResultSet;
import com.oracle.ucm.Row;
import com.oracle.ucm.File;
import java.util.List;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;
import weblogic.wsee.jws.jaxws.owsm.SecurityPolicyFeature;

9. Before calling the web service, keystore and username credentials must be set in the client class. Here is a snippet:

//Set KeyStore path info as system property.


//The jps-config-jse.xml file will reference the default-keystore.jks file and the cwallet.sso.
System.setProperty("oracle.security.jps.config",
"D:\\webservices\\jps-config-jse.xml");

genericSoapService = new GenericSoapService();


SecurityPolicyFeature[] securityFeatures =
new SecurityPolicyFeature[] { new
SecurityPolicyFeature("oracle/wss11_username_token_with_message_protection_client_policy") };

//new SecurityPolicyFeature[] { new SecurityPolicyFeature("oracle/wss_username_token_service_policy") };

GenericSoapPortType genericSoapPortType =
genericSoapService.getGenericSoapPort(securityFeatures);
// Add your code to call the desired methods.

//Set username and password


Map<String, Object> requestContext =

7 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

((BindingProvider)genericSoapPortType).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, "weblogic");
requestContext.put(BindingProvider.PASSWORD_PROPERTY, "welcome1");

10. To call the service, the service and parameters must be declared and set. The following snippet shows how to setup the service and call
it.

Generic request = new Generic();


request.setWebKey("cs");
Service service = new Service();
request.setService(service);
service.setIdcService("DOC_INFO");
Service.Document document = new Service.Document();
service.setDocument(document);

List<Field> fields = document.getField();


Field field = new Field();
field.setName("dID");
field.setValue("1");
fields.add(field);

// Make the request


Generic response = genericSoapPortType.genericSoapOperation(request);
Service serviceResponse = response.getService();

A CHECKIN_NEW service requires additional code. Notice that a File must be inserted into the request. This sample inserts a file called
HelloWorld.txt into the request.

Generic request = new Generic();

request.setWebKey("cs");
Service service = new Service();
request.setService(service);
service.setIdcService("CHECKIN_NEW");
Service.Document document = new Service.Document();
service.setDocument(document);

List<Field> fields = document.getField();


List<File> files = document.getFile();

Field securityGroup = new Field();


securityGroup.setName("dSecurityGroup");
securityGroup.setValue("Public");
fields.add(securityGroup);

Field docType = new Field();


docType.setName("dDocType");
docType.setValue("Document");
fields.add(docType);

Field docAccount = new Field();


docAccount.setName("dDocAccount");
docAccount.setValue("");
fields.add(docAccount);

Field docTitle = new Field();


docTitle.setName("dDocTitle");
docTitle.setValue("UCM JAX-WS Checkin New test file");
fields.add(docTitle);

Field primaryFile = new Field();


primaryFile.setName("primaryFile");
primaryFile.setValue("HelloWorld.txt");
fields.add(primaryFile);

File helloWorld = new File();


helloWorld.setHref("c:\\temp\\HelloWorld.txt");
helloWorld.setContents(new DataHandler(new FileDataSource("c:\\temp\\HelloWorld.txt")));
files.add(helloWorld);

helloWorld.setName("primaryFile");

// Make the request

8 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

Generic response = genericSoapPortType.genericSoapOperation(request);


Service serviceResponse = response.getService();

11. Once the service is called, the response must be parsed and printed to determine success/failure and obtain values. Note that this
snippet only prints the LocalData portion of the returned values, not the ResultSets and OptionLists. The full example of the class listed later
in this file contains code to print ResultSets.

//Get the response


Service.Document doc = serviceResponse.getDocument();

//Show what is in the response


// Dump output fields
List<Field> fieldsResponse = doc.getField();
System.out.println("@Properties LocalData");
for (Field field2 : fieldsResponse) {
String name = field2.getName();
System.out.println(name + "=" + field2.getValue());
}
System.out.println("@end");

12. A full sample client class file follows that performs a CHECKIN_NEW service call.

package genericsoap;
import com.oracle.ucm.Field;
import com.oracle.ucm.Generic;
import com.oracle.ucm.ResultSet;
import com.oracle.ucm.Row;
import com.oracle.ucm.Service;
import com.oracle.ucm.File;

import java.util.List;
import java.util.Map;

import javax.activation.DataHandler;

import javax.activation.FileDataSource;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebServiceRef;

import weblogic.wsee.jws.jaxws.owsm.SecurityPoliciesFeature;
// !THE CHANGES MADE TO THIS FILE WILL BE DESTROYED IF REGENERATED!
// This source file is generated by Oracle tools
// Contents may be subject to change
// For reporting problems, use the following
// Version = Oracle WebServices (11.1.1.0.0, build 101221.1153.15811)

public class GenericSoapPortClient


{
@WebServiceRef
private static GenericSoapService genericSoapService;

public static void main(String [] args)


{
//Set KeyStore path info as system property.
//The jps-config-jse.xml file will reference the default-keystore.jks file and the cwallet.sso.
System.setProperty("oracle.security.jps.config", "D:\\webservices\\jps-config-jse.xml");

genericSoapService = new GenericSoapService();


SecurityPoliciesFeature securityFeatures =
new SecurityPoliciesFeature(new String[] {
"oracle/wss11_username_token_with_message_protection_client_policy" });
GenericSoapPortType genericSoapPortType = genericSoapService.getGenericSoapPort(securityFeatures);
// Add your code to call the desired methods.
//Set username and password
Map<String, Object> requestContext =
((BindingProvider)genericSoapPortType).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, "weblogic");
requestContext.put(BindingProvider.PASSWORD_PROPERTY, "welcome1");

9 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

//Call UCM web service DOC_INFO, giving dID of 1 as parameter. Change the dID to a valid value for your UCM
environment.
Generic request = new Generic();
//WebKey for calling UCM 11g GenericSoapService must be the relative web root.
//Example: If UCM 11g url is http://localhost:16200/cs, the webkey for service calls should be "cs".
request.setWebKey("cs");
Service service = new Service();
request.setService(service);

//Set IdcService
//service.setIdcService("DOC_INFO");
service.setIdcService("CHECKIN_NEW");
//service.setIdcService("GET_SEARCH_RESULTS");
//service.setIdcService("UPDATE_DOCINFO");
Service.Document document = new Service.Document();
service.setDocument(document);

List<Field> fields = document.getField();


List<File> files = document.getFile();

//****************************
//CHECKIN_NEW - Note that checkin has to pass in a File object, using a javax.activation.DataHandler
parameter.
//****************************
Field securityGroup = new Field();
securityGroup.setName("dSecurityGroup");
securityGroup.setValue("Public");
fields.add(securityGroup);

Field docType = new Field();


docType.setName("dDocType");
docType.setValue("Document");
fields.add(docType);

Field docAccount = new Field();


docAccount.setName("dDocAccount");
docAccount.setValue("");
fields.add(docAccount);

Field docTitle = new Field();


docTitle.setName("dDocTitle");
docTitle.setValue("UCM JAX-WS Checkin New test file");
fields.add(docTitle);

Field primaryFile = new Field();


primaryFile.setName("primaryFile");
primaryFile.setValue("HelloWorld.txt");
fields.add(primaryFile);

File helloWorld = new File();


helloWorld.setHref("c:\\temp\\HelloWorld.txt");
helloWorld.setContents(new DataHandler(new FileDataSource("c:\\temp\\HelloWorld.txt")));
files.add(helloWorld);

// Make the request


Generic response = genericSoapPortType.genericSoapOperation(request);
Service serviceResponse = response.getService();

//Get the response


Service.Document doc = serviceResponse.getDocument();
//Show what is in the response
// Dump output fields

List<Field> fieldsResponse = doc.getField();


System.out.println("@Properties LocalData");
for (Field field2 : fieldsResponse) {
String name = field2.getName();
System.out.println(name + "=" + field2.getValue());
}
System.out.println("@end");

// Dump resultsets
List<ResultSet> rsets = doc.getResultSet();
for (ResultSet rset : rsets) {
System.out.println("@ResultSet " + rset.getName());
List<Row> rowYourBoat = rset.getRow();

if (rowYourBoat.size() > 0) {
// Print out the columns

10 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

Row cols = rowYourBoat.get(0);


List<Field> data = cols.getField();
System.out.println(data.size());
for (Field col : data) {
System.out.println(col.getName());
}

// Print out the row data


for (Row row : rowYourBoat) {
data = row.getField();
for (Field val : data) {
System.out.println(val.getValue());
}
}
}
System.out.println("@end");
}

}
}

Note: Since web services secured by OWSM WS-Security policies cannot use MTOM, the size of a file that can be uploaded USING
CHECKIN_NEW or CHECKIN_UNIVERSAL is limited. Streaming upload such as MTOM currently does not work with OWSM policies. If
large file are uploaded this way, the web service proxy client may experience this OutOfMemoryError. This error occurred in a test once
files exceeded 25 mb. For checking in large files to the content server, consider using RIDC as the client.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space


at org.jvnet.staxex.Base64Encoder.print(Base64Encoder.java:66)
at org.jvnet.staxex.Base64Data.toString(Base64Data.java:347)
at com.sun.xml.ws.message.SAX2DOMWriterEx.writeBinary(SAX2DOMWriterEx.java:121)
at com.sun.xml.bind.v2.runtime.output.StAXExStreamWriterOutput.text(StAXExStreamWriterOutput.java:67)
at com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement(XMLSerializer.java:345)
at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$PcdataImpl.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:177)
at com.sun.xml.bind.v2.runtime.MimeTypedTransducer.writeLeafElement(MimeTypedTransducer.java:92)
at
com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.writeLeafElement(TransducedAccessor.
at
com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:98)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:699)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:699)
at
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:699)
at
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:699)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:264)
at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:90)
at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:107)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:331)
at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:158)
at com.sun.xml.ws.message.AbstractMessageImpl.readAsSOAPMessage(AbstractMessageImpl.java:226)
at com.sun.xml.ws.handler.SOAPMessageContextImpl.getMessage(SOAPMessageContextImpl.java:87)
at weblogic.wsee.jaxws.framework.jaxrpc.SOAPMessageContext.getMessage(SOAPMessageContext.java:252)
at oracle.wsm.agent.handler.wls.WSMAgentHook.createWsmMessageContext(WSMAgentHook.java:592)
at oracle.wsm.agent.handler.wls.WSMAgentHook.handleRequest(WSMAgentHook.java:302)
Process exited with exit code 1.

11 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

Note:

In SR 3-9056237611 we found that the code throws a NPE if a file is checked in to a folders_g folder (that has default
metadata applied to it).

The issue was fixed by adding a reference to "primaryFile" to the file payload.

e.g.

File helloWorld = new File();


helloWorld.setHref("c:\\temp\\HelloWorld.txt");
helloWorld.setName("primaryFile");
helloWorld.setContents(new DataHandler(new FileDataSource("c:\\temp\\HelloWorld.txt")));
files.add(helloWorld);

Without the reference, the soap envelope looks like this:

<?xml version='1.0' encoding='UTF-8'?>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
S:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-
1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="UsernameToken-m8GGJH6Swlvgg1pOA5b93w22"><wsse:Username>weblogic</wsse:Username><wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-
1.0#PasswordText">welcome1</wsse:Password></wsse:UsernameToken></wsse:Security>
</S:Header>
<S:Body>
<GenericRequest xmlns="http://www.oracle.com/UCM" webKey="cs">
<Service IdcService="CHECKIN_UNIVERSAL">
<Document>
<Field name="dSecurityGroup">Public</Field>
<Field name="dDocType">Document</Field>
<Field name="dDocAccount"></Field>
<Field name="dDocTitle">Checkin via soap service</Field>
<Field name="tohasCollectionID">true</Field>
<Field name="xCollectionID">659771925421000004</Field>
<Field name="dDocAuthor">weblogic</Field>
<Field name="primaryFile">readme.txt</Field>
<File href="D:\readme.txt"><Contents></Contents></File>
</Document>
</Service>
</GenericRequest>
</S:Body>
</S:Envelope>

WITH reference, the envelope will look like this:

<?xml version='1.0' encoding='UTF-8'?>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
S:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-
1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="UsernameToken-m8GGJH6Swlvgg1pOA5b93w22"><wsse:Username>weblogic</wsse:Username><wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-
1.0#PasswordText">welcome1</wsse:Password></wsse:UsernameToken></wsse:Security>
</S:Header>
<S:Body>
<GenericRequest xmlns="http://www.oracle.com/UCM" webKey="cs">
<Service IdcService="CHECKIN_UNIVERSAL">
<Document>
<Field name="dSecurityGroup">Public</Field>
<Field name="dDocType">Document</Field>
<Field name="dDocAccount"></Field>
<Field name="dDocTitle">Checkin via soap service</Field>
<Field name="tohasCollectionID">true</Field>

12 of 13 1/24/2016 3:14 PM
Document 1332308.1 https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state...

<Field name="xCollectionID">659771925421000004</Field>
<Field name="dDocAuthor">weblogic</Field>
<Field name="primaryFile">readme.txt</Field>
<File name="primaryFile" href="D:\readme.txt"><Contents></Contents></File>
</Document>
</Service>
</GenericRequest>
</S:Body>
</S:Envelope>

Still have questions?

To discuss this information further with Oracle experts and with other Oracle customers, we encourage you to review, ask questions,
join, or start a new discussion in the My WebCenter Content Community.

REFERENCES

NOTE:1332300.1 - Setting up GenericSoapService in UCM 11g (11.1.1.3 to 11.1.1.5) to Use WS-Security


NOTE:1334029.1 - Configuring a Keystore in UCM 11g for Use With Web Services
NOTE:1262613.1 - SOAPFaultException: WSM-06102 PolicyReference The policy reference URI
"oracle/wss11_username_token_with_message_protection_service_policy" is not valid.
NOTE:1332250.1 - Creating a UCM Domain With OWSM Enabled
Didn't find what you are looking for?

13 of 13 1/24/2016 3:14 PM

Potrebbero piacerti anche