WebLogic Server 12c中的Restful管理服务

环境:WebLogic Server 12.1.1(下载)

测试工具:REST Console (下载)

基础知识

支持资源类型:JSON、XML、HTML

单资源展示格式(以JSON举例)

{
  "body": {
    "item": {
      // attributes for the item, e.g.
      // "name": "adminserver"
      // "state": "RUNNING",
      // …
    }
  },
  "messages": [
    // an array of messages
  ]
}

集合资源展标格式

{
 "body": {
  "items": [
    {
      // attributes for item 1
      // "name": "adminserver"
      // "state": "RUNNING",
      // …
     },
    {
      // attributes for item 2
     },
     …
    {
      // attributes for item n
     }
    ],
   "messages": [
    ]
}

REST资源列表

监控所有服务器

http(s)://host:port/management/tenant-monitoring/servers

监控指定服务器

http(s)://host:port/management/tenant-monitoring/servers/{servername}

监控服务器所有集群

http(s)://host:port/management/tenant-monitoring/clusters

监控指定集群

http(s)://host:port/management/tenant-monitoring/clusters/{clustername}

监控所有应用

http(s)://host:port/management/tenant-monitoring/applications

监控指定应用

http(s)://host:port/management/tenant-monitoring/applications/{applicationname}

监控所有数据源

http(s)://host:port/management/tenant-monitoring/datasources

监控指定数据源

http(s)://host:port/management/tenant-monitoring/datasources/{datasourcename}

配置过程

1. 激活RESTful服务

进入控制台->[Your Domain]->Configuration->Advanced->Enable RESTful Management Services

2. 使用REST Console进行测试

参考资料

Overview OTN: http://www.oracle.com/technetwork/middleware/weblogic/documentation/index.html

WLS 12c  Data sheet: http://www.oracle.com/us/products/middleware/application-server/oracle-weblogic-server-ds-1391360.pdf

WLS 12c online Documentation Library: http://docs.oracle.com/cd/E24329_01/index.htm

Usind RESTful Services  With WLS 12c: http://docs.oracle.com/cd/E24329_01/web.1211/e26722/toc.htm

userconfig与userkey理解与应用

为什么需要userconfig与userkey?

举例来说:如果我们想让某人去执行编写一些WLST管理脚本,但又不想告诉对方管理员与用户名密码,如何实现呢?再比如,我们想写一些自动执行的WLST脚本,不想在执行过程中弹出题示框让用户输入用户名与密码,同时又不想把用户名与密码写死在脚本中,又如何实现?所有这些就需要用到userconfig与userkey,简单来说userconfig文件就代表用户名,而userkey文件则代表密码,当需要用户认证时,只要出示这两个文件即可。

如何生成userconfig与userkey?

1.  进入目录WL_HOME/common/bin

2. 执行wlst.cmd/sh

3. 连接到Admin Server

connect( username, password, url )

4. 执行命令生成userconfig与userkey文件

storeUserConfig(‘<userConfigFile>’, <userKeyFile>’)

例如:

storeUserConfig(‘C:/myFiles/myuserconfigfile.secure’, ‘C:/myFiles/myuserkeyfile.secure’)

这样,我们就得到了userconfig与userkey文件

如何使用userconfig与userkey?

userconfig与userkey一般是用在WLS脚本中,例如:

connect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’,url=’t3://10.10.71.79:7001′)

nmConnect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’, host=’10.10.71.79′, port=’5556′, domainName=’SAML_SOURCE’, domainDir=’C:/bea922/user_projects/domains/SAML_SOURCE’, nmType=’plain’)

如何通过userconfig与userkey文件反解析出用户名与密码?

样例Java代码:

import weblogic.security.UserConfigFileManager;
import weblogic.security.UsernameAndPassword;
public class SecureReader {
	public static void main( String[] args ) {
		UsernameAndPassword usernameAndPassword = UserConfigFileManager.getUsernameAndPassword( "d:/myuserconfigfile.secure", "d:/myuserkeyfile.secure", "weblogic.management" );
		String username = new String( usernameAndPassword.getUsername() );
		String password = new String( usernameAndPassword.getPassword() );
		System.out.println( "Username=" + username + ", Password=" + password );
	}
}

编译执行:

D:\>javac -classpath S:\fmw\wlserver_10.3\server\lib\weblogic.jar SecureReader.java

D:\>java -classpath S:\fmw\wlserver_10.3\server\lib\weblogic.jar;. SecureReader
Username=weblogic, Password=welcome1

(完)

WebLogic YouTube在线视频

Oracle WebLogic产品部门在YouTube上开辟了一个Oracle WebLogic产品频道用于展示WebLogic Server的新特性以及产品演示,现在共有26个视频,包括以下主题 :

  • Coherence Server Lifecycle Management with WebLogic Server (James Bayer)
  • WebLogic Server JRockit Mission Control Experimental Plugin (James Bayer)
  • WebLogic Server Virtual Edition Overview and Deployment Oracle Virtual Assembly Builder (Mark Prichard)
  • Migrating Applications from OC4J 10g to WebLogic Server with Smart Upgrade (Mark Prichard)
  • WebLogic Server Java EE 6 Web Profile Demo (Steve Button)
  • WebLogic Server with Maven and Eclipse (Steve Button)
  • Advanced JMS Features: Store and Forward, Unit of Order and Unit of Work (Jeff West)
  • WebLogic Scripting Tool (WLST) Recording, editing and Playback (Jeff West)

视频地址:http://www.youtube.com/OracleWeblogic

youtube

如果你不幸是中国的网民,那么你不得不翻墙才能看到这些视频。在此,我又忍不住用“草泥马”来问候GFW以及所有与其相关的部门与个人。

(完)

为Maven安装WebLogic Server插件

对Maven的支持是WebLogic Server 10.3.4的一个新特性,通过WebLogic插件,用户可以通过Maven实现对于对应用发布周期的管理。本文将介绍此插件的制作及使用的最佳实践。

1. 制作插件

进入%WL_HOME%/server/lib目录,执行如下命令

java -jar wljarbuilder.jar -profile weblogic-maven-plugin

此命令执行后将生成 weblogic-maven-plugin.jar文件,其中包括一个pom.xml描述文件指定如下信息

  • groupId=com.oracle.weblogic
  • artifactId=weblogic-maven-plugin
  • version=10.3.4
  • packaging=maven-plugin

2. 定制pom.xml配置文件

将weblogic-maven-plugin.jar中的pom.xml文件取出(可以借助winrar或7-zip等工具),放在%WL_HOME%/server/lib中。

如果安装插件成功后,执行命令需要输入很长的命令,例如:

shell>mvn com.oracle.com:weblogic-maven-plugin:deploy

为了避免此情况,需要做如下修改:

a. 修改%USER_HOME%/.m2/settings.xml(例如:在我的Win7上是c:/Users/gniu/.m2/settings.xml ),加入如下代码:

<pluginGroups>
	<pluginGroup>com.oracle.weblogic</pluginGroup>
</pluginGroups>

b. 修改%WL_HOME%/server/lib目录下的pom.xml文件,加入如下代码:

<plugin>
    <artifactid>maven-plugin-plugin</artifactid>
    <version>2.3</version>
    <configuration>
        <goalprefix>weblogic</goalprefix>
    </configuration>
</plugin>

c. 测试

shell>mvn weblogic:help

3. 安装插件

在%WL_HOME%/server/lib目录下执行如下命令:

shell>mvn install

shell>mvn install:install-file -Dfile=weblogic-maven-plugin.jar -DpomFile=pom.xml

4.  测试插件

创建mvn项目,此过程略,pom.xml文件如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.oraclefmw</groupId>
	<artifactId>sample-web</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>sample-web</name>
	<url>http://www.oraclefmw.com</url>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencies />
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1</version>
				<configuration>
					<failOnMissingWebXml>false</failOnMissingWebXml>
				</configuration>
			</plugin>
			<plugin>
				<groupId>com.oracle.weblogic</groupId>
				<artifactId>weblogic-maven-plugin</artifactId>
				<version>10.3.4</version>
				<configuration>
					<adminurl>t3://localhost:7001</adminurl>
					<name>sample-web</name>
					<user>weblogic</user>
					<remote>true</remote>
					<upload>true</upload>
					<password>welcome1</password>
					<source>target/sample-web.war</source>
				</configuration>
			</plugin>
		</plugins>
		<finalName>sample-web</finalName>
	</build>
</project>

部署应用测试

shell>mvn weblogic:deploy

5. 注意事项

看到Mark Nelson的博客有如下代码:

<pre class="xml" name="code"> <executions>
<execution>
    <id>deploy</id>
    <phase>pre-integration-test</phase>
    <goals>
        <goal>deploy</goal>
    </goals>
    <configuration>
        <source>target/wldemo.war</source>
    </configuration>
</execution>
</pre>

我也尝试为每个goal指定不同的configurations,但是未试成功,未找到解决方案,不知道他是怎么成功的。

参考资料

(完)