我有一个非常简单的Spring启动项目,用于测试在独立运行时在现有Azure存储帐户中成功创建容器。但是,当部署在WebLogic 12c服务器中时,它会因为在Internet上找不到的错误而失败。
proyect有一个Controller,一个Application,一个weblogic.xml和pom.xml,仅此而已。在本地运行时,它可以完美地工作,创建一个包含帐户连接字符串(带有帐户密钥)和容器名称的容器。
以下是Controller类的代码:
package com.example;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
@RestController
public class DemoController {
@RequestMapping(value = "/createAzureContainer", method = RequestMethod.GET)
void createAzureContainer()
throws URISyntaxException, StorageException, IOException, InvalidKeyException {
CloudStorageAccount storageAccount =
CloudStorageAccount.parse("DefaultEndpointsProtocol=https;" +
"AccountName=[accountName];AccountKey=[accountKey]");
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("[containerName]");
container.createIfNotExists();
container.downloadAttributes();
}
}
Application类的代码:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;
@ComponentScan
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer
implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
}
这是weblogic.xml,位于src / main / webapp / WEB-INF:
中<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:context-root>demo</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
最后是pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
有了这个,任何拥有Azure存储帐户的人都可以尝试独立运行并创建容器。但是,当部署到WebLogic 12c时,请执行以下操作:
container.createIfNotExists();
失败,出现以下异常,这听起来像上传blob时可能遇到的问题,但在互联网上搜索容器时找不到任何关于它的参考:
com.microsoft.azure.storage.StorageException: The server encountered an unknown failure: Length Required
at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:101) ~[azure-storage-5.0.0.jar:na]
at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305) ~[azure-storage-5.0.0.jar:na]
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175) ~[azure-storage-5.0.0.jar:na]
at com.microsoft.azure.storage.blob.CloudBlobContainer.create(CloudBlobContainer.java:261) ~[azure-storage-5.0.0.jar:na]
at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:385) ~[azure-storage-5.0.0.jar:na]
at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:326) ~[azure-storage-5.0.0.jar:na]
at com.example.DemoController.createAzureContainer(DemoController.java:66) ~[_wl_cls_gen.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270) [com.oracle.weblogic.servlet.jar:12.2.1.2]
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348) [com.bea.core.utils.full.jar:12.2.1.2]
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333) [com.bea.core.utils.full.jar:12.2.1.2]
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54) [com.oracle.weblogic.work.jar:12.2.1.2]
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
at weblogic.work.ExecuteThread.run(ExecuteThread.java:346) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
非常感谢您的帮助,感谢您的时间。
答案 0 :(得分:0)
根据您的错误信息&amp; Azure存储官方error codes,问题是由于缺少Content-Length
标题引起的,请参阅下文。
您可以尝试使用Fiddler检查错误代码411
&amp;响应以确定异常发生时的问题原因。
根据我的例外情况,我认为WebLogic服务器导致了Content-Length
标头丢失问题。我搜索并发现WebLogic服务器使用一些向后兼容的策略来使用自己的实现来处理某些标准,如JAX-RS
,JAX-PRC
等。
所以我认为您可以尝试参考Oracle官方文档Invoking Web Services from Client Applications and WebLogic Server
&amp; Fusion Middleware Developing and Securing RESTful Web Services for Oracle WebLogic Server 12.1.3
解决此问题。
我认为有些解决方案可能有助于解决它。
根据文档1,尝试添加以下代码。
// Setup the global JAX-RPC service factory
System.setProperty( "javax.xml.rpc.ServiceFactory", "weblogic.webservice.core.rpc.ServiceFactoryImpl");
尝试Configuring the Web Application to Use Jersey 2.5.1 (JAX-RS 2.0 RI)
。
尝试引用Developing RESTful Web Service Clients
来更改或设置代码。
希望它有所帮助。